From 014daafa2ab7a821beaf6041c68c50f8baf60b83 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Fri, 4 Apr 2014 01:12:07 -0400 Subject: [PATCH] Fix return intent from games, Fix touchscreen in native mode --- shell/android/jni/src/XperiaPlay.c | 19 +++++++++------ .../com/reicast/emulator/GL2JNINative.java | 24 +++++++++---------- .../com/reicast/emulator/MainActivity.java | 6 +++-- .../com/reicast/emulator/periph/Gamepad.java | 3 ++- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/shell/android/jni/src/XperiaPlay.c b/shell/android/jni/src/XperiaPlay.c index 89bebc8b0..716a19c56 100755 --- a/shell/android/jni/src/XperiaPlay.c +++ b/shell/android/jni/src/XperiaPlay.c @@ -50,7 +50,8 @@ static jobject g_pActivity = 0; static jmethodID javaOnNDKTouch = 0; static jmethodID javaOnNDKKey = 0; -int target; +//int target; +static bool isXperiaPlay; /** * Our saved state data. @@ -146,12 +147,14 @@ engine_handle_input( struct android_app* app, AInputEvent* event ) touchstate[nPointerId].x = AMotionEvent_getX( event, n ); touchstate[nPointerId].y = AMotionEvent_getY( event, n ); } - if( jni && g_pActivity && device == target ) { + //if( jni && g_pActivity && device == target ) { + if( jni && g_pActivity && isXperiaPlay) { (*jni)->CallVoidMethod( jni, g_pActivity, javaOnNDKTouch, device, nSourceId, nRawAction, touchstate[nPointerId].x, touchstate[nPointerId].y, newTouch); } newTouch = JNI_FALSE; } - if( device == target ) { +// if( device == target ) { + if( isXperiaPlay ) { return 1; } else { return 0; @@ -225,6 +228,8 @@ android_main( struct android_app* state ) //JNIEnv *env; //(*jVM)->AttachCurrentThread(jVM, &env, NULL); + isXperiaPlay = IsXperiaPlay(); + if( state->savedState != NULL ) { // We are starting with a previous saved state; restore from it. @@ -262,10 +267,10 @@ void EXPORT_XPLAY JNICALL Java_com_reicast_emulator_GL2JNINative_registerNative( { g_pActivity = (jobject)(*env)->NewGlobalRef(env, clazz); } -void EXPORT_XPLAY JNICALL Java_com_reicast_emulator_GL2JNINative_registerXperia(JNIEnv *env, jobject clazz, jint xperia) -{ - target = xperia; -} +//void EXPORT_XPLAY JNICALL Java_com_reicast_emulator_GL2JNINative_registerXperia(JNIEnv *env, jobject clazz, jint xperia) +//{ +// target = xperia; +//} jint EXPORT_XPLAY JNICALL JNI_OnLoad(JavaVM * vm, void * reserved) { JNIEnv *env; diff --git a/shell/android/src/com/reicast/emulator/GL2JNINative.java b/shell/android/src/com/reicast/emulator/GL2JNINative.java index 5a04e6ace..949cd5e1c 100644 --- a/shell/android/src/com/reicast/emulator/GL2JNINative.java +++ b/shell/android/src/com/reicast/emulator/GL2JNINative.java @@ -56,7 +56,7 @@ public class GL2JNINative extends NativeActivity { } public native void registerNative(); - public native void registerXperia(int xperia); +// public native void registerXperia(int xperia); @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override @@ -142,12 +142,12 @@ public class GL2JNINative extends NativeActivity { if (pad.isXperiaPlay) { if (InputDevice.getDevice(joy).getName() .contains(Gamepad.controllers_play_gp)) { - pad.keypadZeus.add(joy); + pad.keypadZeus[0] = joy; } if (InputDevice.getDevice(joy).getName() - .contains("synaptics_touchpad")) { - registerXperia(joy); - pad.keypadZeus.add(joy); + .contains(Gamepad.controllers_play_tp)) { +// registerXperia(joy); + pad.keypadZeus[1] = joy; } } Log.d("reidc", "InputDevice Descriptor: " + descriptor); @@ -515,12 +515,12 @@ public class GL2JNINative extends NativeActivity { return false; } - public boolean OnNativeMotion(int device, int source, int action, int x, int y, boolean newEvent) { - if (newEvent && source == Gamepad.Xperia_Touchpad) { - // Source is Xperia Play touchpad - Integer playerNum = pad.playerNumX.get(device); - if (playerNum != null && playerNum != -1) { - Log.d("reidc", playerNum + " - " + device + ": " + source); + public boolean OnNativeMotion(int device, int source, int action, int x, + int y, boolean newEvent) { + Integer playerNum = pad.playerNumX.get(device); + if (playerNum != null && playerNum != -1) { + Log.d("reidc", playerNum + " - " + device + ": " + source); + if (newEvent && source == Gamepad.Xperia_Touchpad) { if (action == MotionEvent.ACTION_UP) { x = 0; y = 0; @@ -532,7 +532,7 @@ public class GL2JNINative extends NativeActivity { x = 640; } if (x >= 640) { - x = x - 640; + x = x - 640; } y = 366 - y; // Right stick is an extension of left stick diff --git a/shell/android/src/com/reicast/emulator/MainActivity.java b/shell/android/src/com/reicast/emulator/MainActivity.java index 5402a3cb3..cc9acee19 100644 --- a/shell/android/src/com/reicast/emulator/MainActivity.java +++ b/shell/android/src/com/reicast/emulator/MainActivity.java @@ -111,8 +111,10 @@ public class MainActivity extends SlidingFragmentActivity implements // When viewing a resource, pass its URI to the native code for opening Intent intent = getIntent(); - if (intent.getAction().equals(Intent.ACTION_VIEW)) - onGameSelected(Uri.parse(intent.getData().toString())); + if (intent.getAction() != null) { + if (intent.getAction().equals(Intent.ACTION_VIEW)) + onGameSelected(Uri.parse(intent.getData().toString())); + } // Check that the activity is using the layout version with // the fragment_container FrameLayout diff --git a/shell/android/src/com/reicast/emulator/periph/Gamepad.java b/shell/android/src/com/reicast/emulator/periph/Gamepad.java index 1a91024dc..923dabcff 100644 --- a/shell/android/src/com/reicast/emulator/periph/Gamepad.java +++ b/shell/android/src/com/reicast/emulator/periph/Gamepad.java @@ -47,6 +47,7 @@ public class Gamepad { public static final String controllers_shield = "NVIDIA Corporation NVIDIA Controller"; public static final String controllers_play = "keypad-zeus"; public static final String controllers_play_gp = "keypad-game-zeus"; + public static final String controllers_play_tp = "synaptics_touchpad"; public String[] portId = { "_A", "_B", "_C", "_D" }; public boolean[] compat = { false, false, false, false }; @@ -65,7 +66,7 @@ public class Gamepad { public boolean isMogaPro[] = { false, false, false, false }; public SparseArray playerNumX = new SparseArray(); - public List keypadZeus = new ArrayList(); + public int[] keypadZeus = new int[2]; public boolean isXperiaPlay; public boolean isOuyaOrTV;