Fixed bug 2558 - Missing FINGERUP in Android
authorSam Lantinga
Sun, 15 Jun 2014 19:32:39 -0700
changeset 8871e7abd1102676
parent 8870 cd1113741ade
child 8872 5a6375d96834
Fixed bug 2558 - Missing FINGERUP in Android

Sylvain

If you play with the TouchScreen with +3 fingers randomly / pressing simultaneously all fingers.

You triggers FINGER DOWN events, but not always all the associated FINGER UP events.

So, after a while SDL_GetNumFingers() can report a wrong number of fingers pressed !


The explanation is hidden there : http://developer.android.com/reference/android/view/MotionEvent.html

Each pointer has a unique id that is assigned when it first goes down (indicated by ACTION_DOWN or ACTION_POINTER_DOWN).
A pointer id remains valid until the pointer eventually goes up (indicated by ACTION_UP or ACTION_POINTER_UP) or when the gesture is canceled (indicated by ACTION_CANCEL).

in ACTION_CANCEL :

The current gesture has been aborted. You will not receive any more points in it. You should treat this as an up event, but not perform any action that you normally would.
Constant Value: 3 (0x00000003)
android-project/src/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Sun Jun 15 18:31:30 2014 -0700
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Sun Jun 15 19:32:39 2014 -0700
     1.3 @@ -786,6 +786,16 @@
     1.4                  SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
     1.5                  break;
     1.6              
     1.7 +            case MotionEvent.ACTION_CANCEL:
     1.8 +                for (i = 0; i < pointerCount; i++) {
     1.9 +                    pointerFingerId = event.getPointerId(i);
    1.10 +                    x = event.getX(i) / mWidth;
    1.11 +                    y = event.getY(i) / mHeight;
    1.12 +                    p = event.getPressure(i);
    1.13 +                    SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
    1.14 +                }
    1.15 +                break;
    1.16 +
    1.17              default:
    1.18                  break;
    1.19          }