How deteck swipe up correctly

40 views Asked by At

I have a video viewing screen. at the touch down event, I stop the video, at touch up resume. However, I encountered a difficulty - I need to swipe up and open the video settings window, while the video should be paused.

I handled the down and up events correctly - but now when I process swipe up, I get problems. According to the documentation, down is called first, then swipe, then up - as a result, I get events that I don't need during the swipe. How do I track that it is a swipe and at the same time ignore down and up?

i have code to try

    override fun onTouch(view: View, event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                touchAction(TouchEvent.TOUCH_START) //callback touch start
            }
            MotionEvent.ACTION_UP -> {
                touchAction(TouchEvent.TOUCH_END)  //callback touch end
            }

            MotionEvent.ACTION_MOVE -> {
                val lastTouchPosition = lastDownTouchPosition ?: return false
                val deltaX = lastTouchPosition.x - event.rawX
                val deltaY = lastTouchPosition.y - event.rawY

                if (deltaY.absoluteValue - deltaX.absoluteValue > 1.5 && deltaY > 0) {
                    swipeUpAction() //callback swipe up
                }
            }
        }
        return true
    }

Can i filter ACTION_DOWN and ACTION_UP in ACTION_MOVE ?

1

There are 1 answers

1
Cloverleaf On

You need to introduce a SimpleOnGestureListener(), see here (examples in Java and Kotlin).