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(android.view.KeyCharacterMap kcm, int keyCode, int metaState)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).
Intent intent = null;
// First try the exact keycode (with modifiers).
int shortcut = kcm.get(keyCode, metaState);
if (shortcut != 0) {
intent = mShortcutIntents.get(shortcut);
}
// Next try the primary character on that key.
if (intent == null) {
shortcut = Character.toLowerCase(kcm.getDisplayLabel(keyCode));
if (shortcut != 0) {
intent = mShortcutIntents.get(shortcut);
}
}
return intent;
| 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);
}
|
|