Skip to content

Commit

Permalink
Fixed bug 3444 - Android-TV: no more handling of back button on remote
Browse files Browse the repository at this point in the history
ny00

Unfortunately, simply checking the return codes of "onNativePadDown/Up" as previously done has its own issue:

If an SDL joystick is connected *and* opened, then a proper KeyEvent, say with keycode KEYCODE_BUTTON_1, should lead to an SDL joystick button event as expected.

If, however, the joystick was *not* opened, then "onNativePadDown/Up" will return a negative value, so before the commit from bug 3426, you could unexpectedly get a keyboard event. (In practice, you'll just get a log message, since KEYCODE_BUTTON_1 has no mapping to a proper SDL_ScanCode value, but it's still an problem).

What should still be done, though, is checking the key code itself. We do have the KeyEvent.isGamepadButton method, but according my test, it returns "true" exactly (and only) for the KEYCODE_BUTTON* values, and not for KEYCODE_DPAD* or any other key code.

Here is a possible solution:
- Do check the return codes of "onNativePadDown/Up" as previously done.
- In addition, in "Android_OnPadDown/Up" from src/joystick/android/SDL_sysjoystick.c, 0 should *always* be returned in case the key code can be translated to an SDL_joystick button; Even if no matching joystick can be found.
  • Loading branch information
slouken committed Oct 18, 2016
1 parent 8109b13 commit ae8ca7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -1245,14 +1245,15 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source
// So, retrieve the device itself and check all of its sources
if (SDLActivity.isDeviceSDLJoystick(event.getDeviceId())) {
// Note that we always process a pressed/released button here, as an unopened
// SDL_Joystick's button press should not be processed as a keyboard's key press
// Note that we process events with specific key codes here
if (event.getAction() == KeyEvent.ACTION_DOWN) {
SDLActivity.onNativePadDown(event.getDeviceId(), keyCode);
return true;
if (SDLActivity.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
return true;
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
SDLActivity.onNativePadUp(event.getDeviceId(), keyCode);
return true;
if (SDLActivity.onNativePadUp(event.getDeviceId(), keyCode) == 0) {
return true;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/joystick/android/SDL_sysjoystick.c
Expand Up @@ -187,8 +187,8 @@ Android_OnPadDown(int device_id, int keycode)
item = JoystickByDeviceId(device_id);
if (item && item->joystick) {
SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
return 0;
}
return 0;
}

return -1;
Expand All @@ -203,8 +203,8 @@ Android_OnPadUp(int device_id, int keycode)
item = JoystickByDeviceId(device_id);
if (item && item->joystick) {
SDL_PrivateJoystickButton(item->joystick, button, SDL_RELEASED);
return 0;
}
return 0;
}

return -1;
Expand Down

0 comments on commit ae8ca7c

Please sign in to comment.