Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

在使用时无法双击缩小 #1

Open
beilvla opened this issue Nov 5, 2021 · 14 comments
Open

在使用时无法双击缩小 #1

beilvla opened this issue Nov 5, 2021 · 14 comments

Comments

@beilvla
Copy link

beilvla commented Nov 5, 2021

在使用时无法双击缩小

@NanoMichael
Copy link
Owner

v.mp4

你是怎么使用的呢?我这里没有复现

@beilvla
Copy link
Author

beilvla commented Nov 5, 2021

<io.ea.documentview.pdf.WritablePDFView
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@+id/bill_pdf"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/un_close"
    android:textSize="24sp"
    android:textColor="@color/c_e8EBEE"
    android:layout_marginStart="20dp"
    android:layout_marginTop="54dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    android:visibility="gone"
    android:id="@+id/img_close"/>

import android.Manifest
import android.content.Intent

import com.android.libra.tml.viewmodel.BillDetailViewModel
import com.draggable.library.extension.glide.MD5Utils
import com.yanzhenjie.permission.AndPermission
import io.ea.documentview.DefaultAdapterConfig
import io.ea.documentview.DocumentView
import io.ea.documentview.pdf.FileSource
import io.ea.documentview.pdf.WritablePDFView
import io.ea.documentview.rendering.BitmapDocumentView
import java.io.File
import java.net.URL

class BillPDFActivity :
BaseViewModelActivity<ActivityBillPdfactivityBinding, BillDetailViewModel>(BillDetailViewModel::class) {

override fun bindind() = ActivityBillPdfactivityBinding.inflate(layoutInflater)

override fun initIntent(intent: Intent) {
    val billId = intent.getIntExtra("billId", 0)
    billId?.let {
        viewModel.billDetailId = billId
    }

}

override fun initUi() {
        binding.billPdf.apply {
        adapterConfig = DefaultAdapterConfig(18)

// pageBackground = resources.getDrawable(R.drawable.bg_page)
// handWriting.writingColor = Color.RED
onSingleTab = { }
scrollListener = object : DocumentView.ScrollListener {

            override fun onScrolled(view: DocumentView, dx: Int, dy: Int) {
                LogUtil.i("TAG", "onScrolled, [$dx, $dy]")
            }

            override fun onScrollSateChanged(view: DocumentView, oldState: Int, newState: Int) {
                LogUtil.i("TAG", "onScrollStateChanged, $oldState -> $newState")
            }
        }
        zoomListener = object : DocumentView.ZoomListener {

            override fun onZoomStart(view: DocumentView) {
                val elements = Thread.currentThread().stackTrace
                elements.take(10).forEachIndexed { i, e ->
                    LogUtil.i("TAG", "|" + "-".repeat(i) + " $e")
                }
                LogUtil.i("TAG", "onZoomStart")
            }

            override fun onZoomed(view: DocumentView, deltaScale: Float, px: Float, py: Float) {
                LogUtil.i("TAG", "onZoomed, to [$deltaScale, $px, $py]")
            }

            override fun onZoomEnd(view: DocumentView) {
                val elements = Thread.currentThread().stackTrace
                elements.take(10).forEachIndexed { i, e ->
                    LogUtil.i("TAG", "|" + "-".repeat(i) + " $e")
                }
                LogUtil.i("TAG", "onZoomEnd")
            }
        }
        stateListener = object : BitmapDocumentView.StateListener {

            override fun onLoading(view: BitmapDocumentView) {
                LogUtil.i("TAG", "onLoading")
            }

            override fun onLoaded(view: BitmapDocumentView) {
                LogUtil.i("TAG", "onLoaded")
            }

            override fun onLoadError(view: BitmapDocumentView, cause: Throwable) {
                LogUtil.i("TAG", "onLoadError", cause)
            }

            override fun onRenderingError(
                page: Int,
                view: BitmapDocumentView,
                cause: Throwable
            ) {
                LogUtil.i("TAG", "onRenderingError", cause)
            }
        }
    }

// binding.billPdf.load(FileSource(File("/storage/emulated/0/Download/2e71b6ba59fb7be2ae5e134ebcf3cd5e.pdf" )))

    AndPermission.with(this).runtime()
        .permission(
            arrayOf(
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE
            )
        )
        .onGranted {
            viewModel.setPdf()
        }
        .onDenied {

        }
        .start()

}

override fun uiInteraction() {
    binding.imgClose.singleClick { back(it) }

}

override fun observerOnUi() {



    viewModel.getPdf().observerOnUi {
        it?.let {
            var fileName = ""
            val downloadUrl: String = it?.url!!
            val url = URL(downloadUrl) //創建資源類型
            val filePath =
                "${MD5Utils.md5Encode("${BuildConfig.APPLICATION_ID}${viewModel.billDetailId}")}.pdf"
            if (filePath.startsWith("/")) {
                fileName = filePath.substring(1)
            }
            LogUtil.d(
                "MAMAM2",
                "${url.protocol}:${url.host}/----${fileName}"
            )

// val file = File(SpKey.DOWNLOAD_DIR, fileName)
val file = File(SpKey.DOWNLOAD_DIR, filePath)
if (file.exists()) {

                LogUtil.d(
                    "MAMAM3",
                    "${SpKey.DOWNLOAD_DIR + filePath}"
                )
                binding.billPdf.load(FileSource(File("${SpKey.DOWNLOAD_DIR}/${filePath}" )))
                return@observerOnUi
            }
            DownLoadHttpUtils.getInstance().setActionCallBack({

                LogUtil.d("TAG", "Thread : ${Thread.currentThread().name}")
            }, {

                LogUtil.d("TAG", "Thread : ${Thread.currentThread().name}")
            }, {
                binding.billPdf.load(FileSource(File("${SpKey.DOWNLOAD_DIR}/${filePath}" )))
                LogUtil.d("TAG", "success : $it")
                LogUtil.d("TAG", "Thread : ${Thread.currentThread().name}")
            }, {
                LogUtil.d("TAG", "error : $it")
                LogUtil.d("TAG", "Thread : ${Thread.currentThread().name}")
            })

// .addHeader(header)
.initUrl(
downloadUrl,
null
)
.setFilePath(SpKey.DOWNLOAD_DIR!!)
.setFileName(filePath)//皮
.down()
}

    }
}

}

//pdf
implementation "com.github.barteksc:pdfium-android:1.8.2"

使用的aar
image

效果

1636086775997789.mp4

@beilvla
Copy link
Author

beilvla commented Nov 5, 2021

我不明白你的代码没有写请求权限的代码,我仿着写了一个结果会有这个错误
java.io.FileNotFoundException: open failed: EACCES (Permission denied)
at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:344)
at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:231)
at io.ea.documentview.pdf.FileSource.createDocument(Source.kt:32)
at io.ea.documentview.pdf.PDFRenderer.open(PDFRenderer.kt:43)
at io.ea.documentview.rendering.BitmapDocumentView$setupRenderer$2.run(BitmapDocumentView.kt:81)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:264)
at android.os.HandlerThread.run(HandlerThread.java:67)
MyApplication 2.zip

@beilvla
Copy link
Author

beilvla commented Nov 5, 2021

在您的demo中targetSdkVersion和compileSdkVersion>=29就无法正常显示,包括动态获取权限
2021-11-05 15:37:32.502 26802-26802/io.ea.pdf.test E/PDFActivity: onLoadError
java.io.FileNotFoundException: open failed: EACCES (Permission denied)
at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:344)
at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:231)
at io.ea.documentview.pdf.FileSource.createDocument(Source.kt:32)
at io.ea.documentview.pdf.PDFRenderer.open(PDFRenderer.kt:43)
at io.ea.documentview.rendering.BitmapDocumentView$setupRenderer$2.run(BitmapDocumentView.kt:81)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:264)
at android.os.HandlerThread.run(HandlerThread.java:67)

@NanoMichael
Copy link
Owner

你应该先申请读取权限,看报错信息是没有权限读取 pdf 文件

@beilvla
Copy link
Author

beilvla commented Nov 7, 2021

你应该先申请读取权限,看报错信息是没有权限读取 pdf 文件

我加入了获取权限的代码还是提示这个问题,是在targetsdkVersion和complieSdkVersion>=29时
在您的demo中targetSdkVersion和compileSdkVersion>=29就无法正常显示,包括动态获取权限
2021-11-05 15:37:32.502 26802-26802/io.ea.pdf.test E/PDFActivity: onLoadError
java.io.FileNotFoundException: open failed: EACCES (Permission denied)
at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:344)
at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:231)
at io.ea.documentview.pdf.FileSource.createDocument(Source.kt:32)
at io.ea.documentview.pdf.PDFRenderer.open(PDFRenderer.kt:43)
at io.ea.documentview.rendering.BitmapDocumentView$setupRenderer$2.run(BitmapDocumentView.kt:81)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:264)
at android.os.HandlerThread.run(HandlerThread.java:67)

@NanoMichael
Copy link
Owner

但是看报错日志是没有权限读取,你试一下在“设置”中授权读取文件权限呢?

@beilvla
Copy link
Author

beilvla commented Nov 8, 2021

但是看报错日志是没有权限读取,你试一下在“设置”中授权读取文件权限呢?

都开启了,还是不行😂😂😂,包括后台手动设置中开启在是在targetsdkVersion和complieSdkVersion>=29时就是不行

@NanoMichael
Copy link
Owner

只是在 demo 中改了 targetSdkVersion 和 complieSdkVersion 吗?你所要读取的文件是否存在呢?

@beilvla
Copy link
Author

beilvla commented Nov 8, 2021

只是在 demo 中改了 targetSdkVersion 和 complieSdkVersion 吗?你所要读取的文件是否存在呢?

当然存在,本来想自己防着你的demo写一个结果不行,然后把这两个将为29以下即可,包括你的demo也是>=29也是会有这个问题(动态获取权限)

@NanoMichael
Copy link
Owner

OK,我一会看下是什么问题

@beilvla
Copy link
Author

beilvla commented Nov 9, 2021

OK,我一会看下是什么问题

大佬找到什么问题了吗?

@NanoMichael
Copy link
Owner

sorry,我前天没有复现问题,这两天工作比较忙,我今晚再看下

@beilvla
Copy link
Author

beilvla commented Nov 10, 2021

sorry,我前天没有复现问题,这两天工作比较忙,我今晚再看下

好的大佬

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants