feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 7ae49cc342
commit 831f0a812d
  1. 26
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -7,6 +7,7 @@ import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import kotlin.math.* import kotlin.math.*
@Suppress("DEPRECATION")
class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
private var mCornerX = 1 // 拖拽点对应的页脚 private var mCornerX = 1 // 拖拽点对应的页脚
@ -59,6 +60,8 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
private val mPaint: Paint = Paint() private val mPaint: Paint = Paint()
private var curBitmap: Bitmap? = curPage.screenshot() private var curBitmap: Bitmap? = curPage.screenshot()
private var prevBitmap: Bitmap? = prevPage.screenshot()
private var nextBitmap: Bitmap? = nextPage.screenshot()
init { init {
@ -124,7 +127,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
} }
override fun onScrollStop() { override fun onScrollStop() {
curPage?.x = 0.toFloat() curPage.x = 0.toFloat()
if (!isCancel) { if (!isCancel) {
pageView.fillPage(direction) pageView.fillPage(direction)
} }
@ -134,16 +137,16 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
bitmap?.let { bitmap?.let {
if (direction === Direction.NEXT) { if (direction === Direction.NEXT) {
calcPoints() calcPoints()
drawCurrentPageArea(canvas, it, mPath0) //绘制翻页时的正面页 drawCurrentPageArea(canvas, curBitmap, mPath0) //绘制翻页时的正面页
drawNextPageAreaAndShadow(canvas, it) drawNextPageAreaAndShadow(canvas, nextBitmap)
drawCurrentPageShadow(canvas) drawCurrentPageShadow(canvas)
drawCurrentBackArea(canvas, it) drawCurrentBackArea(canvas, curBitmap)
} else { } else {
calcPoints() calcPoints()
drawCurrentPageArea(canvas, it, mPath0) drawCurrentPageArea(canvas, prevBitmap, mPath0)
drawNextPageAreaAndShadow(canvas, it) drawNextPageAreaAndShadow(canvas, curBitmap)
drawCurrentPageShadow(canvas) drawCurrentPageShadow(canvas)
drawCurrentBackArea(canvas, it) drawCurrentBackArea(canvas, prevBitmap)
} }
} }
} }
@ -186,8 +189,9 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
*/ */
private fun drawCurrentBackArea( private fun drawCurrentBackArea(
canvas: Canvas, canvas: Canvas,
bitmap: Bitmap bitmap: Bitmap?
) { ) {
bitmap ?: return
val i = (mBezierStart1.x + mBezierControl1.x).toInt() / 2 val i = (mBezierStart1.x + mBezierControl1.x).toInt() / 2
val f1 = abs(i - mBezierControl1.x) val f1 = abs(i - mBezierControl1.x)
val i1 = (mBezierStart2.y + mBezierControl2.y).toInt() / 2 val i1 = (mBezierStart2.y + mBezierControl2.y).toInt() / 2
@ -353,8 +357,9 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
private fun drawNextPageAreaAndShadow( private fun drawNextPageAreaAndShadow(
canvas: Canvas, canvas: Canvas,
bitmap: Bitmap bitmap: Bitmap?
) { ) {
bitmap ?: return
mPath1.reset() mPath1.reset()
mPath1.moveTo(mBezierStart1.x, mBezierStart1.y) mPath1.moveTo(mBezierStart1.x, mBezierStart1.y)
mPath1.lineTo(mBezierVertex1.x, mBezierVertex1.y) mPath1.lineTo(mBezierVertex1.x, mBezierVertex1.y)
@ -403,9 +408,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
private fun drawCurrentPageArea( private fun drawCurrentPageArea(
canvas: Canvas, canvas: Canvas,
bitmap: Bitmap, bitmap: Bitmap?,
path: Path path: Path
) { ) {
bitmap ?: return
mPath0.reset() mPath0.reset()
mPath0.moveTo(mBezierStart1.x, mBezierStart1.y) mPath0.moveTo(mBezierStart1.x, mBezierStart1.y)
mPath0.quadTo( mPath0.quadTo(

Loading…
Cancel
Save