Explorar el Código

multitouch support implemented in android. yaihgit statusgit status

mikymod hace 13 años
padre
commit
6e267d49e7

+ 41 - 12
android/src/crown/android/CrownActivity.java

@@ -13,18 +13,22 @@ import android.content.Context;
 import android.widget.Toast;
 import android.content.res.AssetManager;
 
+import crown.android.CrownEnum;
+
 public class CrownActivity extends Activity
 {
 	public static String TAG = "CrownActivity";
 
+	// Resource attributes
     static AssetManager assetManager;
 
+	// Graphic attributes
 	private CrownView mView;
 
+	// Input attributes
 	private static SensorManager sm;
 	private Sensor sensor;
-
-	//TODO: add count of finger on screen at the same time
+	private int mActivePointer = -1;
 
 //---------------------------------------------------------------------
     public void onCreate(Bundle savedInstanceState)
@@ -97,29 +101,54 @@ public class CrownActivity extends Activity
 //---------------------------------------------------------------------
 	public boolean onTouchEvent(MotionEvent event)
 	{
-	    float x = event.getX();
-	    float y = event.getY();
 
-		switch (event.getAction()) 
+		int actionMasked = event.getActionMasked();
+
+		switch (actionMasked) 
 		{	
+			case MotionEvent.ACTION_DOWN:
+			{
+				Log.i(TAG, "event = ACTION_DOWN");
+			    final float x = event.getX();
+			    final float y = event.getY();
+				CrownLib.pushEvent(6, 0, (int) x,(int) y, 0);
+				break;			
+			}
+
+			case MotionEvent.ACTION_POINTER_DOWN:
+			{
+				final int pointerIndex = event.getActionIndex();
+				final int pointerId = event.getPointerId(pointerIndex);
+				final float x = event.getX(pointerId);
+				final float y = event.getY(pointerId);
+				Log.i(TAG, "event = ACTION_POINTER_DOWN_" + pointerId);
+				CrownLib.pushEvent(6, pointerId, (int)x, (int)y, 0);
+				break;
+			}
+
 	        case MotionEvent.ACTION_MOVE:
 			{
 				Log.i(TAG, "event = ACTION_MOVE");
-				CrownLib.pushEvent(10,(int) x,(int) y, 0, 0);
+				final int pointerIndex = event.getActionIndex();
+				final int pointerId = event.getPointerId(pointerIndex);
+				final float x = event.getX(pointerId);
+				final float y = event.getY(pointerId);
+				CrownLib.pushEvent(7, pointerId, (int) x,(int) y, 0);
 				break;
 			}
 
-			case MotionEvent.ACTION_DOWN:
+			case MotionEvent.ACTION_POINTER_UP:
 			{
-				Log.i(TAG, "event = ACTION_DOWN");
-				CrownLib.pushEvent(10,(int) x,(int) y, 0, 0);
-				break;			
+				final int pointerIndex = event.getActionIndex();
+				final int pointerId = event.getPointerId(pointerIndex);
+				Log.i(TAG, "event = ACTION_POINTER_DOWN_" + pointerId);
+
+				break;
 			}
 
 			case MotionEvent.ACTION_UP:
 			{
 				Log.i(TAG, "event = ACTION_UP");
-				CrownLib.pushEvent(10,(int) x,(int) y, 0, 0);
 				break;			
 			}
 		}
@@ -140,7 +169,7 @@ public class CrownActivity extends Activity
      	 	float x = event.values[0];
 			float y = event.values[1];
 			float z = event.values[2];
-			Log.i(TAG, "X:" + x + "Y:" + y + "Z:" + z);
+//			Log.i(TAG, "X:" + x + "Y:" + y + "Z:" + z);
 			CrownLib.pushEvent(11,(int) x,(int) y, (int)z, 0);
     	}
   	};

+ 10 - 10
android/src/crown/android/CrownEnum.java

@@ -3,14 +3,14 @@ package crown.android;
 public class CrownEnum
 {
 	// OSEventType enum in OS.h
-	public static final int OSET_NONE			= 0;
-	public static final int OSET_KEY_PRESS		= 1;
-	public static final int OSET_KEY_RELEASE	= 2;
-	public static final int OSET_BUTTON_PRESS	= 3;
-	public static final int OSET_BUTTON_RELEASE	= 4;
-	public static final int OSET_MOTION_NOTIFY	= 5;
-	public static final int OSET_TOUCH_DOWN 	= 6;
-	public static final int OSET_TOUCH_MOVE		= 7;
-	public static final int OSET_TOUCH_UP		= 8;
-	public static final int OSET_ACCELEROMETER	= 9; 
+	public static int OSET_NONE				= 0;
+	public static int OSET_KEY_PRESS		= 1;
+	public static int OSET_KEY_RELEASE		= 2;
+	public static int OSET_BUTTON_PRESS		= 3;
+	public static int OSET_BUTTON_RELEASE	= 4;
+	public static int OSET_MOTION_NOTIFY	= 5;
+	public static int OSET_TOUCH_DOWN 		= 6;
+	public static int OSET_TOUCH_MOVE		= 7;
+	public static int OSET_TOUCH_UP			= 8;
+	public static int OSET_ACCELEROMETER	= 9; 
 }