Created
October 22, 2018 13:02
-
-
Save worker8/82da072a47300e41ca5bbf15244ec334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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