ShortcutManagerpublic class ShortcutManager extends android.database.ContentObserver Manages quick launch shortcuts by:
Keeping the local copy in sync with the database (this is an observer)
Returning a shortcut-matching intent to clients |
Fields Summary |
---|
private static final String | TAG | private static final int | COLUMN_SHORTCUT | private static final int | COLUMN_INTENT | private static final String[] | sProjection | private android.content.Context | mContext | private android.database.Cursor | mCursor | private android.util.SparseArray | mShortcutIntentsMap of a shortcut to its intent. |
Methods Summary |
---|
public android.content.Intent | getIntent(int keyCode, int modifiers)Gets the shortcut intent for a given keycode+modifier. Make sure you
strip whatever modifier is used for invoking shortcuts (for example,
if 'Sym+A' should invoke a shortcut on 'A', you should strip the
'Sym' bit from the modifiers before calling this method.
This will first try an exact match (with modifiers), and then try a
match without modifiers (primary character on a key).
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
// First try the exact keycode (with modifiers)
int shortcut = kcm.get(keyCode, modifiers);
Intent intent = shortcut != 0 ? mShortcutIntents.get(shortcut) : null;
if (intent != null) return intent;
// Next try the keycode without modifiers (the primary character on that key)
shortcut = Character.toLowerCase(kcm.get(keyCode, 0));
return shortcut != 0 ? mShortcutIntents.get(shortcut) : null;
| public void | observe()Observes the provider of shortcut+intents
mCursor = mContext.getContentResolver().query(
Settings.Bookmarks.CONTENT_URI, sProjection, null, null, null);
mCursor.registerContentObserver(this);
updateShortcuts();
| public void | onChange(boolean selfChange)
updateShortcuts();
| private void | updateShortcuts()
Cursor c = mCursor;
if (!c.requery()) {
Log.e(TAG, "ShortcutObserver could not re-query shortcuts.");
return;
}
mShortcutIntents.clear();
while (c.moveToNext()) {
int shortcut = c.getInt(COLUMN_SHORTCUT);
if (shortcut == 0) continue;
String intentURI = c.getString(COLUMN_INTENT);
Intent intent = null;
try {
intent = Intent.getIntent(intentURI);
} catch (URISyntaxException e) {
Log.w(TAG, "Intent URI for shortcut invalid.", e);
}
if (intent == null) continue;
mShortcutIntents.put(shortcut, intent);
}
|
|