diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-11-29 13:13:33 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-29 13:13:33 -0800 |
commit | be6ab576ff0e3bf2a8dc3feee6f476061afbda30 (patch) | |
tree | 37535e8706bf89b94c10d0ed7d7b6970cd3a637d /packages/SettingsProvider | |
parent | 50b2042502bc459b40430fe3b3b83d7d61e5daf9 (diff) | |
parent | 6651a638348c15e89e265b0a53c775cac9beafa2 (diff) | |
download | frameworks_base-be6ab576ff0e3bf2a8dc3feee6f476061afbda30.zip frameworks_base-be6ab576ff0e3bf2a8dc3feee6f476061afbda30.tar.gz frameworks_base-be6ab576ff0e3bf2a8dc3feee6f476061afbda30.tar.bz2 |
Merge "Fix application launch shortcuts." into ics-mr1
Diffstat (limited to 'packages/SettingsProvider')
-rw-r--r-- | packages/SettingsProvider/res/xml/bookmarks.xml | 25 | ||||
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java | 83 |
2 files changed, 58 insertions, 50 deletions
diff --git a/packages/SettingsProvider/res/xml/bookmarks.xml b/packages/SettingsProvider/res/xml/bookmarks.xml index 83229f4..454f456 100644 --- a/packages/SettingsProvider/res/xml/bookmarks.xml +++ b/packages/SettingsProvider/res/xml/bookmarks.xml @@ -19,6 +19,7 @@ Bookmarks for vendor apps should be added to a bookmarks resource overlay; not here. Typical shortcuts (not necessarily defined here): + 'a': Calculator 'b': Browser 'c': Contacts 'e': Email @@ -32,27 +33,27 @@ --> <bookmarks> <bookmark - package="com.android.browser" - class="com.android.browser.BrowserActivity" + category="android.intent.category.APP_CALCULATOR" + shortcut="a" /> + <bookmark + category="android.intent.category.APP_BROWSER" shortcut="b" /> <bookmark - package="com.android.contacts" - class="com.android.contacts.activities.ContactsFrontDoor" + category="android.intent.category.APP_CONTACTS" shortcut="c" /> <bookmark - package="com.google.android.email" - class="com.android.email.activity.Welcome" + category="android.intent.category.APP_EMAIL" shortcut="e" /> <bookmark - package="com.google.android.calendar" - class="com.android.calendar.LaunchActivity" + category="android.intent.category.APP_CALENDAR" shortcut="l" /> <bookmark - package="com.android.music" - class="com.android.music.MusicBrowserActivity" + category="android.intent.category.APP_MAPS" + shortcut="m" /> + <bookmark + category="android.intent.category.APP_MUSIC" shortcut="p" /> <bookmark - package="com.android.mms" - class="com.android.mms.ui.ConversationList" + category="android.intent.category.APP_MESSAGING" shortcut="s" /> </bookmarks> diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index aa08e64..080d345 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -63,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // is properly propagated through your change. Not doing so will result in a loss of user // settings. - private static final int DATABASE_VERSION = 70; + private static final int DATABASE_VERSION = 71; private Context mContext; @@ -946,6 +946,12 @@ public class DatabaseHelper extends SQLiteOpenHelper { upgradeVersion = 70; } + if (upgradeVersion == 70) { + // Update all built-in bookmarks. Some of the package names have changed. + loadBookmarks(db); + upgradeVersion = 71; + } + // *** Remember to update DATABASE_VERSION above! if (upgradeVersion != currentVersion) { @@ -1086,16 +1092,11 @@ public class DatabaseHelper extends SQLiteOpenHelper { * Loads the default set of bookmarked shortcuts from an xml file. * * @param db The database to write the values into - * @param startingIndex The zero-based position at which bookmarks in this file should begin */ - private int loadBookmarks(SQLiteDatabase db, int startingIndex) { - Intent intent = new Intent(Intent.ACTION_MAIN, null); - intent.addCategory(Intent.CATEGORY_LAUNCHER); + private void loadBookmarks(SQLiteDatabase db) { ContentValues values = new ContentValues(); PackageManager packageManager = mContext.getPackageManager(); - int i = startingIndex; - try { XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks); XmlUtils.beginDocument(parser, "bookmarks"); @@ -1118,54 +1119,60 @@ public class DatabaseHelper extends SQLiteOpenHelper { String pkg = parser.getAttributeValue(null, "package"); String cls = parser.getAttributeValue(null, "class"); String shortcutStr = parser.getAttributeValue(null, "shortcut"); + String category = parser.getAttributeValue(null, "category"); int shortcutValue = shortcutStr.charAt(0); if (TextUtils.isEmpty(shortcutStr)) { Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls); + continue; } - ActivityInfo info = null; - ComponentName cn = new ComponentName(pkg, cls); - try { - info = packageManager.getActivityInfo(cn, 0); - } catch (PackageManager.NameNotFoundException e) { - String[] packages = packageManager.canonicalToCurrentPackageNames( - new String[] { pkg }); - cn = new ComponentName(packages[0], cls); + final Intent intent; + final String title; + if (pkg != null && cls != null) { + ActivityInfo info = null; + ComponentName cn = new ComponentName(pkg, cls); try { info = packageManager.getActivityInfo(cn, 0); - } catch (PackageManager.NameNotFoundException e1) { - Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e); + } catch (PackageManager.NameNotFoundException e) { + String[] packages = packageManager.canonicalToCurrentPackageNames( + new String[] { pkg }); + cn = new ComponentName(packages[0], cls); + try { + info = packageManager.getActivityInfo(cn, 0); + } catch (PackageManager.NameNotFoundException e1) { + Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e); + continue; + } } - } - - if (info != null) { + + intent = new Intent(Intent.ACTION_MAIN, null); + intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(cn); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - values.put(Settings.Bookmarks.INTENT, intent.toUri(0)); - values.put(Settings.Bookmarks.TITLE, - info.loadLabel(packageManager).toString()); - values.put(Settings.Bookmarks.SHORTCUT, shortcutValue); - db.insert("bookmarks", null, values); - i++; + title = info.loadLabel(packageManager).toString(); + } else if (category != null) { + intent = new Intent(Intent.ACTION_MAIN, null); + intent.addCategory(category); + title = ""; + } else { + Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr + + ": missing package/class or category attributes"); + continue; } + + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + values.put(Settings.Bookmarks.INTENT, intent.toUri(0)); + values.put(Settings.Bookmarks.TITLE, title); + values.put(Settings.Bookmarks.SHORTCUT, shortcutValue); + db.delete("bookmarks", "shortcut = ?", + new String[] { Integer.toString(shortcutValue) }); + db.insert("bookmarks", null, values); } } catch (XmlPullParserException e) { Log.w(TAG, "Got execption parsing bookmarks.", e); } catch (IOException e) { Log.w(TAG, "Got execption parsing bookmarks.", e); } - - return i; - } - - /** - * Loads the default set of bookmark packages. - * - * @param db The database to write the values into - */ - private void loadBookmarks(SQLiteDatabase db) { - loadBookmarks(db, 0); } /** |