summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/LauncherProvider.java
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2010-02-08 13:44:00 -0800
committerJoe Onorato <joeo@android.com>2010-02-12 12:18:40 -0500
commit0589f0f66ce498512c6ee47482c649d88294c9d0 (patch)
tree42d42799a5578bde35a79b18ab8b28d301c663fe /src/com/android/launcher2/LauncherProvider.java
parent3e244cf9d2da4fb04ef095f8b752a2a2c6e2f287 (diff)
downloadandroid_packages_apps_Trebuchet-0589f0f66ce498512c6ee47482c649d88294c9d0.tar.gz
android_packages_apps_Trebuchet-0589f0f66ce498512c6ee47482c649d88294c9d0.tar.bz2
android_packages_apps_Trebuchet-0589f0f66ce498512c6ee47482c649d88294c9d0.zip
Split ApplicationInfo into ApplicationInfo which is used for AllAppsView and ShortcutInfo which is
used for the workspace. Consolidate the three icon resampling functions into one. Ensure that the icons stored in LauncherProvider are the right size, so we don't have to resample them each time we load them.
Diffstat (limited to 'src/com/android/launcher2/LauncherProvider.java')
-rw-r--r--src/com/android/launcher2/LauncherProvider.java67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java
index f03e50c99..4a0802977 100644
--- a/src/com/android/launcher2/LauncherProvider.java
+++ b/src/com/android/launcher2/LauncherProvider.java
@@ -34,9 +34,12 @@ import android.content.pm.PackageManager;
import android.content.pm.ActivityInfo;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteStatement;
import android.database.sqlite.SQLiteQueryBuilder;
import android.database.Cursor;
import android.database.SQLException;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.util.Log;
import android.util.Xml;
import android.util.AttributeSet;
@@ -61,7 +64,7 @@ public class LauncherProvider extends ContentProvider {
private static final String DATABASE_NAME = "launcher.db";
- private static final int DATABASE_VERSION = 7;
+ private static final int DATABASE_VERSION = 8;
static final String AUTHORITY = "com.android.launcher2.settings";
@@ -392,6 +395,14 @@ public class LauncherProvider extends ContentProvider {
version = 7;
}
+ if (version < 8) {
+ // Version 8 (froyo) has the icons all normalized. This should
+ // already be the case in practice, but we now rely on it and don't
+ // resample the images each time.
+ normalizeIcons(db);
+ version = 8;
+ }
+
if (version != DATABASE_VERSION) {
Log.w(TAG, "Destroying all old data.");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
@@ -466,6 +477,60 @@ public class LauncherProvider extends ContentProvider {
return true;
}
+ private void normalizeIcons(SQLiteDatabase db) {
+ Log.d(TAG, "normalizing icons");
+
+ Cursor c = null;
+ try {
+ boolean logged = false;
+ final ContentValues values = new ContentValues();
+ final ContentResolver cr = mContext.getContentResolver();
+ final SQLiteStatement update = db.compileStatement("UPDATE favorites "
+ + "WHERE _id=? SET icon=?");
+
+ c = db.rawQuery("SELECT _id, icon FROM favorites WHERE iconType=" +
+ Favorites.ICON_TYPE_BITMAP, null);
+
+ final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
+ final int iconIndex = c.getColumnIndexOrThrow(Favorites.ICON);
+
+ while (c.moveToNext()) {
+ long id = c.getLong(idIndex);
+ byte[] data = c.getBlob(iconIndex);
+ try {
+ Bitmap bitmap = Utilities.resampleIconBitmap(
+ BitmapFactory.decodeByteArray(data, 0, data.length),
+ mContext);
+ if (bitmap != null) {
+ update.bindLong(1, id);
+ data = ItemInfo.flattenBitmap(bitmap);
+ if (data != null) {
+ update.bindBlob(2, data);
+ update.execute();
+ }
+ bitmap.recycle();
+ bitmap = null;
+ }
+ } catch (Exception e) {
+ if (!logged) {
+ Log.e(TAG, "Failed normalizing icon " + id, e);
+ } else {
+ Log.e(TAG, "Also failed normalizing icon " + id);
+ }
+ logged = true;
+ }
+ }
+ } catch (SQLException ex) {
+ Log.w(TAG, "Problem while allocating appWidgetIds for existing widgets", ex);
+ } finally {
+ db.endTransaction();
+ if (c != null) {
+ c.close();
+ }
+ }
+
+ }
+
/**
* Upgrade existing clock and photo frame widgets into their new widget
* equivalents.