Fixed bug 3444 - Android-TV: no more handling of back button on remote

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.
This commit is contained in:
Sam Lantinga 2016-10-17 22:09:22 -07:00
parent 8109b1378a
commit ae8ca7c54d
2 changed files with 9 additions and 8 deletions

View File

@ -1245,14 +1245,15 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// 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;
}
}
}

View File

@ -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;
@ -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;