Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScaleGestureDetector not detecting gesture end

I have hooked in a ScaleGestureDetector to an OnTouchListener as instructed in Android documentation. For some reason the ScaleGestureDetector does not always detect end of a pinch gesture. This happens mostly when pinching fast from large to small.

The effect is that after I have released both fingers the detector does not fire the gesture end event. If I touch the screen with one afterwards it still thinks I'm continuing the scale gesture (keeps firing onScale events). I have to do another gesture to get the detector to fire end event.

I have added logs to the OnTouchListener and when the scale gesture gets stuck I still get motion events normally when using one finger and event.getPointerCount() is 1.

I have made sure that I don't have any other listeners intervening. View that has the onTouchListener is not the only view on screen but this effect happens also when I'm very careful to begin and end the gesture inside this one view.

Is there any way to improve the end detection?

Or if there a way for me to manually set the ScaleGestureDetector to fire onScaleEnd and change scaleGestureDetector.isInProgress() to false?

like image 410
Juhani Avatar asked Oct 22 '25 03:10

Juhani


2 Answers

I came up with a solution, after applying the above fix. My application uses both a ScaleGestureDetector and a normal GestureDetector so I implemented in my onScroll method (from the GestureDetector):

if (m_dualFingerGestureDetector.isInProgress() && (evt1.getPointerCount() == 2 || evt2.getPointerCount == 2)
{
    return false;
}
...

My variables are as follows:

m_dualFingerGestureDetector is my ScaleGestureDetector
evt1 and evt2 are MotionEvents for a drag gesture. If you only have one event, you can shorten the above code:

if (m_dualFingerGestureDetector.isInProgress() && evt.getPointerCount() == 2)
{
    return false;
}
...

This allows very nice user interfaces to be built. I would always recommend using the combination of gesture detectors to add pan-and-zoom features to your app.

like image 141
Nathan Moos Avatar answered Oct 23 '25 18:10

Nathan Moos


You might be running into the following bug http://code.google.com/p/android/issues/detail?id=10067

I've had to copy the ScaleGestureDetector implementation into my local project so I could apply the fix. I'm also targeting 2.1 devices so this class is otherwise not available to me unless I copy it into my project.

https://android.googlesource.com/platform/frameworks/base/+/gingerbread-release/core/java/android/view/ScaleGestureDetector.java

like image 28
Akos Cz Avatar answered Oct 23 '25 18:10

Akos Cz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!