2

I am using a gesture detector inside a onTouchListener, but I want to have independent actions for pinching and single presses. Is there a workaround that allows an android application to do both?

ScaleGestureDetector gestureDetector;

private class movePoint implements View.OnTouchListener {
    public boolean onTouch(View v, MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        switch (event.getAction()) {
            case (MotionEvent.ACTION_DOWN):
                break;
            case (MotionEvent.ACTION_UP):
                break;

        }
}
Andrew Su
  • 87
  • 1
  • 2
  • 9
  • The difference is touch-gesture = ACTION_DOWN and ACTION_UP while the scale-gesture = ACTION_MOVE. Probably you can try using that ? – zeekhuge Jun 26 '17 at 16:35
  • It looks like action down and ACTION_DOWN and ACTION_UP are still called in the same sequence of events as ACTION_MOVE, as in MOVE occurs in between the reading of DOWN and UP. Whenever MOVE is called, so must DOWN and UP. – Andrew Su Jun 26 '17 at 17:00
  • maybe use a variable to save the last ACTION ? and if its ACTION_DOWN and then ACTION_MOVE, it will be scaleGesture. If its ACTION_DOWN and then ACTION_UP, its a touch. – zeekhuge Jun 26 '17 at 17:07
  • Yes, I believe I have solved the issue by creating a boolean switch that is changed inside onScaleBegin to control when ACTION_UP is enabled. However, ACTION_DOWN will still always be called. – Andrew Su Jun 26 '17 at 17:28
  • try this https://stackoverflow.com/questions/5790503/can-we-use-scale-gesture-detector-for-pinch-zoom-in-android – Francisco Azevedo Mar 25 '19 at 11:49
  • I know this question is three years old, but still. I simply `MotionEvent#getpointerCount()`. If there's just one pointer I handle the event myself; if there's more I pass it onto my gestureDetector. Seems to be working – Dogcat Jun 08 '20 at 11:26

0 Answers0