summaryrefslogtreecommitdiff
path: root/android-project
diff options
context:
space:
mode:
authorRyan C. Gordon <icculus@icculus.org>2011-10-13 01:21:35 -0400
committerRyan C. Gordon <icculus@icculus.org>2011-10-13 01:21:35 -0400
commit45b644d1a90b72630f3304077f21b372488ebc4e (patch)
tree2b34cea3dc50ceac4f300a97f55a3703c60fac92 /android-project
parentf8c3950a95dc43bb7f40e65202599318ba969718 (diff)
Added support for multitouch on Android.
Fixes Bugzilla #1294. Thanks to Gabriel Jacobo for the patch!
Diffstat (limited to 'android-project')
-rw-r--r--android-project/src/org/libsdl/app/SDLActivity.java41
1 files changed, 30 insertions, 11 deletions
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index b883abf6..1e44994e 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -93,7 +93,8 @@ public class SDLActivity extends Activity {
public static native void onNativeResize(int x, int y, int format);
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
- public static native void onNativeTouch(int action, float x,
+ public static native void onNativeTouch(int touchDevId, int pointerFingerId,
+ int action, float x,
float y, float p);
public static native void onNativeAccel(float x, float y, float z);
public static native void nativeRunAudioThread();
@@ -459,16 +460,34 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Touch events
public boolean onTouch(View v, MotionEvent event) {
-
- int action = event.getAction();
- float x = event.getX();
- float y = event.getY();
- float p = event.getPressure();
-
- // TODO: Anything else we need to pass?
- SDLActivity.onNativeTouch(action, x, y, p);
- return true;
- }
+ {
+ final int touchDevId = event.getDeviceId();
+ final int pointerCount = event.getPointerCount();
+ // touchId, pointerId, action, x, y, pressure
+ int actionPointerIndex = event.getActionIndex();
+ int pointerFingerId = event.getPointerId(actionPointerIndex);
+ int action = event.getActionMasked();
+
+ float x = event.getX(actionPointerIndex);
+ float y = event.getY(actionPointerIndex);
+ float p = event.getPressure(actionPointerIndex);
+
+ if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) {
+ // TODO send motion to every pointer if its position has
+ // changed since prev event.
+ for (int i = 0; i < pointerCount; i++) {
+ pointerFingerId = event.getPointerId(i);
+ x = event.getX(i);
+ y = event.getY(i);
+ p = event.getPressure(i);
+ SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
+ }
+ } else {
+ SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
+ }
+ }
+ return true;
+ }
// Sensor events
public void enableSensor(int sensortype, boolean enabled) {