Finish voice input on D-pad center / Enter instead of canceling (Android TV)#2078
Open
PimpinPumpkin wants to merge 1 commit into
Open
Finish voice input on D-pad center / Enter instead of canceling (Android TV)#2078PimpinPumpkin wants to merge 1 commit into
PimpinPumpkin wants to merge 1 commit into
Conversation
On devices navigated by a D-pad or remote (e.g. Android TV) the IME window is focusable and initial focus lands on the action bar's back button. Pressing the D-pad center then activated that button and canceled dictation, with no way to "tap" the window to submit the result, since there is no touchscreen. Add an open ActionWindow.onKeyEvent hook, invoked via onPreviewKeyEvent on the action window container so it runs before focused composables consume the event. The voice input window overrides it to treat D-pad center / Enter / numpad Enter as a tap on the window: finish recognition and submit the result. Other windows are unaffected (the default implementation returns false). Cancel remains available via the system Back button.
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.
Summary
On Android TV (and other D-pad / remote driven devices), pressing the remote's center / "OK" button while the voice input window is open cancels dictation instead of finishing it. There is no touchscreen to "tap" the window, so there is currently no way to end dictation and submit the result using a remote.
Cause
On a device without a touchscreen the IME window is focusable, so the D-pad moves focus through the keyboard's Compose UI. When the voice input action window opens, initial focus lands on the back arrow in the action-bar header (
ActionWindowBar,onBack = { closeActionWindow(true) }). Pressing D-pad center then activates that button and cancels dictation. (Tapping the window — which callsrecognizerView.finish()— works on phones because touch bypasses focus.)Fix
ActionWindow.onKeyEvent(KeyEvent): Booleanhook (default returnsfalse).UixManagerviaModifier.onPreviewKeyEventon the action-window container, so it runs before the focused composable (the back button) consumes the key.VoiceInputActionWindowoverrides it to treat D-pad center / Enter / numpad Enter as a tap on the window: finish recognition and submit the result.Other action windows are unaffected (the default hook returns
false, so the event propagates normally). Cancel remains available via the system Back button.Notes
KEYCODE_DPAD_CENTER). With the fix, center finishes & submits; the system Back button still cancels.onPreviewKeyEventfires under exactly the focus condition that produces the unwanted cancel (the back button being focused), so it reliably intercepts the same event before the button does.