fun onTouchEvent(event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { downX = event.rawX downY = event.rawY } MotionEvent.ACTION_UP -> { val velocityX = event.rawX - downX val velocityY = event.rawY - downY if (Math.abs(velocityX) > VELOCITY_THRESHOLD || Math.abs(velocityY) > VELOCITY_THRESHOLD) { if (velocityX > 0 || velocityY > 0) { // fling to the right or down } ..