feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 82a931cc2b
commit ab2235d65d
  1. 14
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -263,14 +263,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mFolderShadowDrawable = mFolderShadowDrawableRL mFolderShadowDrawable = mFolderShadowDrawableRL
} }
canvas.save() canvas.save()
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)
} }
}
mPaint.colorFilter = mColorMatrixFilter mPaint.colorFilter = mColorMatrixFilter
val dis = hypot( val dis = hypot(
mCornerX - mBezierControl1.x.toDouble(), mCornerX - mBezierControl1.x.toDouble(),
@ -322,14 +321,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mPath1.lineTo(mBezierStart1.x, mBezierStart1.y) mPath1.lineTo(mBezierStart1.x, mBezierStart1.y)
mPath1.close() mPath1.close()
canvas.save() canvas.save()
kotlin.runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
canvas.clipOutPath(mPath0) canvas.clipOutPath(mPath0)
} else { } else {
canvas.clipPath(mPath0, Region.Op.XOR) canvas.clipPath(mPath0, Region.Op.XOR)
} }
canvas.clipPath(mPath1, Region.Op.INTERSECT) canvas.clipPath(mPath1, Region.Op.INTERSECT)
}
var leftX: Int var leftX: Int
var rightX: Int var rightX: Int
var mCurrentPageShadow: GradientDrawable var mCurrentPageShadow: GradientDrawable
@ -362,14 +360,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mPath1.lineTo(mBezierStart2.x, mBezierStart2.y) mPath1.lineTo(mBezierStart2.x, mBezierStart2.y)
mPath1.close() mPath1.close()
canvas.save() canvas.save()
kotlin.runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
canvas.clipOutPath(mPath0) canvas.clipOutPath(mPath0)
} else { } else {
canvas.clipPath(mPath0, Region.Op.XOR) canvas.clipPath(mPath0, Region.Op.XOR)
} }
canvas.clipPath(mPath1) canvas.clipPath(mPath1)
}
if (mIsRtOrLb) { if (mIsRtOrLb) {
leftX = mBezierControl2.y.toInt() leftX = mBezierControl2.y.toInt()
rightX = mBezierControl2.y.toInt() + 25 rightX = mBezierControl2.y.toInt() + 25
@ -431,15 +428,12 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mBackShadowDrawable = mBackShadowDrawableRL mBackShadowDrawable = mBackShadowDrawableRL
} }
canvas.save() canvas.save()
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.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(
@ -471,10 +465,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)
kotlin.runCatching {
canvas.restore() canvas.restore()
} }
}
/** /**
* 计算拖拽点对应的拖拽脚 * 计算拖拽点对应的拖拽脚

Loading…
Cancel
Save