Skip to content

Commit 1c51be8

Browse files
alemartSiegeLord
authored andcommitted
Android: make detection of game controllers more robust
1 parent 95e2806 commit 1c51be8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

android/gradle_project/allegro/src/main/java/org/liballeg/android/AllegroActivity.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,14 @@ String getOsVersion()
542542
private boolean isJoystick(int id) {
543543
InputDevice input = InputDevice.getDevice(id);
544544
int sources = input.getSources();
545-
if ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) {
546-
return true;
547-
}
548-
return false;
545+
546+
// the device is a game controller if it has gamepad buttons, control sticks, or both
547+
boolean hasAnalogSticks = ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK);
548+
boolean hasGamepadButtons = ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD);
549+
550+
return hasGamepadButtons || hasAnalogSticks;
549551
}
552+
550553
public void reconfigureJoysticks() {
551554
joysticks.clear();
552555

0 commit comments

Comments
 (0)