mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-13 07:03:54 +00:00
Fixed bug #13850: SDLControllerManager, we can use isVirtual() since API > 16
This commit is contained in:
@@ -1495,9 +1495,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputConnection ic) {
|
||||
int deviceId = event.getDeviceId();
|
||||
int source = event.getSource();
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
|
||||
if (source == InputDevice.SOURCE_UNKNOWN) {
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
if (device != null) {
|
||||
source = device.getSources();
|
||||
}
|
||||
@@ -1516,7 +1516,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
// Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
|
||||
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source
|
||||
// So, retrieve the device itself and check all of its sources
|
||||
if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) {
|
||||
if (SDLControllerManager.isDeviceSDLJoystick(device)) {
|
||||
// Note that we process events with specific key codes here
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
if (SDLControllerManager.onNativePadDown(deviceId, keyCode, event.getScanCode())) {
|
||||
|
||||
@@ -144,11 +144,9 @@ public class SDLControllerManager
|
||||
}
|
||||
|
||||
// Check if a given device is considered a possible SDL joystick
|
||||
static public boolean isDeviceSDLJoystick(int deviceId) {
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
// We cannot use InputDevice.isVirtual before API 16, so let's accept
|
||||
// only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
|
||||
if ((device == null) || (deviceId < 0)) {
|
||||
static public boolean isDeviceSDLJoystick(InputDevice device) {
|
||||
// No virtual device (eg nonnegative deviceId. VIRTUAL_KEYBOARD equals -1)
|
||||
if (device == null || device.isVirtual()) {
|
||||
return false;
|
||||
}
|
||||
int sources = device.getSources();
|
||||
@@ -171,6 +169,10 @@ public class SDLControllerManager
|
||||
((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
);
|
||||
}
|
||||
|
||||
static public boolean isDeviceSDLJoystick(int deviceId) {
|
||||
return isDeviceSDLJoystick(InputDevice.getDevice(deviceId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user