Skip to content

Map DPAD_DOWN to TAB in HAWebViewActivity#6735

Open
TimoPtr wants to merge 1 commit intomainfrom
dmap_mapping_androidtv
Open

Map DPAD_DOWN to TAB in HAWebViewActivity#6735
TimoPtr wants to merge 1 commit intomainfrom
dmap_mapping_androidtv

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented Apr 20, 2026

Summary

DPAD_DOWN to TAB remapping for Android TV

  • Extracted DPAD_DOWN mapping into HAWebView.kt
  • Applied automatically in HAWebView's factory block
  • Removed the dispatchKeyEvent override from WebViewActivity

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Copilot AI review requested due to automatic review settings April 20, 2026 15:06
@dshokouhi
Copy link
Copy Markdown
Member

you know i havent had a chance to recheck this but I wonder this is still necessary? at the time it was used to help android tv users login because they couldnt even switch to the password field using the remote control. This was before the frontend login screen was updated to be more modern. I do recall we have a bug from a keyboard only user getting stuck due to this one too.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR moves the Android TV DPAD_DOWN → TAB navigation workaround from the legacy WebViewActivity key dispatch override into the shared HAWebView composable, so the behavior is applied at the WebView level whenever HAWebView is used.

Changes:

  • Removed dispatchKeyEvent override (and KeyEvent import) from WebViewActivity
  • Added a WebView.remapDpadDownToTab() helper using an OnKeyListener
  • Applied the remapping automatically in HAWebView’s AndroidView.factory block and documented the behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt Removes the Activity-level DPAD_DOWN workaround, relying on WebView-level handling instead
app/src/main/kotlin/io/homeassistant/companion/android/util/compose/webview/HAWebView.kt Adds and applies DPAD_DOWN → TAB remapping via OnKeyListener, with updated KDoc

Comment on lines +137 to +146
private fun WebView.remapDpadDownToTab() {
setOnKeyListener { view, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && event.action == KeyEvent.ACTION_DOWN) {
view.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB))
true
} else {
false
}
}
}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new key-handling behavior (DPAD_DOWN -> TAB) but there is no automated test covering it. Please add a unit/Robolectric or Compose UI test that verifies a DPAD_DOWN key event dispatched to the WebView results in a TAB key event being forwarded, to prevent regressions across Android TV and non-TV devices.

Copilot generated this review using guidance from repository custom instructions.
@TimoPtr
Copy link
Copy Markdown
Member Author

TimoPtr commented Apr 20, 2026

you know i havent had a chance to recheck this but I wonder this is still necessary? at the time it was used to help android tv users login because they couldnt even switch to the password field using the remote control. This was before the frontend login screen was updated to be more modern. I do recall we have a bug from a keyboard only user getting stuck due to this one too.

Thanks for jumping in I remember discussing about it but I didn't remember what was the outcome .... So maybe it is not relevant anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants