Android: Fixed touch pressure being out of range.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 22 May 2015 22:34:08 +0200
changeset 96129b60f0a1cae8
parent 9611 c23b2fa8d4c2
child 9613 5d7389abafec
Android: Fixed touch pressure being out of range.

According to the documentation of Android's MotionEvent, the getPressure() may
return values higher than 1 on some devices. To prevent passing such values into
SDL they are now corrected to 1 in Java before the JNI call (where it is assumed
to be correct).

Currently SDL only sends SDL_FINGERMOTION events if the touch state (position or
pressure) changed. By correcting pressure down to 1 some events may get dropped
in the rare case that only the pressure was changed but was out of range and the
position did not change.
android-project/src/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Thu May 21 21:27:53 2015 +0200
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Fri May 22 22:34:08 2015 +0200
     1.3 @@ -1156,6 +1156,11 @@
     1.4                          x = event.getX(i) / mWidth;
     1.5                          y = event.getY(i) / mHeight;
     1.6                          p = event.getPressure(i);
     1.7 +                        if (p > 1.0f) {
     1.8 +                            // may be larger than 1.0f on some devices
     1.9 +                            // see the documentation of getPressure(i)
    1.10 +                            p = 1.0f;
    1.11 +                        }
    1.12                          SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
    1.13                      }
    1.14                      break;
    1.15 @@ -1175,6 +1180,11 @@
    1.16                      x = event.getX(i) / mWidth;
    1.17                      y = event.getY(i) / mHeight;
    1.18                      p = event.getPressure(i);
    1.19 +                    if (p > 1.0f) {
    1.20 +                        // may be larger than 1.0f on some devices
    1.21 +                        // see the documentation of getPressure(i)
    1.22 +                        p = 1.0f;
    1.23 +                    }
    1.24                      SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
    1.25                      break;
    1.26  
    1.27 @@ -1184,6 +1194,11 @@
    1.28                          x = event.getX(i) / mWidth;
    1.29                          y = event.getY(i) / mHeight;
    1.30                          p = event.getPressure(i);
    1.31 +                        if (p > 1.0f) {
    1.32 +                            // may be larger than 1.0f on some devices
    1.33 +                            // see the documentation of getPressure(i)
    1.34 +                            p = 1.0f;
    1.35 +                        }
    1.36                          SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
    1.37                      }
    1.38                      break;