diff options
| author | 2018-02-26 15:02:59 -0800 | |
|---|---|---|
| committer | 2018-03-12 17:53:57 -0700 | |
| commit | d842533f224280484839b77d016c2e8da697a0ed (patch) | |
| tree | ae8a8110997d8a36484ce807b9fdbedd5e18f23b | |
| parent | 2b83982b2b8a0e2772a0f44def8007f274cb8376 (diff) | |
Display shortcut modifiers in menu
Prepend relevant meta key names (such as Ctrl+) to the shortcut
displayed in a menu.
Do not prepend "Menu+" if the device does not have a hardware Menu key.
Bug: 31045453
Test: run ApiDemos (MenuInflateFromXml), select "Shortcuts", observe
Ctrl+ prepended to shortcuts.
Change-Id: I1a38bd1baf069dd1adb24a26f89c6db6390b8b8d
(cherry picked from commit 0cc2c6b190695ef78029c7b05a175fb3bb7e4098)
| -rw-r--r-- | core/java/com/android/internal/view/menu/MenuItemImpl.java | 63 | ||||
| -rw-r--r-- | core/res/res/values/strings.xml | 12 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 6 |
3 files changed, 56 insertions, 25 deletions
diff --git a/core/java/com/android/internal/view/menu/MenuItemImpl.java b/core/java/com/android/internal/view/menu/MenuItemImpl.java index 9d012de33089..0c5ea6327dff 100644 --- a/core/java/com/android/internal/view/menu/MenuItemImpl.java +++ b/core/java/com/android/internal/view/menu/MenuItemImpl.java @@ -23,6 +23,7 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.res.ColorStateList; +import android.content.res.Resources; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.util.Log; @@ -33,6 +34,7 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewDebug; import android.widget.LinearLayout; @@ -108,13 +110,6 @@ public final class MenuItemImpl implements MenuItem { private CharSequence mContentDescription; private CharSequence mTooltipText; - private static String sLanguage; - private static String sPrependShortcutLabel; - private static String sEnterShortcutLabel; - private static String sDeleteShortcutLabel; - private static String sSpaceShortcutLabel; - - /** * Instantiates this menu item. * @@ -130,20 +125,6 @@ public final class MenuItemImpl implements MenuItem { MenuItemImpl(MenuBuilder menu, int group, int id, int categoryOrder, int ordering, CharSequence title, int showAsAction) { - String lang = menu.getContext().getResources().getConfiguration().locale.toString(); - if (sPrependShortcutLabel == null || !lang.equals(sLanguage)) { - sLanguage = lang; - // This is instantiated from the UI thread, so no chance of sync issues - sPrependShortcutLabel = menu.getContext().getResources().getString( - com.android.internal.R.string.prepend_shortcut_label); - sEnterShortcutLabel = menu.getContext().getResources().getString( - com.android.internal.R.string.menu_enter_shortcut_label); - sDeleteShortcutLabel = menu.getContext().getResources().getString( - com.android.internal.R.string.menu_delete_shortcut_label); - sSpaceShortcutLabel = menu.getContext().getResources().getString( - com.android.internal.R.string.menu_space_shortcut_label); - } - mMenu = menu; mId = id; mGroup = group; @@ -353,19 +334,45 @@ public final class MenuItemImpl implements MenuItem { return ""; } - StringBuilder sb = new StringBuilder(sPrependShortcutLabel); + final Resources res = mMenu.getContext().getResources(); + + StringBuilder sb = new StringBuilder(); + if (ViewConfiguration.get(mMenu.getContext()).hasPermanentMenuKey()) { + // Only prepend "Menu+" if there is a hardware menu key. + sb.append(res.getString( + com.android.internal.R.string.prepend_shortcut_label)); + } + + final int modifiers = + mMenu.isQwertyMode() ? mShortcutAlphabeticModifiers : mShortcutNumericModifiers; + appendModifier(sb, modifiers, KeyEvent.META_META_ON, res.getString( + com.android.internal.R.string.menu_meta_shortcut_label)); + appendModifier(sb, modifiers, KeyEvent.META_CTRL_ON, res.getString( + com.android.internal.R.string.menu_ctrl_shortcut_label)); + appendModifier(sb, modifiers, KeyEvent.META_ALT_ON, res.getString( + com.android.internal.R.string.menu_alt_shortcut_label)); + appendModifier(sb, modifiers, KeyEvent.META_SHIFT_ON, res.getString( + com.android.internal.R.string.menu_shift_shortcut_label)); + appendModifier(sb, modifiers, KeyEvent.META_SYM_ON, res.getString( + com.android.internal.R.string.menu_sym_shortcut_label)); + appendModifier(sb, modifiers, KeyEvent.META_FUNCTION_ON, res.getString( + com.android.internal.R.string.menu_function_shortcut_label)); + switch (shortcut) { case '\n': - sb.append(sEnterShortcutLabel); + sb.append(res.getString( + com.android.internal.R.string.menu_enter_shortcut_label)); break; case '\b': - sb.append(sDeleteShortcutLabel); + sb.append(res.getString( + com.android.internal.R.string.menu_delete_shortcut_label)); break; case ' ': - sb.append(sSpaceShortcutLabel); + sb.append(res.getString( + com.android.internal.R.string.menu_space_shortcut_label)); break; default: @@ -376,6 +383,12 @@ public final class MenuItemImpl implements MenuItem { return sb.toString(); } + private static void appendModifier(StringBuilder sb, int mask, int modifier, String label) { + if ((mask & modifier) == modifier) { + sb.append(label); + } + } + /** * @return Whether this menu item should be showing shortcuts (depends on * whether the menu should show shortcuts and whether this item has diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index dc937e63c11e..20cc44d55b6f 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2447,6 +2447,18 @@ <string name="more_item_label">More</string> <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the MENU button together with the shortcut to invoke the item. For example, if the shortcut to open a new tab in browser is MENU and B together, then this would be prepended to the letter "B" --> <string name="prepend_shortcut_label">Menu+</string> + <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the META key together with the shortcut to invoke the item. --> + <string name="menu_meta_shortcut_label">Meta+</string> + <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the CTRL key together with the shortcut to invoke the item. --> + <string name="menu_ctrl_shortcut_label">Ctrl+</string> + <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the ALT key together with the shortcut to invoke the item. --> + <string name="menu_alt_shortcut_label">Alt+</string> + <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the SHIFT key together with the shortcut to invoke the item. --> + <string name="menu_shift_shortcut_label">Shift+</string> + <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the SYM key together with the shortcut to invoke the item. --> + <string name="menu_sym_shortcut_label">Sym+</string> + <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the FUNCTION key together with the shortcut to invoke the item. --> + <string name="menu_function_shortcut_label">Function+</string> <!-- Displayed in place of the regular shortcut letter when a menu item has Menu+space for the shortcut. --> <string name="menu_space_shortcut_label">space</string> <!-- Displayed in place of the regular shortcut letter when a menu item has Menu+enter for the shortcut. --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 97116f54e7c9..30193a81d778 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -528,9 +528,15 @@ <java-symbol type="string" name="delete" /> <java-symbol type="string" name="deleteText" /> <java-symbol type="string" name="grant_permissions_header_text" /> + <java-symbol type="string" name="menu_alt_shortcut_label" /> + <java-symbol type="string" name="menu_ctrl_shortcut_label" /> <java-symbol type="string" name="menu_delete_shortcut_label" /> <java-symbol type="string" name="menu_enter_shortcut_label" /> + <java-symbol type="string" name="menu_function_shortcut_label" /> + <java-symbol type="string" name="menu_meta_shortcut_label" /> <java-symbol type="string" name="menu_space_shortcut_label" /> + <java-symbol type="string" name="menu_shift_shortcut_label" /> + <java-symbol type="string" name="menu_sym_shortcut_label" /> <java-symbol type="string" name="notification_title" /> <java-symbol type="string" name="permission_request_notification_with_subtitle" /> <java-symbol type="string" name="prepend_shortcut_label" /> |