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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index cc453c0..5e88108 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -1156,6 +1156,11 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
+ if (p > 1.0f) {
+ // may be larger than 1.0f on some devices
+ // see the documentation of getPressure(i)
+ p = 1.0f;
+ }
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
}
break;
@@ -1175,6 +1180,11 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
+ if (p > 1.0f) {
+ // may be larger than 1.0f on some devices
+ // see the documentation of getPressure(i)
+ p = 1.0f;
+ }
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
break;
@@ -1184,6 +1194,11 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
x = event.getX(i) / mWidth;
y = event.getY(i) / mHeight;
p = event.getPressure(i);
+ if (p > 1.0f) {
+ // may be larger than 1.0f on some devices
+ // see the documentation of getPressure(i)
+ p = 1.0f;
+ }
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
}
break;