packages/apps/Launcher
Revision | 299075effe561b7ae7bfcfce28c225cd3d482960 (tree) |
---|---|
Zeit | 2009-12-03 13:18:29 |
Autor | Romain Guy <romainguy@andr...> |
Commiter | Romain Guy |
Upgrade contacts shortcut to the quick contact feature.
Change-Id: Ibd5171253686f717273fa109bd2976ccbaa774d2
@@ -16,7 +16,6 @@ | ||
16 | 16 | |
17 | 17 | package com.android.launcher; |
18 | 18 | |
19 | -import static android.util.Log.d; | |
20 | 19 | import static android.util.Log.w; |
21 | 20 | |
22 | 21 | import android.appwidget.AppWidgetHost; |
@@ -60,7 +59,7 @@ public class LauncherProvider extends ContentProvider { | ||
60 | 59 | |
61 | 60 | private static final String DATABASE_NAME = "launcher.db"; |
62 | 61 | |
63 | - private static final int DATABASE_VERSION = 4; | |
62 | + private static final int DATABASE_VERSION = 5; | |
64 | 63 | |
65 | 64 | static final String AUTHORITY = "com.android.launcher.settings"; |
66 | 65 |
@@ -68,7 +67,6 @@ public class LauncherProvider extends ContentProvider { | ||
68 | 67 | static final String EXTRA_BIND_TARGETS = "com.android.launcher.settings.bindtargets"; |
69 | 68 | |
70 | 69 | static final String TABLE_FAVORITES = "favorites"; |
71 | - static final String TABLE_GESTURES = "gestures"; | |
72 | 70 | static final String PARAMETER_NOTIFY = "notify"; |
73 | 71 | |
74 | 72 | /** |
@@ -372,36 +370,90 @@ public class LauncherProvider extends ContentProvider { | ||
372 | 370 | } |
373 | 371 | |
374 | 372 | 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; | |
394 | 379 | } |
395 | 380 | } |
396 | 381 | |
397 | 382 | if (version != DATABASE_VERSION) { |
398 | 383 | Log.w(LOG_TAG, "Destroying all old data."); |
399 | 384 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES); |
400 | - db.execSQL("DROP TABLE IF EXISTS " + TABLE_GESTURES); | |
401 | 385 | onCreate(db); |
402 | 386 | } |
403 | 387 | } |
404 | 388 | |
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 | + | |
405 | 457 | /** |
406 | 458 | * Upgrade existing clock and photo frame widgets into their new widget |
407 | 459 | * equivalents. This method allocates appWidgetIds, and then hands off to |
@@ -591,7 +643,7 @@ public class LauncherProvider extends ContentProvider { | ||
591 | 643 | final int iconResId = a.getResourceId(R.styleable.Favorite_icon, 0); |
592 | 644 | final int titleResId = a.getResourceId(R.styleable.Favorite_title, 0); |
593 | 645 | |
594 | - Intent intent = null; | |
646 | + Intent intent; | |
595 | 647 | String uri = null; |
596 | 648 | try { |
597 | 649 | uri = a.getString(R.styleable.Favorite_uri); |