Move Events AFTER LongPress

Marcos Vasconcelos picture Marcos Vasconcelos · Apr 13, 2011 · Viewed 8.6k times · Source

How can I listen the move events after the LongPress is caled in my GestureDetector?

When the user LongClick he starts the selection mode, and can drag a square into the screen. But I noticed that the onScroll is not called after LongPress is consumed.

Answer

Lukas picture Lukas · Apr 22, 2011

Tried to do fight this for a while, and for now the solution is:

  1. Disable the longpress using setIsLongpressEnabled(isLongpressEnabled) on your gestureDetector

Here is my OnTouch method of my View:

public boolean onTouchEvent(MotionEvent event) {
        if (mGestureDetector.onTouchEvent(event)== true)
        {
            //Fling or other gesture detected (not logpress because it is disabled)
        }
        else
        {
            //Manually handle the event.
            if (event.getAction() == MotionEvent.ACTION_DOWN)
            {
                //Remember the time and press position
                Log.e("test","Action down");
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE)
            {
                //Check if user is actually longpressing, not slow-moving 
                // if current position differs much then press positon then discard whole thing
                // If position change is minimal then after 0.5s that is a longpress. You can now process your other gestures 
                Log.e("test","Action move");
            }
            if (event.getAction() == MotionEvent.ACTION_UP)
            {
                //Get the time and position and check what that was :)
                Log.e("test","Action down");
            }

        }
        return true;
    }

My device returned ACTION_MOVE whenever I hold finger on the screen. If your doesnt, just check the state of some pressed flag after 0.5s using a timer or thread.

Hope that helps!