summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiaquan He <hejq@google.com> 2016-01-13 15:46:52 -0800
committer Jiaquan He <hejq@google.com> 2016-01-14 02:36:58 +0000
commite7d716d5e35a4e6b5fcc1ff012942e4ad4933d1a (patch)
tree241f0f5f9fe8c32ce83ef00bb78c3e2cac88ca15
parentcc1251b9b23daa6e03000a9857c9e1a58c7e9e76 (diff)
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: <bookmark package="package" class="package.Class" shift="true" shortcut="z" /> Bug 26540880 Change-Id: Ib6d6ea59124226d4e4eb8ec9972059f2d71bd77e (cherry picked from commit e7319ecbbe865db8884914ceb10f526f4e160a64)
-rw-r--r--services/core/java/com/android/server/policy/ShortcutManager.java19
1 files 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 990862431799..928444275854 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<ShortcutInfo> mShortcuts = new SparseArray<>();
+ private final SparseArray<ShortcutInfo> 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<ShortcutInfo> 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);