summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Robert Horvath <robhor@google.com> 2023-05-03 09:19:34 +0000
committer Robert Horvath <robhor@google.com> 2023-06-28 12:03:02 +0000
commitbcb0d40688e8886cd01773f8ed4fdcf033c63f38 (patch)
treefdf94b22f0688fddc44f4c3a942c98affaf86686
parentf743000d35038e8c481a7a1a9e7ae93e8296a80e (diff)
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
-rw-r--r--packages/SystemUI/res/drawable/list_item_background.xml21
-rw-r--r--packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml5
-rw-r--r--packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java20
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/tv/TvSystemUIModule.java2
6 files changed, 52 insertions, 9 deletions
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 000000000000..2dbab9cfe984
--- /dev/null
+++ b/packages/SystemUI/res/drawable/list_item_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2023 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true" android:drawable="@*android:drawable/list_choice_background_material" />
+ <item android:drawable="@android:color/transparent" />
+</selector> \ 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 3786812db827..fcf9638440c7 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 @@
<com.android.systemui.statusbar.KeyboardShortcutAppItemLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
+ android:background="@drawable/list_item_background"
+ android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
@@ -55,6 +57,5 @@
android:layout_alignParentEnd="true"
android:textSize="14sp"
android:scrollHorizontally="false"
- android:layout_centerVertical="true"
- android:focusable="true"/>
+ android:layout_centerVertical="true"/>
</com.android.systemui.statusbar.KeyboardShortcutAppItemLayout>
diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml
index 8414223b7654..0759990f1677 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
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="14sp"
android:fontFamily="sans-serif-medium"
+ android:importantForAccessibility="yes"
android:paddingStart="24dp"
android:paddingTop="20dp"
android:paddingEnd="24dp"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
index a3fd82e9b140..ae3d41e19b5f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
@@ -440,10 +440,15 @@ public final class KeyboardShortcuts {
mContext.getString(R.string.keyboard_shortcut_group_system_back),
KeyEvent.KEYCODE_DEL,
KeyEvent.META_META_ON));
- systemGroup.addItem(new KeyboardShortcutInfo(
- mContext.getString(R.string.keyboard_shortcut_group_system_recents),
- KeyEvent.KEYCODE_TAB,
- KeyEvent.META_ALT_ON));
+
+ // Some devices (like TV) don't have recents
+ if (mContext.getResources().getBoolean(com.android.internal.R.bool.config_hasRecents)) {
+ systemGroup.addItem(new KeyboardShortcutInfo(
+ mContext.getString(R.string.keyboard_shortcut_group_system_recents),
+ KeyEvent.KEYCODE_TAB,
+ KeyEvent.META_ALT_ON));
+ }
+
systemGroup.addItem(new KeyboardShortcutInfo(
mContext.getString(
R.string.keyboard_shortcut_group_system_notifications),
@@ -683,8 +688,10 @@ public final class KeyboardShortcuts {
ViewGroup shortcutItemsContainer = (ViewGroup) shortcutView
.findViewById(R.id.keyboard_shortcuts_item_container);
final int shortcutKeysSize = shortcutKeys.size();
+ final List<String> 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 b1b8341d9584..d35d34063d1e 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 d9a8e0cfb53a..3f31ff94fee7 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 {