Multitouch detection + 1.5/1.6 devices support.
This commit is contained in:
parent
a3022a6f17
commit
b3db7fb931
2 changed files with 75 additions and 28 deletions
|
@ -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"
|
||||
|
|
|
@ -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,19 +485,51 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
|||
int code = -1;
|
||||
int pointerID = 0;
|
||||
|
||||
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;
|
||||
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 = Wrapper.MotionEvent_getX(event, pointerID);
|
||||
y = Wrapper.MotionEvent_getY(event, pointerID);
|
||||
pointerID = Wrapper.MotionEvent_getPointerId(event, pointerID) + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// *_DOWN : lookup by coordinates
|
||||
// *_UP : lookup by pointer pressed
|
||||
if( actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(int i=0;i<MAX_TOUCHES;i++) {
|
||||
if(touches[i] == pointerID)
|
||||
code = i;
|
||||
}
|
||||
}
|
||||
if (code == -1 && actionCode == MotionEvent.ACTION_DOWN && currentOrientation != Configuration.ORIENTATION_LANDSCAPE ) {
|
||||
//x48.flipkeyboard();
|
||||
((X48) getContext()).changeKeybLite();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (code > -1) {
|
||||
key(code, actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN, pointerID);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// *_DOWN : lookup by coordinates
|
||||
// *_UP : lookup by pointer pressed
|
||||
if( actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN ) {
|
||||
// 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])
|
||||
{
|
||||
|
@ -503,21 +537,15 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(int i=0;i<MAX_TOUCHES;i++) {
|
||||
if(touches[i] == pointerID)
|
||||
code = i;
|
||||
}
|
||||
}
|
||||
if (code == -1 && actionCode == MotionEvent.ACTION_DOWN && currentOrientation != Configuration.ORIENTATION_LANDSCAPE ) {
|
||||
//x48.flipkeyboard();
|
||||
((X48) getContext()).changeKeybLite();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (code > -1) {
|
||||
key(code, actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN, pointerID);
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue