From 1d648a14a410f21eb679982c4c0977201d97aac1 Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Wed, 23 Mar 2016 17:09:02 +0000 Subject: [PATCH] Keyboard Shortcuts Helper: Include all System shortcuts Also add support for shortcuts with no base character or keycode, as needed by "Search" being triggered with just Meta. Bug: 27454997 Change-Id: I75bc9d22c30f9ebcdcbea3fb53f166d942dc7b90 --- .../android/view/KeyboardShortcutInfo.java | 2 +- packages/SystemUI/res/values/strings.xml | 25 +++++++++ .../systemui/statusbar/KeyboardShortcuts.java | 56 ++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/KeyboardShortcutInfo.java b/core/java/android/view/KeyboardShortcutInfo.java index c2bd347687a6c..eee925df50382 100644 --- a/core/java/android/view/KeyboardShortcutInfo.java +++ b/core/java/android/view/KeyboardShortcutInfo.java @@ -51,7 +51,7 @@ public final class KeyboardShortcutInfo implements Parcelable { mLabel = label; mIcon = icon; mBaseCharacter = MIN_VALUE; - checkArgument(keycode > KeyEvent.KEYCODE_UNKNOWN && keycode <= KeyEvent.getMaxKeyCode()); + checkArgument(keycode >= KeyEvent.KEYCODE_UNKNOWN && keycode <= KeyEvent.getMaxKeyCode()); mKeycode = keycode; mModifiers = modifiers; } diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index a523a411399fd..a01066d702625 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1388,6 +1388,31 @@ Recents Back + + Notifications + + Keyboard Shortcuts + + Switch input method + + + Applications + + Assist + + Browser + + Contacts + + Email + + IM + + Music + + YouTube + + Calendar Show with volume controls diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java index 8fe60a0d9d829..2b365dc743e99 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java @@ -245,7 +245,57 @@ public class KeyboardShortcuts { 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), + KeyEvent.KEYCODE_N, KeyEvent.META_META_ON)); + systemGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_system_shortcuts_helper), + KeyEvent.KEYCODE_SLASH, KeyEvent.META_META_ON)); + systemGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_system_switch_input), + KeyEvent.KEYCODE_SPACE, KeyEvent.META_META_ON)); result.add(systemGroup); + + KeyboardShortcutGroup applicationGroup = new KeyboardShortcutGroup( + mContext.getString(R.string.keyboard_shortcut_group_applications), + true); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_assist), + KeyEvent.KEYCODE_UNKNOWN, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_browser), + KeyEvent.KEYCODE_B, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_contacts), + KeyEvent.KEYCODE_C, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_email), + KeyEvent.KEYCODE_E, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_im), + KeyEvent.KEYCODE_T, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_music), + KeyEvent.KEYCODE_P, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_youtube), + KeyEvent.KEYCODE_Y, KeyEvent.META_META_ON)); + applicationGroup.addItem(new KeyboardShortcutInfo( + mContext.getString( + R.string.keyboard_shortcut_group_applications_calendar), + KeyEvent.KEYCODE_L, KeyEvent.META_META_ON)); + result.add(applicationGroup); + showKeyboardShortcutsDialog(result); } }, deviceId); @@ -354,11 +404,15 @@ public class KeyboardShortcuts { return null; } String displayLabelString; - if (info.getKeycode() == KeyEvent.KEYCODE_UNKNOWN) { + if (info.getBaseCharacter() > Character.MIN_VALUE) { displayLabelString = String.valueOf(info.getBaseCharacter()); } else if (SPECIAL_CHARACTER_NAMES.get(info.getKeycode()) != null) { displayLabelString = SPECIAL_CHARACTER_NAMES.get(info.getKeycode()); } else { + // Special case for shortcuts with no base key or keycode. + if (info.getKeycode() == KeyEvent.KEYCODE_UNKNOWN) { + return shortcutKeys; + } // TODO: Have a generic map for when we don't have the device's. char displayLabel = mKeyCharacterMap == null ? 0 : mKeyCharacterMap.getDisplayLabel(info.getKeycode());