[Android] Try to improve handling of DPAD|GAMEPAD + KEYBOARD devices It seems some devices report themselves as DPAD or GAMEPAD and KEYBOARD as well, and we need to route different keycodes to different parts of SDL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index 54670f8..cd7b0c2 100755
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -245,8 +245,8 @@ public class SDLActivity extends Activity {
public static native void nativePause();
public static native void nativeResume();
public static native void onNativeResize(int x, int y, int format);
- public static native void onNativePadDown(int padId, int keycode);
- public static native void onNativePadUp(int padId, int keycode);
+ public static native int onNativePadDown(int padId, int keycode);
+ public static native int onNativePadUp(int padId, int keycode);
public static native void onNativeJoy(int joyId, int axis,
float value);
public static native void onNativeKeyDown(int keycode);
@@ -600,19 +600,22 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// Dispatch the different events depending on where they come from
- // Some SOURCE_DPAD or SOURCE_GAMEPAD events appear to also be marked as SOURCE_KEYBOARD
- // So, to avoid problems, we process DPAD or GAMEPAD events first.
+ // Some SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
+ // So, we try to process them as DPAD or GAMEPAD events first, if that fails we try them as KEYBOARD
if ( (event.getSource() & 0x00000401) != 0 || /* API 12: SOURCE_GAMEPAD */
(event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {
int id = SDLActivity.getJoyId( event.getDeviceId() );
if (id != -1) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
- SDLActivity.onNativePadDown(id, keyCode);
+ if (SDLActivity.onNativePadDown(id, keyCode) == 0) {
+ return true;
+ }
} else if (event.getAction() == KeyEvent.ACTION_UP) {
- SDLActivity.onNativePadUp(id, keyCode);
+ if (SDLActivity.onNativePadUp(id, keyCode) == 0) {
+ return true;
+ }
}
- return true;
}
}
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 6feb48b..549d0a8 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -148,19 +148,19 @@ void Java_org_libsdl_app_SDLActivity_onNativeResize(
}
// Paddown
-void Java_org_libsdl_app_SDLActivity_onNativePadDown(
+int Java_org_libsdl_app_SDLActivity_onNativePadDown(
JNIEnv* env, jclass jcls,
jint padId, jint keycode)
{
- Android_OnPadDown(padId, keycode);
+ return Android_OnPadDown(padId, keycode);
}
// Padup
-void Java_org_libsdl_app_SDLActivity_onNativePadUp(
+int Java_org_libsdl_app_SDLActivity_onNativePadUp(
JNIEnv* env, jclass jcls,
jint padId, jint keycode)
{
- Android_OnPadUp(padId, keycode);
+ return Android_OnPadUp(padId, keycode);
}
/* Joy */
diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c
index bbed18a..3289a28 100644
--- a/src/joystick/android/SDL_sysjoystick.c
+++ b/src/joystick/android/SDL_sysjoystick.c
@@ -128,7 +128,6 @@ keycode_to_SDL(int keycode)
break;
default:
- SDL_Log("The button you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> Android KeyCode %d", keycode);
return -1;
break;
}
@@ -313,9 +312,10 @@ Android_OnPadDown(int padId, int keycode)
int button = keycode_to_SDL(keycode);
if (button >= 0) {
SDL_PrivateJoystickButton(SYS_Joysticks[padId], button , SDL_PRESSED);
+ return 0;
}
- return 0;
+ return -1;
}
int
@@ -324,9 +324,10 @@ Android_OnPadUp(int padId, int keycode)
int button = keycode_to_SDL(keycode);
if (button >= 0) {
SDL_PrivateJoystickButton(SYS_Joysticks[padId], button, SDL_RELEASED);
+ return 0;
}
- return 0;
+ return -1;
}
int