Skip to content

Commit

Permalink
Android: Fixed touch pressure being out of range.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
philippwiesemann committed May 22, 2015
1 parent 4f00dda commit 1968ff0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -1156,6 +1156,11 @@ public boolean onTouch(View v, MotionEvent event) {
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;
Expand All @@ -1175,6 +1180,11 @@ public boolean onTouch(View v, MotionEvent event) {
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;

Expand All @@ -1184,6 +1194,11 @@ public boolean onTouch(View v, MotionEvent event) {
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;
Expand Down

0 comments on commit 1968ff0

Please sign in to comment.