Simplification

This commit is contained in:
shagr4th 2014-09-20 10:05:11 +02:00
parent 03d4aa168b
commit 6c2d25db56
3 changed files with 38 additions and 185 deletions

View file

@ -52,7 +52,6 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
private short buf [];
private short audiobuf [];
int currentOrientation;
private boolean multiTouch;
private AudioTrack track;
private TimerTask audioTask;
private Timer audioTimer;
@ -103,7 +102,6 @@ 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);
@ -947,67 +945,44 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
int code = -1;
int pointerID = 0;
systemOptionDisplayed = false;
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 ) {
x48.openOptionsMenu();
return true;
}
if (code > -1) {
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.openOptionsMenu();
return true;
}
if (code > -1) {
key(code, action == MotionEvent.ACTION_DOWN);
return action == MotionEvent.ACTION_DOWN;
}
}
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;
} 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;
break;
}
}
}
if (code == -1 && actionCode == MotionEvent.ACTION_DOWN ) {
x48.openOptionsMenu();
return true;
}
if (code > -1) {
key(code, actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN, pointerID);
return true;
}
}
return false;
@ -1041,16 +1016,6 @@ 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);
@ -1068,15 +1033,6 @@ 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();

View file

@ -1,59 +0,0 @@
package org.ab.x48;
import android.content.Context;
import android.os.Build;
import android.view.MotionEvent;
public class Wrapper {
static final int SDK_INT = Integer.parseInt(Build.VERSION.SDK);
public static boolean supportsMultitouch(Context context) {
if (SDK_INT >= 5)
return Wrapper5.supportsMultitouch(context);
return false;
}
public static final int MotionEvent_getPointerCount(MotionEvent event) {
if (SDK_INT >= 5)
return Wrapper5.MotionEvent_getPointerCount(event);
return 1;
}
public static final int MotionEvent_getPointerId(MotionEvent event,
int pointerIndex) {
if (SDK_INT >= 5)
return Wrapper5.MotionEvent_getPointerId(event, pointerIndex);
return 0;
}
public static final int MotionEvent_findPointerIndex(MotionEvent event,
int pointerId) {
if (SDK_INT >= 5)
return Wrapper5.MotionEvent_findPointerIndex(event, pointerId);
if (pointerId == 0)
return 0;
return -1;
}
public static final float MotionEvent_getX(MotionEvent event,
int pointerIndex) {
if (SDK_INT >= 5)
return Wrapper5.MotionEvent_getX(event, pointerIndex);
return event.getX();
}
public static final float MotionEvent_getY(MotionEvent event,
int pointerIndex) {
if (SDK_INT >= 5)
return Wrapper5.MotionEvent_getY(event, pointerIndex);
return event.getY();
}
public static final float MotionEvent_getSize(MotionEvent event,
int pointerIndex) {
if (SDK_INT >= 5)
return Wrapper5.MotionEvent_getSize(event, pointerIndex);
return event.getSize();
}
}

View file

@ -1,44 +0,0 @@
package org.ab.x48;
import android.content.Context;
import android.content.pm.PackageManager;
import android.view.MotionEvent;
class Wrapper5 {
public static final boolean supportsMultitouch(Context context) {
if (Wrapper.SDK_INT < 7)
return true;
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
}
public static final int MotionEvent_getPointerCount(MotionEvent event) {
return event.getPointerCount();
}
public static final int MotionEvent_getPointerId(MotionEvent event,
int pointerIndex) {
return event.getPointerId(pointerIndex);
}
public static final int MotionEvent_findPointerIndex(MotionEvent event,
int pointerId) {
return event.findPointerIndex(pointerId);
}
public static final float MotionEvent_getX(MotionEvent event,
int pointerIndex) {
return event.getX(pointerIndex);
}
public static final float MotionEvent_getY(MotionEvent event,
int pointerIndex) {
return event.getY(pointerIndex);
}
public static final float MotionEvent_getSize(MotionEvent event,
int pointerIndex) {
return event.getSize(pointerIndex);
}
}