Update touch code
This commit is contained in:
parent
cd81aa82ea
commit
e33ceda57a
1 changed files with 42 additions and 16 deletions
|
@ -501,28 +501,54 @@ View.OnKeyListener, View.OnTouchListener {
|
||||||
|
|
||||||
// Touch events
|
// Touch events
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
final int touchDevId = event.getDeviceId();
|
/* Ref: http://developer.android.com/training/gestures/multi.html */
|
||||||
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);
|
final int touchDevId = event.getDeviceId();
|
||||||
float y = event.getY(actionPointerIndex);
|
final int pointerCount = event.getPointerCount();
|
||||||
|
int action = event.getActionMasked();
|
||||||
|
int pointerFingerId;
|
||||||
|
int mouseButton;
|
||||||
|
int i = -1;
|
||||||
|
float x,y;
|
||||||
|
switch(action) {
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
for (i = 0; i < pointerCount; i++) {
|
||||||
|
pointerFingerId = event.getPointerId(i);
|
||||||
|
x = event.getX(i);
|
||||||
|
y = event.getY(i);
|
||||||
|
XashActivity.nativeTouch(pointerFingerId, action, x, y);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
// Primary pointer up/down, the index is always zero
|
||||||
|
i = 0;
|
||||||
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
|
// Non primary pointer up/down
|
||||||
|
if (i == -1) {
|
||||||
|
i = event.getActionIndex();
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
pointerFingerId = event.getPointerId(i);
|
||||||
x = event.getX(i);
|
x = event.getX(i);
|
||||||
y = event.getY(i);
|
y = event.getY(i);
|
||||||
XashActivity.nativeTouch(pointerFingerId, action, x, y);
|
XashActivity.nativeTouch(pointerFingerId, action, x, y);
|
||||||
}
|
break;
|
||||||
} else {
|
|
||||||
XashActivity.nativeTouch(pointerFingerId, action, x, y);
|
case MotionEvent.ACTION_CANCEL:
|
||||||
}
|
for (i = 0; i < pointerCount; i++) {
|
||||||
|
pointerFingerId = event.getPointerId(i);
|
||||||
|
x = event.getX(i);
|
||||||
|
y = event.getY(i);
|
||||||
|
XashActivity.nativeTouch(pointerFingerId, action, x, y);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue