Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save worker8/19bb3701145e3813163dff191edc3631 to your computer and use it in GitHub Desktop.
Save worker8/19bb3701145e3813163dff191edc3631 to your computer and use it in GitHub Desktop.
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val action = event.actionMasked
val currentPoint = Point(event.x.toInt(), event.y.toInt())
if (action == MotionEvent.ACTION_DOWN) {
// mark the beginning, when finger touched down
initialTouchPoint = Point(currentPoint)
} else if (action == MotionEvent.ACTION_UP) {
// reset the marking, when finger is lifted up
initialTouchPoint = Point(0, 0)
} else {
val moveDistance = currentPoint.distanceFrom(initialTouchPoint)
if (moveDistance > FINGER_MOVE_THRESHOLD) {
val direction = MotionUtil.getDirection(initialTouchPoint, currentPoint)
// check if the scrolling is vertical
if (direction == MotionUtil.Direction.up || direction == MotionUtil.Direction.down) {
return true
}
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment