android pdf框架-3,基于recyclerview修改

基于recyclerview的实现版本

解析使用的是pdifum.这个库缺点是缩放功能不行.点击链接功能没有.只有渲染.

GitHub - danjdt/android-pdfviewer: A Android PDF Viewer that render pdf using PdfRenderer and displays it in a RecyclerView.

recyclerview的滑动并不是像ios那样,有很好的惯性,针对此,从ebookdroid中拿了flinger,因为recyclerview不能直接修改scroller,所以只有修改源码了,换了包名,避免冲突.

https://github.com/archko/pdf-recyclerview.git,这是修改recyclerview,添加了flinger,滑动更流畅,当然可以不用它.

修改几个bug

缩放的bug修改

上面源码中的缩放是针对view,如果要自定义linearlayoutmanager也是可以的,复杂度就提升不少了.

在这我只作view的缩放后映射到解码上面:

override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.save()
        canvas.translate(mTouchX, 0f)
        canvas.scale(mScaleFactor, mScaleFactor)
        canvas.restore()
    }

    override fun dispatchDraw(canvas: Canvas) {
        canvas.save()

        if (mScaleFactor == mMinZoom) {
            mTouchX = 0f
        }

        canvas.translate(mTouchX, 0f)
        canvas.scale(mScaleFactor, mScaleFactor)

        super.dispatchDraw(canvas)

        canvas.restore()
        invalidate()
    }

这是原来的缩放作了一些小修改的结果.修正事件,

当缩放手势完成后,需要处理解码的缩放,否则就是把原来的图片放大,会模糊,而不是真正的缩放.

private inner class ScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
        override fun onScale(detector: ScaleGestureDetector): Boolean {
            if (mIsZoomEnabled) {
                mScaleFactor *= detector.scaleFactor
                mScaleFactor = Math.max(mMinZoom, Math.min(mScaleFactor, mMaxZoom))
                mMaxWidth = mWidth - mWidth * mScaleFactor
                //Log.d("PDFSDK", "mScaleFactor:$mScaleFactor")
                invalidate()
            }
            return true
        }

        override fun onScaleEnd(detector: ScaleGestureDetector) {
            super.onScaleEnd(detector)

            pdfRendererProxy?.a

你可能感兴趣的:(pdf,android,pdf)