From bcb0d40688e8886cd01773f8ed4fdcf033c63f38 Mon Sep 17 00:00:00 2001 From: Robert Horvath Date: Wed, 3 May 2023 09:19:34 +0000 Subject: [PATCH] Add support for keyboard shortcuts panel on TV The keyboard shortcuts panel lists available shortcuts for the currently focused app + system shortcuts. Apps can request the panel to be shown by calling Activity#requestShowKeyboardShortcuts. Calling this method on TV caused SystemUI to crash, as KeyboardShortcutsReceiver couldn't be instantiated. Adding the KeyboardShortcutsModule on TV fixes this crash. Adding the override for toggleKeyboardShortcutsMenu in TvStatusBar enables the global toggle shortcuts panel shortcut to work. The other changes are to improve usability of the dialog on TV: - Make the list rows focusable - Give the whole row a suitable contentDescription for a11y - Give the items a background that highlights the focused row - Hide the "Recents" row on devices that do not support it (like TV) Bug: 278514212 Test: manual on TV device Change-Id: Ia8285d5b05ad909cecb16eb087cbbc56ed86475a --- .../res/drawable/list_item_background.xml | 21 +++++++++++++++++++ .../res/layout/keyboard_shortcut_app_item.xml | 5 +++-- .../keyboard_shortcuts_category_title.xml | 3 ++- .../systemui/statusbar/KeyboardShortcuts.java | 20 ++++++++++++++---- .../systemui/statusbar/tv/TvStatusBar.java | 10 +++++++-- .../android/systemui/tv/TvSystemUIModule.java | 2 ++ 6 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 packages/SystemUI/res/drawable/list_item_background.xml diff --git a/packages/SystemUI/res/drawable/list_item_background.xml b/packages/SystemUI/res/drawable/list_item_background.xml new file mode 100644 index 0000000000000..2dbab9cfe984d --- /dev/null +++ b/packages/SystemUI/res/drawable/list_item_background.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml b/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml index 3786812db8275..fcf9638440c7f 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml @@ -17,6 +17,8 @@ + android:layout_centerVertical="true"/> diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml index 8414223b76547..0759990f16773 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml @@ -16,10 +16,11 @@ ~ limitations under the License --> humanReadableShortcuts = new ArrayList<>(); for (int k = 0; k < shortcutKeysSize; k++) { StringDrawableContainer shortcutRepresentation = shortcutKeys.get(k); + humanReadableShortcuts.add(shortcutRepresentation.mString); if (shortcutRepresentation.mDrawable != null) { ImageView shortcutKeyIconView = (ImageView) inflater.inflate( R.layout.keyboard_shortcuts_key_icon_view, shortcutItemsContainer, @@ -714,6 +721,11 @@ public final class KeyboardShortcuts { shortcutItemsContainer.addView(shortcutKeyTextView); } } + CharSequence contentDescription = info.getLabel(); + if (!humanReadableShortcuts.isEmpty()) { + contentDescription += ": " + String.join(", ", humanReadableShortcuts); + } + shortcutView.setContentDescription(contentDescription); shortcutContainer.addView(shortcutView); } keyboardShortcutsLayout.addView(shortcutContainer); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java index b1b8341d95842..d35d34063d1e4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java @@ -27,11 +27,12 @@ import com.android.systemui.CoreStartable; import com.android.systemui.assist.AssistManager; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.statusbar.CommandQueue; - -import javax.inject.Inject; +import com.android.systemui.statusbar.KeyboardShortcuts; import dagger.Lazy; +import javax.inject.Inject; + /** * Status bar implementation for "large screen" products that mostly present no on-screen nav. * Serves as a collection of UI components, rather than showing its own UI. @@ -78,4 +79,9 @@ public class TvStatusBar implements CoreStartable, CommandQueue.Callbacks { new Intent(ACTION_SHOW_PIP_MENU).setPackage(mContext.getPackageName()), SYSTEMUI_PERMISSION); } + + @Override + public void toggleKeyboardShortcutsMenu(int deviceId) { + KeyboardShortcuts.show(mContext, deviceId); + } } diff --git a/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIModule.java b/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIModule.java index d9a8e0cfb53ae..3f31ff94fee7d 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIModule.java @@ -48,6 +48,7 @@ import com.android.systemui.shade.ShadeController; import com.android.systemui.shade.ShadeControllerImpl; import com.android.systemui.shade.ShadeExpansionStateManager; import com.android.systemui.statusbar.CommandQueue; +import com.android.systemui.statusbar.KeyboardShortcutsModule; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationLockscreenUserManager; import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl; @@ -96,6 +97,7 @@ import javax.inject.Named; ReferenceScreenshotModule.class, StatusBarEventsModule.class, VolumeModule.class, + KeyboardShortcutsModule.class } ) public abstract class TvSystemUIModule {