pull/38/head
kunfei 5 years ago
parent 76ff444675
commit 6dc231d1c7
  1. 54
      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 val mViewFling: ViewFling by lazy { ViewFling() }
private var velocityTracker: VelocityTracker? = null private var velocityTracker: VelocityTracker? = null
private var mScrollState = scrollStateIdle private var mScrollState = scrollStateIdle
private var mScrollPointerId = -1
private var mLastTouchY: Int = 0 private var mLastTouchY: Int = 0
private var mTouchSlop: Int = 0 private var mTouchSlop: Int = 0
private var mMinFlingVelocity: Int = 0 private var mMinFlingVelocity: Int = 0
@ -111,7 +110,6 @@ class ContentTextView : AppCompatTextView {
override fun onTouchEvent(event: MotionEvent?): Boolean { override fun onTouchEvent(event: MotionEvent?): Boolean {
event?.let { event?.let {
val action = event.action val action = event.action
val actionIndex = event.actionIndex
val vtEvent = MotionEvent.obtain(event) val vtEvent = MotionEvent.obtain(event)
if (velocityTracker == null) { if (velocityTracker == null) {
@ -121,51 +119,35 @@ class ContentTextView : AppCompatTextView {
when (action) { when (action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
setScrollState(scrollStateIdle) setScrollState(scrollStateIdle)
mScrollPointerId = event.getPointerId(0)
mLastTouchY = (event.y + 0.5f).toInt() mLastTouchY = (event.y + 0.5f).toInt()
} }
MotionEvent.ACTION_POINTER_DOWN -> {
mScrollPointerId = event.getPointerId(actionIndex)
mLastTouchY = (event.getY(actionIndex) + 0.5f).toInt()
}
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
val index = event.findPointerIndex(mScrollPointerId) val y = (event.y + 0.5f).toInt()
if (index > 0) { var dy = mLastTouchY - y
val y = (event.getY(index) + 0.5f).toInt()
var dy = mLastTouchY - y if (mScrollState != scrollStateDragging) {
var startScroll = false
if (mScrollState != scrollStateDragging) {
var startScroll = false if (abs(dy) > mTouchSlop) {
if (dy > 0) {
if (abs(dy) > mTouchSlop) { dy -= mTouchSlop
if (dy > 0) { } else {
dy -= mTouchSlop dy += mTouchSlop
} else {
dy += mTouchSlop
}
startScroll = true
}
if (startScroll) {
setScrollState(scrollStateDragging)
} }
startScroll = true
} }
if (startScroll) {
if (mScrollState == scrollStateDragging) { setScrollState(scrollStateDragging)
mLastTouchY = y
} }
} }
}
MotionEvent.ACTION_POINTER_UP -> { if (mScrollState == scrollStateDragging) {
if (event.getPointerId(actionIndex) == mScrollPointerId) { mLastTouchY = y
// 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 -> { MotionEvent.ACTION_UP -> {
velocityTracker?.computeCurrentVelocity(1000, mMaxFlingVelocity.toFloat()) velocityTracker?.computeCurrentVelocity(1000, mMaxFlingVelocity.toFloat())
val yVelocity = velocityTracker?.getYVelocity(mScrollPointerId) ?: 0f val yVelocity = velocityTracker?.yVelocity ?: 0f
if (abs(yVelocity) > mMinFlingVelocity) { if (abs(yVelocity) > mMinFlingVelocity) {
mViewFling.fling(-yVelocity.toInt()) mViewFling.fling(-yVelocity.toInt())
} else { } else {

Loading…
Cancel
Save