Fields Summary |
---|
private static final String | TAG |
private static final String | KEY_SHORTCUT_CATEGORY |
private static final int | DIALOG_CLEAR_SHORTCUT |
private static final int | REQUEST_PICK_BOOKMARK |
private static final int | COLUMN_SHORTCUT |
private static final int | COLUMN_TITLE |
private static final int | COLUMN_INTENT |
private static final String[] | sProjection |
private static final String | sShortcutSelection |
private android.os.Handler | mUiHandler |
private static final String | DEFAULT_BOOKMARK_FOLDER |
private android.database.Cursor | mBookmarksCursorCursor for Bookmarks provider. |
private BookmarksObserver | mBookmarksObserverListens for changes to Bookmarks provider. |
private android.util.SparseBooleanArray | mBookmarkedShortcutsUsed to keep track of which shortcuts have bookmarks. |
private android.preference.PreferenceGroup | mShortcutGroupPreference category to hold the shortcut preferences. |
private android.util.SparseArray | mShortcutToPreferenceMapping of a shortcut to its preference. |
private CharSequence | mClearDialogBookmarkTitleThe bookmark title of the shortcut that is being cleared. |
private static final String | CLEAR_DIALOG_BOOKMARK_TITLE |
private char | mClearDialogShortcutThe shortcut that is being cleared. |
private static final String | CLEAR_DIALOG_SHORTCUT |
Methods Summary |
---|
private void | clearShortcut(char shortcut)
getContentResolver().delete(Bookmarks.CONTENT_URI, sShortcutSelection,
new String[] { String.valueOf((int) shortcut) });
|
private ShortcutPreference | createPreference(char shortcut)
ShortcutPreference pref = new ShortcutPreference(QuickLaunchSettings.this, shortcut);
mShortcutGroup.addPreference(pref);
mShortcutToPreference.put(shortcut, pref);
return pref;
|
private ShortcutPreference | getOrCreatePreference(char shortcut)
ShortcutPreference pref = mShortcutToPreference.get(shortcut);
if (pref != null) {
return pref;
} else {
Log.w(TAG, "Unknown shortcut '" + shortcut + "', creating preference anyway");
return createPreference(shortcut);
}
|
private void | initShortcutPreferences()
/** Whether the shortcut has been seen already. The array index is the shortcut. */
SparseBooleanArray shortcutSeen = new SparseBooleanArray();
KeyCharacterMap keyMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
// Go through all the key codes and create a preference for the appropriate keys
for (int keyCode = KeyEvent.getMaxKeyCode() - 1; keyCode >= 0; keyCode--) {
// Get the label for the primary char on the key that produces this key code
char shortcut = (char) Character.toLowerCase(keyMap.getDisplayLabel(keyCode));
if (shortcut == 0 || shortcutSeen.get(shortcut, false)) continue;
// TODO: need a to tell if the current keyboard can produce this key code, for now
// only allow the letter or digits
if (!Character.isLetterOrDigit(shortcut)) continue;
shortcutSeen.put(shortcut, true);
createPreference(shortcut);
}
|
protected void | onActivityResult(int requestCode, int resultCode, android.content.Intent data)
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == REQUEST_PICK_BOOKMARK) {
// Returned from the 'pick bookmark for this shortcut' screen
if (data == null) {
Log.w(TAG, "Result from bookmark picker does not have an intent.");
return;
}
String title = data.getStringExtra(BookmarkPicker.EXTRA_TITLE);
char shortcut = data.getCharExtra(BookmarkPicker.EXTRA_SHORTCUT, (char) 0);
updateShortcut(shortcut, data);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
|
public void | onClick(android.content.DialogInterface dialog, int which)
if (mClearDialogShortcut > 0 && which == AlertDialog.BUTTON1) {
// Clear the shortcut
clearShortcut(mClearDialogShortcut);
}
mClearDialogBookmarkTitle = null;
mClearDialogShortcut = 0;
|
protected void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.quick_launch_settings);
mShortcutGroup = (PreferenceGroup) findPreference(KEY_SHORTCUT_CATEGORY);
mShortcutToPreference = new SparseArray<ShortcutPreference>();
mBookmarksObserver = new BookmarksObserver(mUiHandler);
initShortcutPreferences();
mBookmarksCursor = managedQuery(Bookmarks.CONTENT_URI, sProjection, null, null);
getListView().setOnItemLongClickListener(this);
|
protected android.app.Dialog | onCreateDialog(int id)
switch (id) {
case DIALOG_CLEAR_SHORTCUT: {
// Create the dialog for clearing a shortcut
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.quick_launch_clear_dialog_title))
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.quick_launch_clear_dialog_message,
mClearDialogShortcut, mClearDialogBookmarkTitle))
.setPositiveButton(R.string.quick_launch_clear_ok_button, this)
.setNegativeButton(R.string.quick_launch_clear_cancel_button, this)
.create();
}
}
return super.onCreateDialog(id);
|
public boolean | onItemLongClick(android.widget.AdapterView parent, android.view.View view, int position, long id)
// Open the clear shortcut dialog
Preference pref = (Preference) getPreferenceScreen().getRootAdapter().getItem(position);
if (!(pref instanceof ShortcutPreference)) return false;
showClearDialog((ShortcutPreference) pref);
return true;
|
protected void | onPause()
super.onPause();
getContentResolver().unregisterContentObserver(mBookmarksObserver);
|
public boolean | onPreferenceTreeClick(android.preference.PreferenceScreen preferenceScreen, android.preference.Preference preference)
if (!(preference instanceof ShortcutPreference)) return false;
// Open the screen to pick a bookmark for this shortcut
ShortcutPreference pref = (ShortcutPreference) preference;
Intent intent = new Intent(this, BookmarkPicker.class);
intent.putExtra(BookmarkPicker.EXTRA_SHORTCUT, pref.getShortcut());
startActivityForResult(intent, REQUEST_PICK_BOOKMARK);
return true;
|
protected void | onPrepareDialog(int id, android.app.Dialog dialog)
switch (id) {
case DIALOG_CLEAR_SHORTCUT: {
AlertDialog alertDialog = (AlertDialog) dialog;
alertDialog.setMessage(getString(R.string.quick_launch_clear_dialog_message,
mClearDialogShortcut, mClearDialogBookmarkTitle));
}
}
|
protected void | onRestoreInstanceState(android.os.Bundle state)
super.onRestoreInstanceState(state);
// Restore the clear dialog's info
mClearDialogBookmarkTitle = state.getString(CLEAR_DIALOG_BOOKMARK_TITLE);
mClearDialogShortcut = (char) state.getInt(CLEAR_DIALOG_SHORTCUT, 0);
|
protected void | onResume()
super.onResume();
getContentResolver().registerContentObserver(Bookmarks.CONTENT_URI, true,
mBookmarksObserver);
refreshShortcuts();
|
protected void | onSaveInstanceState(android.os.Bundle outState)
super.onSaveInstanceState(outState);
// Save the clear dialog's info
outState.putCharSequence(CLEAR_DIALOG_BOOKMARK_TITLE, mClearDialogBookmarkTitle);
outState.putInt(CLEAR_DIALOG_SHORTCUT, mClearDialogShortcut);
|
private synchronized void | refreshShortcuts()
Cursor c = mBookmarksCursor;
if (c == null) {
// Haven't finished querying yet
return;
}
if (!c.requery()) {
Log.e(TAG, "Could not requery cursor when refreshing shortcuts.");
return;
}
/**
* We use the previous bookmarked shortcuts array to filter out those
* shortcuts that had bookmarks before this method call, and don't after
* (so we can set the preferences to be without bookmarks).
*/
SparseBooleanArray noLongerBookmarkedShortcuts = mBookmarkedShortcuts;
SparseBooleanArray newBookmarkedShortcuts = new SparseBooleanArray();
while (c.moveToNext()) {
char shortcut = Character.toLowerCase((char) c.getInt(COLUMN_SHORTCUT));
if (shortcut == 0) continue;
ShortcutPreference pref = getOrCreatePreference(shortcut);
pref.setTitle(Bookmarks.getTitle(this, c));
pref.setSummary(getString(R.string.quick_launch_shortcut,
String.valueOf(shortcut)));
pref.setHasBookmark(true);
newBookmarkedShortcuts.put(shortcut, true);
if (noLongerBookmarkedShortcuts != null) {
// After this loop, the shortcuts with value true in this array
// will no longer have bookmarks
noLongerBookmarkedShortcuts.put(shortcut, false);
}
}
if (noLongerBookmarkedShortcuts != null) {
for (int i = noLongerBookmarkedShortcuts.size() - 1; i >= 0; i--) {
if (noLongerBookmarkedShortcuts.valueAt(i)) {
// True, so there is no longer a bookmark for this shortcut
char shortcut = (char) noLongerBookmarkedShortcuts.keyAt(i);
ShortcutPreference pref = mShortcutToPreference.get(shortcut);
if (pref != null) {
pref.setHasBookmark(false);
}
}
}
}
mBookmarkedShortcuts = newBookmarkedShortcuts;
c.deactivate();
|
private void | showClearDialog(ShortcutPreference pref)
if (!pref.hasBookmark()) return;
mClearDialogBookmarkTitle = pref.getTitle();
mClearDialogShortcut = pref.getShortcut();
showDialog(DIALOG_CLEAR_SHORTCUT);
|
private void | updateShortcut(char shortcut, android.content.Intent intent)
// Update the bookmark for a shortcut
// Pass an empty title so it gets resolved each time this bookmark is
// displayed (since the locale could change after we insert into the provider).
Bookmarks.add(getContentResolver(), intent, "", DEFAULT_BOOKMARK_FOLDER, shortcut, 0);
|