Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-Launcher: Commit

packages/apps/Launcher


Commit MetaInfo

Revision299075effe561b7ae7bfcfce28c225cd3d482960 (tree)
Zeit2009-12-03 13:18:29
AutorRomain Guy <romainguy@andr...>
CommiterRomain Guy

Log Message

Upgrade contacts shortcut to the quick contact feature.

Change-Id: Ibd5171253686f717273fa109bd2976ccbaa774d2

Ändern Zusammenfassung

Diff

--- a/src/com/android/launcher/LauncherProvider.java
+++ b/src/com/android/launcher/LauncherProvider.java
@@ -16,7 +16,6 @@
1616
1717 package com.android.launcher;
1818
19-import static android.util.Log.d;
2019 import static android.util.Log.w;
2120
2221 import android.appwidget.AppWidgetHost;
@@ -60,7 +59,7 @@ public class LauncherProvider extends ContentProvider {
6059
6160 private static final String DATABASE_NAME = "launcher.db";
6261
63- private static final int DATABASE_VERSION = 4;
62+ private static final int DATABASE_VERSION = 5;
6463
6564 static final String AUTHORITY = "com.android.launcher.settings";
6665
@@ -68,7 +67,6 @@ public class LauncherProvider extends ContentProvider {
6867 static final String EXTRA_BIND_TARGETS = "com.android.launcher.settings.bindtargets";
6968
7069 static final String TABLE_FAVORITES = "favorites";
71- static final String TABLE_GESTURES = "gestures";
7270 static final String PARAMETER_NOTIFY = "notify";
7371
7472 /**
@@ -372,36 +370,90 @@ public class LauncherProvider extends ContentProvider {
372370 }
373371
374372 if (version < 4) {
375- db.beginTransaction();
376- try {
377- db.execSQL("CREATE TABLE gestures (" +
378- "_id INTEGER PRIMARY KEY," +
379- "title TEXT," +
380- "intent TEXT," +
381- "itemType INTEGER," +
382- "iconType INTEGER," +
383- "iconPackage TEXT," +
384- "iconResource TEXT," +
385- "icon BLOB" +
386- ");");
387- db.setTransactionSuccessful();
388- version = 4;
389- } catch (SQLException ex) {
390- // Old version remains, which means we wipe old data
391- Log.e(LOG_TAG, ex.getMessage(), ex);
392- } finally {
393- db.endTransaction();
373+ version = 4;
374+ }
375+
376+ if (version < 5) {
377+ if (updateContactsShortcuts(db)) {
378+ version = 5;
394379 }
395380 }
396381
397382 if (version != DATABASE_VERSION) {
398383 Log.w(LOG_TAG, "Destroying all old data.");
399384 db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
400- db.execSQL("DROP TABLE IF EXISTS " + TABLE_GESTURES);
401385 onCreate(db);
402386 }
403387 }
404388
389+ private boolean updateContactsShortcuts(SQLiteDatabase db) {
390+ Cursor c = null;
391+ final String selectWhere = buildOrWhereString(LauncherSettings.Favorites.ITEM_TYPE,
392+ new int[] { LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT });
393+
394+ db.beginTransaction();
395+ try {
396+ // Select and iterate through each matching widget
397+ c = db.query(TABLE_FAVORITES, new String[] { LauncherSettings.Favorites._ID,
398+ LauncherSettings.Favorites.INTENT }, selectWhere, null, null, null, null);
399+
400+ if (LOGD) Log.d(LOG_TAG, "found upgrade cursor count=" + c.getCount());
401+
402+ final ContentValues values = new ContentValues();
403+ final int idIndex = c.getColumnIndex(LauncherSettings.Favorites._ID);
404+ final int intentIndex = c.getColumnIndex(LauncherSettings.Favorites.INTENT);
405+
406+ while (c != null && c.moveToNext()) {
407+ long favoriteId = c.getLong(idIndex);
408+ final String intentUri = c.getString(intentIndex);
409+ if (intentUri != null) {
410+ try {
411+ Intent intent = Intent.parseUri(intentUri, 0);
412+ android.util.Log.d("Home", intent.toString());
413+ final Uri uri = intent.getData();
414+ final String data = uri.toString();
415+ if (Intent.ACTION_VIEW.equals(intent.getAction()) &&
416+ (data.startsWith("content://contacts/people/") ||
417+ data.startsWith("content://com.android.contacts/contacts/lookup/"))) {
418+
419+ intent = new Intent("com.android.contacts.action.QUICK_CONTACT");
420+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
421+ Intent.FLAG_ACTIVITY_CLEAR_TOP |
422+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
423+
424+ intent.setData(uri);
425+ intent.putExtra("mode", 3);
426+ intent.putExtra("exclude_mimes", (String[]) null);
427+
428+ values.clear();
429+ values.put(LauncherSettings.Favorites.INTENT, intent.toUri(0));
430+
431+ String updateWhere = LauncherSettings.Favorites._ID + "=" + favoriteId;
432+ db.update(TABLE_FAVORITES, values, updateWhere, null);
433+ }
434+ } catch (RuntimeException ex) {
435+ Log.e(LOG_TAG, "Problem upgrading shortcut", ex);
436+ } catch (URISyntaxException e) {
437+ Log.e(LOG_TAG, "Problem upgrading shortcut", e);
438+ }
439+ }
440+ }
441+
442+ db.setTransactionSuccessful();
443+ } catch (SQLException ex) {
444+ Log.w(LOG_TAG, "Problem while upgrading contacts", ex);
445+ return false;
446+ } finally {
447+ db.endTransaction();
448+ if (c != null) {
449+ c.close();
450+ }
451+ }
452+
453+ return true;
454+ }
455+
456+
405457 /**
406458 * Upgrade existing clock and photo frame widgets into their new widget
407459 * equivalents. This method allocates appWidgetIds, and then hands off to
@@ -591,7 +643,7 @@ public class LauncherProvider extends ContentProvider {
591643 final int iconResId = a.getResourceId(R.styleable.Favorite_icon, 0);
592644 final int titleResId = a.getResourceId(R.styleable.Favorite_title, 0);
593645
594- Intent intent = null;
646+ Intent intent;
595647 String uri = null;
596648 try {
597649 uri = a.getString(R.styleable.Favorite_uri);
Show on old repository browser