diff options
author | Michael Jurka <mikejurka@google.com> | 2011-08-05 15:48:10 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-05 15:48:10 -0700 |
commit | bacd9efce7acbde09cc28b7d449887959165a7a3 (patch) | |
tree | 30019b5e5da2067a896228d2e03c2047e98077e3 /src/com/android/launcher2 | |
parent | b8472bb83cd96456a543137e1e56d589171934c3 (diff) | |
parent | 931dc9779dab5071efc21163647f5f004991bfb3 (diff) | |
download | android_packages_apps_Trebuchet-bacd9efce7acbde09cc28b7d449887959165a7a3.tar.gz android_packages_apps_Trebuchet-bacd9efce7acbde09cc28b7d449887959165a7a3.tar.bz2 android_packages_apps_Trebuchet-bacd9efce7acbde09cc28b7d449887959165a7a3.zip |
Merge "Solving bug where labels were uneven"
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r-- | src/com/android/launcher2/LauncherModel.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/Utilities.java | 30 |
2 files changed, 33 insertions, 8 deletions
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 63e80775f..157348312 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -1511,7 +1511,7 @@ public class LauncherModel extends BroadcastReceiver { // the db if (icon == null) { if (c != null) { - icon = getIconFromCursor(c, iconIndex); + icon = getIconFromCursor(c, iconIndex, context); } } // the fallback icon @@ -1581,7 +1581,7 @@ public class LauncherModel extends BroadcastReceiver { } // the db if (icon == null) { - icon = getIconFromCursor(c, iconIndex); + icon = getIconFromCursor(c, iconIndex, context); } // the fallback icon if (icon == null) { @@ -1590,7 +1590,7 @@ public class LauncherModel extends BroadcastReceiver { } break; case LauncherSettings.Favorites.ICON_TYPE_BITMAP: - icon = getIconFromCursor(c, iconIndex); + icon = getIconFromCursor(c, iconIndex, context); if (icon == null) { icon = getFallbackIcon(); info.customIcon = false; @@ -1609,14 +1609,15 @@ public class LauncherModel extends BroadcastReceiver { return info; } - Bitmap getIconFromCursor(Cursor c, int iconIndex) { + Bitmap getIconFromCursor(Cursor c, int iconIndex, Context context) { if (false) { Log.d(TAG, "getIconFromCursor app=" + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE))); } byte[] data = c.getBlob(iconIndex); try { - return BitmapFactory.decodeByteArray(data, 0, data.length); + return Utilities.createIconBitmap( + BitmapFactory.decodeByteArray(data, 0, data.length), context); } catch (Exception e) { return null; } diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java index c63c82206..b537f7acc 100644 --- a/src/com/android/launcher2/Utilities.java +++ b/src/com/android/launcher2/Utilities.java @@ -76,8 +76,32 @@ final class Utilities { } /** - * Returns a bitmap suitable for the all apps view. The bitmap will be a power - * of two sized ARGB_8888 bitmap that can be used as a gl texture. + * Returns a bitmap suitable for the all apps view. Used to convert pre-ICS + * icon bitmaps that are stored in the database (which were 74x74 pixels at hdpi size) + * to the proper size (48dp) + */ + static Bitmap createIconBitmap(Bitmap icon, Context context) { + int textureWidth = sIconTextureWidth; + int textureHeight = sIconTextureHeight; + int sourceWidth = icon.getWidth(); + int sourceHeight = icon.getHeight(); + if (sourceWidth > textureWidth && sourceHeight > textureHeight) { + // Icon is bigger than it should be; clip it (solves the GB->ICS migration case) + return Bitmap.createBitmap(icon, + (sourceWidth - textureWidth) / 2, + (sourceHeight - textureHeight) / 2, + textureWidth, textureHeight); + } else if (sourceWidth == textureWidth && sourceHeight == textureHeight) { + // Icon is the right size, no need to change it + return icon; + } else { + // Icon is too small, render to a larger bitmap + return createIconBitmap(new BitmapDrawable(icon), context); + } + } + + /** + * Returns a bitmap suitable for the all apps view. */ static Bitmap createIconBitmap(Drawable icon, Context context) { synchronized (sCanvas) { // we share the statics :-( @@ -103,7 +127,7 @@ final class Utilities { int sourceWidth = icon.getIntrinsicWidth(); int sourceHeight = icon.getIntrinsicHeight(); - if (sourceWidth > 0 && sourceWidth > 0) { + if (sourceWidth > 0 && sourceHeight > 0) { // There are intrinsic sizes. if (width < sourceWidth || height < sourceHeight) { // It's too big, scale it down. |