pull/38/head
kunfei 5 years ago
parent 76ff444675
commit 6dc231d1c7
  1. 22
      app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt

@ -30,7 +30,6 @@ class ContentTextView : AppCompatTextView {
private val mViewFling: ViewFling by lazy { ViewFling() }
private var velocityTracker: VelocityTracker? = null
private var mScrollState = scrollStateIdle
private var mScrollPointerId = -1
private var mLastTouchY: Int = 0
private var mTouchSlop: Int = 0
private var mMinFlingVelocity: Int = 0
@ -111,7 +110,6 @@ class ContentTextView : AppCompatTextView {
override fun onTouchEvent(event: MotionEvent?): Boolean {
event?.let {
val action = event.action
val actionIndex = event.actionIndex
val vtEvent = MotionEvent.obtain(event)
if (velocityTracker == null) {
@ -121,17 +119,10 @@ class ContentTextView : AppCompatTextView {
when (action) {
MotionEvent.ACTION_DOWN -> {
setScrollState(scrollStateIdle)
mScrollPointerId = event.getPointerId(0)
mLastTouchY = (event.y + 0.5f).toInt()
}
MotionEvent.ACTION_POINTER_DOWN -> {
mScrollPointerId = event.getPointerId(actionIndex)
mLastTouchY = (event.getY(actionIndex) + 0.5f).toInt()
}
MotionEvent.ACTION_MOVE -> {
val index = event.findPointerIndex(mScrollPointerId)
if (index > 0) {
val y = (event.getY(index) + 0.5f).toInt()
val y = (event.y + 0.5f).toInt()
var dy = mLastTouchY - y
if (mScrollState != scrollStateDragging) {
@ -154,18 +145,9 @@ class ContentTextView : AppCompatTextView {
mLastTouchY = y
}
}
}
MotionEvent.ACTION_POINTER_UP -> {
if (event.getPointerId(actionIndex) == mScrollPointerId) {
// Pick a new pointer to pick up the slack.
val newIndex = if (actionIndex == 0) 1 else 0
mScrollPointerId = event.getPointerId(newIndex)
mLastTouchY = (event.getY(newIndex) + 0.5f).toInt()
}
}
MotionEvent.ACTION_UP -> {
velocityTracker?.computeCurrentVelocity(1000, mMaxFlingVelocity.toFloat())
val yVelocity = velocityTracker?.getYVelocity(mScrollPointerId) ?: 0f
val yVelocity = velocityTracker?.yVelocity ?: 0f
if (abs(yVelocity) > mMinFlingVelocity) {
mViewFling.fling(-yVelocity.toInt())
} else {

Loading…
Cancel
Save