diff --git a/.gitignore b/.gitignore index 9e9e916ebb..2e5b81f314 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Release Debug *.vcxproj.user +android/.settings diff --git a/android/app-android.cpp b/android/app-android.cpp index 5a6c5b27b3..27b26d05ff 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -24,6 +24,22 @@ #include "net/resolve.h" #include "android/native_audio.h" +// For Xperia Play support +enum AndroidKeyCodes { + KEYCODE_BUTTON_CROSS = 23, // trackpad or X button(Xperia Play) is pressed + KEYCODE_BUTTON_CIRCLE = 1004, // Special custom keycode generated from 'O' button by our java code. Or 'O' button if Alt is pressed (TODO) + KEYCODE_BUTTON_SQUARE = 99, // Square button(Xperia Play) is pressed + KEYCODE_BUTTON_TRIANGLE = 100, // 'Triangle button(Xperia Play) is pressed + KEYCODE_DPAD_LEFT = 21, + KEYCODE_DPAD_UP = 19, + KEYCODE_DPAD_RIGHT = 22, + KEYCODE_DPAD_DOWN = 20, + KEYCODE_BUTTON_L1 = 102, + KEYCODE_BUTTON_R1 = 103, + KEYCODE_BUTTON_START = 108, + KEYCODE_BUTTON_SELECT = 109, +}; + static JNIEnv *jniEnvUI; std::string frameCommand; @@ -282,36 +298,56 @@ extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_touch input_state.mouse_valid = true; } +static void AsyncDown(int padbutton) { + pad_buttons_async_set |= padbutton; + pad_buttons_async_clear &= ~padbutton; +} + +static void AsyncUp(int padbutton) { + pad_buttons_async_set &= ~padbutton; + pad_buttons_async_clear |= padbutton; +} + extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyDown(JNIEnv *, jclass, jint key) { switch (key) { - case 1: // Back - pad_buttons_async_set |= PAD_BUTTON_BACK; - pad_buttons_async_clear &= ~PAD_BUTTON_BACK; - break; - case 2: // Menu - pad_buttons_async_set |= PAD_BUTTON_MENU; - pad_buttons_async_clear &= ~PAD_BUTTON_MENU; - break; - case 3: // Search - pad_buttons_async_set |= PAD_BUTTON_A; - pad_buttons_async_clear &= ~PAD_BUTTON_A; + case 1: AsyncDown(PAD_BUTTON_BACK); break; // Back + case 2: AsyncDown(PAD_BUTTON_MENU); break; // Menu + case 3: AsyncDown(PAD_BUTTON_A); break; // Search + case KEYCODE_BUTTON_CROSS: AsyncDown(PAD_BUTTON_A); break; + case KEYCODE_BUTTON_CIRCLE: AsyncDown(PAD_BUTTON_B); break; + case KEYCODE_BUTTON_SQUARE: AsyncDown(PAD_BUTTON_X); break; + case KEYCODE_BUTTON_TRIANGLE: AsyncDown(PAD_BUTTON_Y); break; + case KEYCODE_DPAD_LEFT: AsyncDown(PAD_BUTTON_LEFT); break; + case KEYCODE_DPAD_UP: AsyncDown(PAD_BUTTON_UP); break; + case KEYCODE_DPAD_RIGHT: AsyncDown(PAD_BUTTON_RIGHT); break; + case KEYCODE_DPAD_DOWN: AsyncDown(PAD_BUTTON_LEFT); break; + case KEYCODE_BUTTON_L1: AsyncDown(PAD_BUTTON_LBUMPER); break; + case KEYCODE_BUTTON_R1: AsyncDown(PAD_BUTTON_RBUMPER); break; + case KEYCODE_BUTTON_START: AsyncDown(PAD_BUTTON_START); break; + case KEYCODE_BUTTON_SELECT: AsyncDown(PAD_BUTTON_SELECT); break; + default: break; } } extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyUp(JNIEnv *, jclass, jint key) { switch (key) { - case 1: // Back - pad_buttons_async_set &= ~PAD_BUTTON_BACK; - pad_buttons_async_clear |= PAD_BUTTON_BACK; - break; - case 2: // Menu - pad_buttons_async_set &= ~PAD_BUTTON_MENU; - pad_buttons_async_clear |= PAD_BUTTON_MENU; - break; - case 3: // Search - pad_buttons_async_set &= ~PAD_BUTTON_A; - pad_buttons_async_clear |= PAD_BUTTON_A; + case 1: AsyncUp(PAD_BUTTON_BACK); break; // Back + case 2: AsyncUp(PAD_BUTTON_MENU); break; // Menu + case 3: AsyncUp(PAD_BUTTON_A); break; // Search + case KEYCODE_BUTTON_CROSS: AsyncUp(PAD_BUTTON_A); break; + case KEYCODE_BUTTON_CIRCLE: AsyncUp(PAD_BUTTON_B); break; + case KEYCODE_BUTTON_SQUARE: AsyncUp(PAD_BUTTON_X); break; + case KEYCODE_BUTTON_TRIANGLE: AsyncUp(PAD_BUTTON_Y); break; + case KEYCODE_DPAD_LEFT: AsyncUp(PAD_BUTTON_LEFT); break; + case KEYCODE_DPAD_UP: AsyncUp(PAD_BUTTON_UP); break; + case KEYCODE_DPAD_RIGHT: AsyncUp(PAD_BUTTON_RIGHT); break; + case KEYCODE_DPAD_DOWN: AsyncUp(PAD_BUTTON_LEFT); break; + case KEYCODE_BUTTON_L1: AsyncUp(PAD_BUTTON_LBUMPER); break; + case KEYCODE_BUTTON_R1: AsyncUp(PAD_BUTTON_RBUMPER); break; + case KEYCODE_BUTTON_START: AsyncUp(PAD_BUTTON_START); break; + case KEYCODE_BUTTON_SELECT: AsyncUp(PAD_BUTTON_SELECT); break; + default: break; } } diff --git a/android/src/com/henrikrydgard/libnative/NativeActivity.java b/android/src/com/henrikrydgard/libnative/NativeActivity.java index ed9eff8f6e..8e0791dfc8 100644 --- a/android/src/com/henrikrydgard/libnative/NativeActivity.java +++ b/android/src/com/henrikrydgard/libnative/NativeActivity.java @@ -242,19 +242,24 @@ public class NativeActivity extends Activity { // Eat these keys, to avoid accidental exits / other screwups. // Maybe there's even more we need to eat on tablets? if (keyCode == KeyEvent.KEYCODE_BACK) { - NativeApp.keyDown(1); - return true; + if (event.isAltPressed()) { + NativeApp.keyDown(1004); // special custom keycode + } else { + NativeApp.keyDown(1); + } } else if (keyCode == KeyEvent.KEYCODE_MENU) { NativeApp.keyDown(2); - return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { NativeApp.keyDown(3); - return true; } - // Don't process any other keys. - return false; + else { + // send the rest of the keys through. + // TODO: get rid of the three special cases above by adjusting the native side of the code. + NativeApp.keyDown(keyCode); + } + return true; } @Override @@ -262,25 +267,29 @@ public class NativeActivity extends Activity { // Eat these keys, to avoid accidental exits / other screwups. // Maybe there's even more we need to eat on tablets? if (keyCode == KeyEvent.KEYCODE_BACK) { - if (NativeApp.isAtTopLevel()) { + if (event.isAltPressed()) { + NativeApp.keyUp(1004); // special custom keycode + } + else if (NativeApp.isAtTopLevel()) { return false; } else { NativeApp.keyUp(1); - return true; } } else if (keyCode == KeyEvent.KEYCODE_MENU) { // Menu should be ignored from SDK 11 forwards. We send it to the app. NativeApp.keyUp(2); - return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { // Search probably should also be ignored. We send it to the app. NativeApp.keyUp(3); - return true; } - // All other keys retain their default behavior. - return false; + else { + // send the rest of the keys through. + // TODO: get rid of the three special cases above by adjusting the native side of the code. + NativeApp.keyUp(keyCode); + } + return true; } // Prevent destroying and recreating the main activity when the device rotates etc, @@ -310,13 +319,11 @@ public class NativeActivity extends Activity { .setView(fl) .setTitle(title) .setPositiveButton(defaultAction, new DialogInterface.OnClickListener(){ - @Override public void onClick(DialogInterface d, int which) { d.dismiss(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener(){ - @Override public void onClick(DialogInterface d, int which) { d.cancel(); NativeActivity.inputBoxCancelled = false; diff --git a/android/src/com/henrikrydgard/libnative/NativeGLView.java b/android/src/com/henrikrydgard/libnative/NativeGLView.java index 3d2dec1fce..6dafdc54ae 100644 --- a/android/src/com/henrikrydgard/libnative/NativeGLView.java +++ b/android/src/com/henrikrydgard/libnative/NativeGLView.java @@ -87,12 +87,10 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener { } // Sensor management - @Override public void onAccuracyChanged(Sensor sensor, int arg1) { Log.i(TAG, "onAccuracyChanged"); } - @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; diff --git a/android/src/com/henrikrydgard/libnative/NativeRenderer.java b/android/src/com/henrikrydgard/libnative/NativeRenderer.java index ea5573eb9a..bb63f4b07b 100644 --- a/android/src/com/henrikrydgard/libnative/NativeRenderer.java +++ b/android/src/com/henrikrydgard/libnative/NativeRenderer.java @@ -16,19 +16,16 @@ public class NativeRenderer implements GLSurfaceView.Renderer { } - @Override public void onDrawFrame(GL10 unused /*use GLES20*/) { displayRender(); } - @Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { Log.i(TAG, "onSurfaceCreated - EGL context is new or was lost"); // Actually, it seems that it is here we should recreate lost GL objects. displayInit(); } - @Override public void onSurfaceChanged(GL10 unused, int width, int height) { Log.i(TAG, "onSurfaceChanged"); displayResize(width, height); @@ -50,7 +47,6 @@ public class NativeRenderer implements GLSurfaceView.Renderer { final String cmd = command; final String param = parameter; mActivity.runOnUiThread(new Runnable() { - @Override public void run() { NativeRenderer.this.mActivity.processCommand(cmd, param); }