fix(android): Correct gamepad device detection and stop breaking keyboard input - #127
Open
spydon wants to merge 1 commit into
Open
fix(android): Correct gamepad device detection and stop breaking keyboard input#127spydon wants to merge 1 commit into
spydon wants to merge 1 commit into
Conversation
…oard input The alphabetic-keyboard exclusion added in #66 only applied to the SOURCE_JOYSTICK branch due to operator precedence, so bluetooth keyboards claiming SOURCE_GAMEPAD were still registered as gamepads and had all their key events consumed. Conversely, controllers that expose an alphabetic keyboard profile but only claim SOURCE_JOYSTICK were rejected entirely. Devices are now classified by whether they report joystick-source motion ranges, which distinguishes keyboards from real controllers in both directions. Also degrade gracefully with a descriptive log instead of a ClassCastException when the host Activity does not implement GamepadsCompatibleActivity, and fix the README boilerplate so dispatchGenericMotionEvent falls back to super instead of swallowing all generic motion events. Fixes #70
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the Android device filter so bluetooth keyboards are no longer registered as gamepads (which caused all their key events to be consumed, breaking keyboard input app-wide), and so real controllers that expose a keyboard profile are no longer rejected.
Root causes
&&binds tighter than||), the check parsed asGAMEPAD || (JOYSTICK && notAlphabetic), so a keyboard claimingSOURCE_GAMEPADstill passed the filter. SinceEventListener.onKeyEventalways returnstrue, every keystroke from such a keyboard was consumed and never reached Flutter.KEYBOARD_TYPE_ALPHABETIC(common for 8BitDo and some bluetooth controllers) but only claimSOURCE_JOYSTICKwere rejected entirely, so they produced no gamepad events at all.Changes
GamepadsCompatibleActivity.isGamepadsInputDevice: rewritten with explicit logic. A device must have a gamepad or joystick source, and keyboards are distinguished from controllers by whether the device reports any joystick-source motion ranges (sticks, hats, triggers) instead of by keyboard type alone. This fixes both directions of the misclassification.GamepadsAndroidPlugin: the hardas GamepadsCompatibleActivitycast is now a safe cast with a descriptiveLog.epointing to the README setup, so apps whose MainActivity is missing the boilerplate no longer crash at startup with an opaqueClassCastException.listGamepadsreturns an empty list instead of throwing in that state.dispatchGenericMotionEventnow falls back tosuper.dispatchGenericMotionEventinstead of returningfalse, which previously swallowed all generic motion events (mouse hover, scroll wheel, trackpad) for the whole app.Note: the unconditional consumption of key events from registered gamepads (dpad/back navigation, #61) is intentionally left out of scope.
Fixes #70
Testing instructions
Verified that both the plugin and the README boilerplate compile by building a scratch Flutter app against the local
gamepads_android, once with a plainFlutterActivity(graceful-degradation path) and once with the README MainActivity.To verify on hardware:
gamepadswith the README MainActivity setup on an Android device.Gamepads.list().Gamepads.list()and emit button and axis events.GamepadsCompatibleActivityimplementation from MainActivity: the app should start normally and log an error explaining the missing setup instead of crashing.