|
|
@ -4,12 +4,11 @@ import android.graphics.Canvas |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.VelocityTracker |
|
|
|
import android.view.VelocityTracker |
|
|
|
import io.legado.app.ui.book.read.page.PageView |
|
|
|
import io.legado.app.ui.book.read.page.PageView |
|
|
|
import kotlin.math.abs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { |
|
|
|
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { |
|
|
|
|
|
|
|
|
|
|
|
// 滑动追踪的时间 |
|
|
|
// 滑动追踪的时间 |
|
|
|
private val VELOCITY_DURATION = 1000 |
|
|
|
private val velocityDuration = 1000 |
|
|
|
//速度追踪器 |
|
|
|
//速度追踪器 |
|
|
|
private val mVelocity: VelocityTracker = VelocityTracker.obtain() |
|
|
|
private val mVelocity: VelocityTracker = VelocityTracker.obtain() |
|
|
|
|
|
|
|
|
|
|
@ -44,42 +43,12 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { |
|
|
|
distanceY: Float |
|
|
|
distanceY: Float |
|
|
|
): Boolean { |
|
|
|
): Boolean { |
|
|
|
mVelocity.addMovement(e2) |
|
|
|
mVelocity.addMovement(e2) |
|
|
|
|
|
|
|
mVelocity.computeCurrentVelocity(velocityDuration) |
|
|
|
setTouchPoint(e2.x, e2.y) |
|
|
|
setTouchPoint(e2.x, e2.y) |
|
|
|
if (!isMoved && abs(distanceX) < abs(distanceY)) { |
|
|
|
|
|
|
|
if (distanceY < 0) { |
|
|
|
curPage.onScroll(lastY - touchY) |
|
|
|
if (atTop) { |
|
|
|
|
|
|
|
//如果上一页不存在 |
|
|
|
return true |
|
|
|
if (!hasPrev()) { |
|
|
|
|
|
|
|
noNext = true |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setDirection(Direction.PREV) |
|
|
|
|
|
|
|
setBitmap() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (atBottom) { |
|
|
|
|
|
|
|
//如果不存在表示没有下一页了 |
|
|
|
|
|
|
|
if (!hasNext()) { |
|
|
|
|
|
|
|
noNext = true |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setDirection(Direction.NEXT) |
|
|
|
|
|
|
|
setBitmap() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
isMoved = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ((atTop && mDirection != Direction.PREV) || (atBottom && mDirection != Direction.NEXT) || mDirection == Direction.NONE) { |
|
|
|
|
|
|
|
//传递触摸事件到textView |
|
|
|
|
|
|
|
curPage.dispatchTouchEvent(e2) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (isMoved) { |
|
|
|
|
|
|
|
isCancel = if (mDirection == Direction.NEXT) distanceY < 0 else distanceY > 0 |
|
|
|
|
|
|
|
isRunning = true |
|
|
|
|
|
|
|
//设置触摸点 |
|
|
|
|
|
|
|
setTouchPoint(e2.x, e2.y) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return isMoved |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onFling( |
|
|
|
override fun onFling( |
|
|
|