author | Xeli |
Fri, 19 Aug 2011 22:31:59 +0200 | |
branch | hedgeroid |
changeset 5613 | a7e40b20ce44 |
parent 5550 | 50650032c251 |
child 5621 | ea796c83ea47 |
permissions | -rw-r--r-- |
5546 | 1 |
package org.hedgewars.mobile.TouchInterface; |
2 |
||
3 |
import org.hedgewars.mobile.SDLActivity; |
|
4 |
||
5 |
import android.os.Build; |
|
6 |
import android.util.Log; |
|
7 |
import android.view.MotionEvent; |
|
8 |
import android.view.View; |
|
9 |
import android.view.View.OnTouchListener; |
|
10 |
||
11 |
public class TouchInterface{ |
|
12 |
||
13 |
public static OnTouchListener getTouchInterface(){ |
|
14 |
OnTouchListener toucher; |
|
15 |
if(Build.VERSION.SDK_INT < 5){//8 == Build.VERSION_CODES.FROYO |
|
16 |
toucher = new TouchInterfaceST(); |
|
17 |
}else{ |
|
18 |
toucher = new TouchInterfaceMT(); |
|
19 |
} |
|
20 |
||
21 |
return toucher; |
|
22 |
} |
|
23 |
} |
|
24 |
/** |
|
25 |
* Touch interface with multitouch |
|
26 |
*/ |
|
27 |
class TouchInterfaceMT implements OnTouchListener { |
|
28 |
||
29 |
private boolean firstEvent = true; |
|
30 |
||
31 |
public boolean onTouch(View v, MotionEvent event) { |
|
32 |
//dumpEvent(event); |
|
33 |
||
34 |
if(firstEvent){ |
|
35 |
firstEvent = false; |
|
36 |
SDLActivity.onNativeTouch(-1, -1, v.getWidth(), v.getHeight(), 1); |
|
37 |
} |
|
38 |
||
39 |
int action = event.getAction(); |
|
40 |
int actionCode = action & MotionEvent.ACTION_MASK; |
|
41 |
||
42 |
for (int i = 0; i < event.getPointerCount(); i++) { |
|
5550
50650032c251
Zoom and moving the camera now works with SDL_FINGER* events
Xeli
parents:
5546
diff
changeset
|
43 |
SDLActivity.onNativeTouch(actionCode, event.getPointerId(i), (int)event.getX(i), (int)event.getY(i), event.getPressure(i)); |
50650032c251
Zoom and moving the camera now works with SDL_FINGER* events
Xeli
parents:
5546
diff
changeset
|
44 |
// Log.d("Android", String.format("x=%f, y=%f, pntr=%d", event.getX(i), event.getY(i), event.getPointerId(i))); |
5546 | 45 |
} |
46 |
return true; |
|
47 |
} |
|
48 |
||
49 |
/** Show an event in the LogCat view, for debugging */ |
|
50 |
private void dumpEvent(MotionEvent event) { |
|
51 |
String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" , |
|
52 |
"POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" }; |
|
53 |
StringBuilder sb = new StringBuilder(); |
|
54 |
int action = event.getAction(); |
|
55 |
int actionCode = action & MotionEvent.ACTION_MASK; |
|
56 |
sb.append("event ACTION_" ).append(names[actionCode]); |
|
57 |
if (actionCode == MotionEvent.ACTION_POINTER_DOWN |
|
58 |
|| actionCode == MotionEvent.ACTION_POINTER_UP) { |
|
59 |
sb.append("(pid " ).append( |
|
60 |
action >> MotionEvent.ACTION_POINTER_ID_SHIFT); |
|
61 |
sb.append(")" ); |
|
62 |
} |
|
63 |
sb.append("[" ); |
|
64 |
for (int i = 0; i < event.getPointerCount(); i++) { |
|
65 |
sb.append("#" ).append(i); |
|
66 |
sb.append("(pid " ).append(event.getPointerId(i)); |
|
67 |
sb.append(")=" ).append((int) event.getX(i)); |
|
68 |
sb.append("," ).append((int) event.getY(i)); |
|
69 |
if (i + 1 < event.getPointerCount()) |
|
70 |
sb.append(";" ); |
|
71 |
} |
|
72 |
sb.append("]" ); |
|
73 |
Log.d("HW_APP_TOUCH", sb.toString()); |
|
74 |
} |
|
75 |
||
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Touch interface without multitouch |
|
80 |
*/ |
|
81 |
class TouchInterfaceST implements OnTouchListener { |
|
82 |
||
83 |
public boolean onTouch(View v, MotionEvent event) { |
|
84 |
return false; |
|
85 |
} |
|
86 |
||
87 |
||
88 |
||
89 |
} |
|
90 |