feat: 优化代码

pull/133/head
kunfei 5 years ago
parent 7d178ebc8b
commit ae924bee81
  1. 17
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -114,20 +114,20 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
} }
override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) {
super.setStartPoint(x, y, invalidate) super.setStartPoint(x, y, false)
calcCornerXY(x, y) calcCornerXY(x, y)
} }
override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) { override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) {
super.setTouchPoint(x, y, false) super.setTouchPoint(x, y, false)
//触摸y中间位置吧y变成屏幕高度 //触摸y中间位置吧y变成屏幕高度
if ((startY > viewHeight / 3.0 && startY < viewHeight * 2 / 3.0) if ((startY > viewHeight / 3 && startY < viewHeight * 2 / 3)
|| mDirection == Direction.PREV || mDirection == Direction.PREV
) { ) {
touchY = viewHeight.toFloat() touchY = viewHeight.toFloat()
} }
if (startY > viewHeight / 3.0 && startY < viewHeight / 2.0 if (startY > viewHeight / 3 && startY < viewHeight / 2
&& mDirection == Direction.NEXT && mDirection == Direction.NEXT
) { ) {
touchY = 1f touchY = 1f
@ -140,13 +140,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
when (direction) { when (direction) {
Direction.PREV -> Direction.PREV ->
//上一页滑动不出现对角 //上一页滑动不出现对角
if (startX > viewWidth / 2.0) { if (startX > viewWidth / 2) {
calcCornerXY(startX, viewHeight.toFloat()) calcCornerXY(startX, viewHeight.toFloat())
} else { } else {
calcCornerXY(viewWidth - startX, viewHeight.toFloat()) calcCornerXY(viewWidth - startX, viewHeight.toFloat())
} }
Direction.NEXT -> Direction.NEXT ->
if (viewWidth / 2.0 > startX) { if (viewWidth / 2 > startX) {
calcCornerXY(viewWidth - startX, startY) calcCornerXY(viewWidth - startX, startY)
} }
else -> Unit else -> Unit
@ -193,6 +193,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
if (!isRunning) return
when (mDirection) { when (mDirection) {
Direction.NEXT -> { Direction.NEXT -> {
calcPoints() calcPoints()
@ -455,8 +456,8 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
* 计算拖拽点对应的拖拽脚 * 计算拖拽点对应的拖拽脚
*/ */
private fun calcCornerXY(x: Float, y: Float) { private fun calcCornerXY(x: Float, y: Float) {
mCornerX = if (x <= viewWidth / 2.0) 0 else viewWidth mCornerX = if (x <= viewWidth / 2) 0 else viewWidth
mCornerY = if (y <= viewHeight / 2.0) 0 else viewHeight mCornerY = if (y <= viewHeight / 2) 0 else viewHeight
mIsRtOrLb = (mCornerX == 0 && mCornerY == viewHeight) mIsRtOrLb = (mCornerX == 0 && mCornerY == viewHeight)
|| (mCornerY == 0 && mCornerX == viewWidth) || (mCornerY == 0 && mCornerX == viewWidth)
} }
@ -513,7 +514,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mBezierStart2.x = mCornerX.toFloat() mBezierStart2.x = mCornerX.toFloat()
mBezierStart2.y = mBezierControl2.y - (mCornerY - mBezierControl2.y) / 2 mBezierStart2.y = mBezierControl2.y - (mCornerY - mBezierControl2.y) / 2
mTouchToCornerDis = hypot(mTouchX - mCornerX, touchY - mCornerY) mTouchToCornerDis = hypot(mTouchX - mCornerX, mTouchY - mCornerY)
mBezierEnd1 = mBezierEnd1 =
getCross(PointF(mTouchX, mTouchY), mBezierControl1, mBezierStart1, mBezierStart2) getCross(PointF(mTouchX, mTouchY), mBezierControl1, mBezierStart1, mBezierStart2)

Loading…
Cancel
Save