Multitouch detection + 1.5/1.6 devices support.

This commit is contained in:
shagrath 2011-06-29 21:06:09 +02:00
parent a3022a6f17
commit b3db7fb931
2 changed files with 75 additions and 28 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.ab.x48" android:installLocation="auto" android:versionName="1.28" android:versionCode="28">
package="org.ab.x48" android:installLocation="auto" android:versionName="1.29" android:versionCode="29">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".X48"
android:label="@string/app_name"

View file

@ -42,6 +42,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
protected boolean needFlip;
private short buf [];
private int currentOrientation;
private boolean multiTouch;
int buttons_coords [][] = new int [MAX_TOUCHES][4];
int icons_coords [][] = new int [6][2];
@ -56,6 +57,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
setFocusable(true);
setFocusableInTouchMode(true);
x48 = ((X48) context);
multiTouch = Wrapper.supportsMultitouch(x48);
mSurfaceHolder = getHolder();
mSurfaceHolder.addCallback(this);
mainScreen = Bitmap.createBitmap(262, 14+128, Bitmap.Config.RGB_565);
@ -483,12 +485,13 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
int code = -1;
int pointerID = 0;
if (multiTouch) {
if( actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_UP ||
actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP ) {
pointerID = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
x = event.getX(pointerID);
y = event.getY(pointerID);
pointerID = event.getPointerId(pointerID) + 1;
x = Wrapper.MotionEvent_getX(event, pointerID);
y = Wrapper.MotionEvent_getY(event, pointerID);
pointerID = Wrapper.MotionEvent_getPointerId(event, pointerID) + 1;
} else {
return false;
}
@ -519,6 +522,31 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
key(code, actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN, pointerID);
return true;
}
} else {
// old code used before the 1.29 version:
x = event.getX();
y = event.getY();
if (action != MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_UP)
return false;
for(int i=0;i<MAX_TOUCHES;i++) {
if (x >= buttons_coords[i][0] && x < buttons_coords[i][2] && y >= buttons_coords[i][1] && y < buttons_coords[i][3])
{
code = i;
break;
}
}
if (code == -1 && action == MotionEvent.ACTION_DOWN && currentOrientation != Configuration.ORIENTATION_LANDSCAPE ) {
((X48) getContext()).changeKeybLite();
return true;
}
if (code > -1) {
key(code, action == MotionEvent.ACTION_DOWN);
return action == MotionEvent.ACTION_DOWN;
}
}
}
return false;
@ -542,6 +570,16 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
//Log.i("x48", "code: " + code + " / " + down);
if (code < MAX_TOUCHES) {
if (down) {
if (!multiTouch) {
for(int i=0;i<MAX_TOUCHES;i++) {
if (touches[i] != 0) {
Log.i("x48", "no multitouch !, force up of " + i);
queuedCodes.add(i + 100);
touches [i] = 0;
break;
}
}
}
Integer cI = code+1;
if (!queuedCodes.contains(cI)) {
queuedCodes.add(cI);
@ -559,6 +597,15 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
touches [code] = 0;
} else {
Log.i("x48", "rejected up");
if (!multiTouch) {
for(int i=0;i<MAX_TOUCHES;i++) {
if (touches[i] != 0) {
Log.i("x48", "forced up of " + i);
queuedCodes.add(i + 100);
touches [i] = 0;
}
}
}
}
}
x48.flipScreen();