feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 9953c37549
commit cbe6a5c277
  1. 30
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -417,39 +417,37 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
) )
).toFloat() ).toFloat()
val leftX: Int val leftX: Int
val rightY: Int val rightX: Int
val mBackShadowDrawable: GradientDrawable val mBackShadowDrawable: GradientDrawable
if (mIsRtOrLb) { //左下及右上 if (mIsRtOrLb) { //左下及右上
leftX = mBezierStart1.x.toInt() leftX = mBezierStart1.x.toInt()
rightY = (mBezierStart1.x + mTouchToCornerDis / 4).toInt() rightX = (mBezierStart1.x + mTouchToCornerDis / 4).toInt()
mBackShadowDrawable = mBackShadowDrawableLR!! mBackShadowDrawable = mBackShadowDrawableLR!!
} else { } else {
leftX = (mBezierStart1.x - mTouchToCornerDis / 4).toInt() leftX = (mBezierStart1.x - mTouchToCornerDis / 4).toInt()
rightY = mBezierStart1.x.toInt() rightX = mBezierStart1.x.toInt()
mBackShadowDrawable = mBackShadowDrawableRL!! mBackShadowDrawable = mBackShadowDrawableRL!!
} }
canvas.save() canvas.save()
try { kotlin.runCatching {
canvas.clipPath(mPath0) canvas.clipPath(mPath0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
canvas.clipPath(mPath1) canvas.clipPath(mPath1)
} else { } else {
canvas.clipPath(mPath1, Region.Op.INTERSECT) canvas.clipPath(mPath1, Region.Op.INTERSECT)
} }
//canvas.clipPath(mPath1, Region.Op.INTERSECT);
} catch (ignored: java.lang.Exception) {
} }
canvas.drawBitmap(bitmap, 0f, 0f, null) canvas.drawBitmap(bitmap, 0f, 0f, null)
canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y) canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y)
mBackShadowDrawable.setBounds( mBackShadowDrawable.setBounds(
leftX, mBezierStart1.y.toInt(), rightY, leftX, mBezierStart1.y.toInt(),
(mMaxLength + mBezierStart1.y).toInt() rightX, (mMaxLength + mBezierStart1.y).toInt()
) //左上及右下角的xy坐标值,构成一个矩形 ) //左上及右下角的xy坐标值,构成一个矩形
mBackShadowDrawable.draw(canvas) mBackShadowDrawable.draw(canvas)
canvas.restore() canvas.restore()
} }
//绘制翻页时的正面页
private fun drawCurrentPageArea( private fun drawCurrentPageArea(
canvas: Canvas, canvas: Canvas,
bitmap: Bitmap?, bitmap: Bitmap?,
@ -458,16 +456,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
bitmap ?: return bitmap ?: return
mPath0.reset() mPath0.reset()
mPath0.moveTo(mBezierStart1.x, mBezierStart1.y) mPath0.moveTo(mBezierStart1.x, mBezierStart1.y)
mPath0.quadTo( mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y)
mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x,
mBezierEnd1.y
)
mPath0.lineTo(touchX, touchY) mPath0.lineTo(touchX, touchY)
mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y) mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y)
mPath0.quadTo( mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y)
mBezierControl2.x, mBezierControl2.y, mBezierStart2.x,
mBezierStart2.y
)
mPath0.lineTo(mCornerX.toFloat(), mCornerY.toFloat()) mPath0.lineTo(mCornerX.toFloat(), mCornerY.toFloat())
mPath0.close() mPath0.close()
canvas.save() canvas.save()
@ -477,10 +469,8 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
canvas.clipPath(path, Region.Op.XOR) canvas.clipPath(path, Region.Op.XOR)
} }
canvas.drawBitmap(bitmap, 0f, 0f, null) canvas.drawBitmap(bitmap, 0f, 0f, null)
try { kotlin.runCatching {
canvas.restore() canvas.restore()
} catch (e: java.lang.Exception) {
e.printStackTrace()
} }
} }

Loading…
Cancel
Save