From e7d716d5e35a4e6b5fcc1ff012942e4ad4933d1a Mon Sep 17 00:00:00 2001 From: Jiaquan He Date: Wed, 13 Jan 2016 15:46:52 -0800 Subject: [PATCH] Add support for shortcuts with the shift key. Now shortcuts with the shift key can be defined in frameworks/base/packages/SettingsProvider/res/xml/bookmarks.xml. Sample: Bug 26540880 Change-Id: Ib6d6ea59124226d4e4eb8ec9972059f2d71bd77e (cherry picked from commit e7319ecbbe865db8884914ceb10f526f4e160a64) --- .../server/policy/ShortcutManager.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/policy/ShortcutManager.java b/services/core/java/com/android/server/policy/ShortcutManager.java index 9908624317991..9284442758546 100644 --- a/services/core/java/com/android/server/policy/ShortcutManager.java +++ b/services/core/java/com/android/server/policy/ShortcutManager.java @@ -26,6 +26,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.SparseArray; import android.view.KeyCharacterMap; +import android.view.KeyEvent; import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -47,8 +48,10 @@ class ShortcutManager { private static final String ATTRIBUTE_CLASS = "class"; private static final String ATTRIBUTE_SHORTCUT = "shortcut"; private static final String ATTRIBUTE_CATEGORY = "category"; + private static final String ATTRIBUTE_SHIFT = "shift"; private final SparseArray mShortcuts = new SparseArray<>(); + private final SparseArray mShiftShortcuts = new SparseArray<>(); private final Context mContext; @@ -75,17 +78,21 @@ class ShortcutManager { public Intent getIntent(KeyCharacterMap kcm, int keyCode, int metaState) { ShortcutInfo shortcut = null; + // If the Shift key is preesed, then search for the shift shortcuts. + boolean isShiftOn = (metaState & KeyEvent.META_SHIFT_ON) == KeyEvent.META_SHIFT_ON; + SparseArray shortcutMap = isShiftOn ? mShiftShortcuts : mShortcuts; + // First try the exact keycode (with modifiers). int shortcutChar = kcm.get(keyCode, metaState); if (shortcutChar != 0) { - shortcut = mShortcuts.get(shortcutChar); + shortcut = shortcutMap.get(shortcutChar); } // Next try the primary character on that key. if (shortcut == null) { shortcutChar = Character.toLowerCase(kcm.getDisplayLabel(keyCode)); if (shortcutChar != 0) { - shortcut = mShortcuts.get(shortcutChar); + shortcut = shortcutMap.get(shortcutChar); } } @@ -114,6 +121,7 @@ class ShortcutManager { String className = parser.getAttributeValue(null, ATTRIBUTE_CLASS); String shortcutName = parser.getAttributeValue(null, ATTRIBUTE_SHORTCUT); String categoryName = parser.getAttributeValue(null, ATTRIBUTE_CATEGORY); + String shiftName = parser.getAttributeValue(null, ATTRIBUTE_SHIFT); if (TextUtils.isEmpty(shortcutName)) { Log.w(TAG, "Unable to get shortcut for: " + packageName + "/" + className); @@ -121,6 +129,7 @@ class ShortcutManager { } final int shortcutChar = shortcutName.charAt(0); + final boolean isShiftShortcut = (shiftName != null && shiftName.equals("true")); final Intent intent; final String title; @@ -158,7 +167,11 @@ class ShortcutManager { } ShortcutInfo shortcut = new ShortcutInfo(title, intent); - mShortcuts.put(shortcutChar, shortcut); + if (isShiftShortcut) { + mShiftShortcuts.put(shortcutChar, shortcut); + } else { + mShortcuts.put(shortcutChar, shortcut); + } } } catch (XmlPullParserException e) { Log.w(TAG, "Got exception parsing bookmarks.", e);