diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2014-10-07 12:01:58 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2014-10-07 12:04:39 -0700 |
commit | 2fce90c38a79d318e96a28107dea287e42509861 (patch) | |
tree | 9fcc3f0b65a4de7b43e820f3549019b9ae20bb25 /src/com/android/launcher3 | |
parent | 33de945451e1380eff2f4c6cd3aa5bb32c0ad368 (diff) | |
download | android_packages_apps_Trebuchet-2fce90c38a79d318e96a28107dea287e42509861.tar.gz android_packages_apps_Trebuchet-2fce90c38a79d318e96a28107dea287e42509861.tar.bz2 android_packages_apps_Trebuchet-2fce90c38a79d318e96a28107dea287e42509861.zip |
Cleaning up icon resizing code
> For resizing icons, scaling them down instead of cropping them
> Removing duplicate methods and variables
Bug: 17663119
Change-Id: I0f270860c0edaaa939495e63e05da841a603f6e9
Diffstat (limited to 'src/com/android/launcher3')
-rw-r--r-- | src/com/android/launcher3/IconCache.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 61 |
4 files changed, 15 insertions, 56 deletions
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index bb71d776c..47cca37f1 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -29,7 +29,6 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.Log; @@ -390,8 +389,7 @@ public class IconCache { entry.title = title; } if (icon != null) { - entry.icon = Utilities.createIconBitmap( - new BitmapDrawable(mContext.getResources(), icon), mContext); + entry.icon = Utilities.createIconBitmap(icon, mContext); } } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 60eb15f9c..550535edd 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -3485,8 +3485,8 @@ public class LauncherModel extends BroadcastReceiver boolean customIcon = false; ShortcutIconResource iconResource = null; - if (bitmap != null && bitmap instanceof Bitmap) { - icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap)bitmap), context); + if (bitmap instanceof Bitmap) { + icon = Utilities.createIconBitmap((Bitmap) bitmap, context); customIcon = true; } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 4b27837c4..44ccb6cb3 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -1050,7 +1050,7 @@ public class LauncherProvider extends ContentProvider { long id = c.getLong(idIndex); byte[] data = c.getBlob(iconIndex); try { - Bitmap bitmap = Utilities.resampleIconBitmap( + Bitmap bitmap = Utilities.createIconBitmap( BitmapFactory.decodeByteArray(data, 0, data.length), mContext); if (bitmap != null) { diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 80d4b22ce..84eb8bfa2 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -54,8 +54,6 @@ public final class Utilities { private static int sIconWidth = -1; private static int sIconHeight = -1; - public static int sIconTextureWidth = -1; - public static int sIconTextureHeight = -1; private static final Rect sOldBounds = new Rect(); private static final Canvas sCanvas = new Canvas(); @@ -89,7 +87,7 @@ public final class Utilities { * Resizes an icon drawable to the correct icon size. */ static void resizeIconDrawable(Drawable icon) { - icon.setBounds(0, 0, sIconTextureWidth, sIconTextureHeight); + icon.setBounds(0, 0, sIconWidth, sIconHeight); } private static boolean isPropertyEnabled(String propertyName) { @@ -110,29 +108,18 @@ public final class Utilities { } /** - * 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) + * Returns a bitmap which is of the appropriate size to be displayed as an icon */ 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 + synchronized (sCanvas) { // we share the statics :-( + if (sIconWidth == -1) { + initStatics(context); + } + } + if (sIconWidth == icon.getWidth() && sIconHeight == icon.getHeight()) { return icon; - } else { - // Icon is too small, render to a larger bitmap - final Resources resources = context.getResources(); - return createIconBitmap(new BitmapDrawable(resources, icon), context); } + return createIconBitmap(new BitmapDrawable(context.getResources(), icon), context); } /** @@ -172,8 +159,8 @@ public final class Utilities { } // no intrinsic size --> use default size - int textureWidth = sIconTextureWidth; - int textureHeight = sIconTextureHeight; + int textureWidth = sIconWidth; + int textureHeight = sIconHeight; final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888); @@ -205,30 +192,6 @@ public final class Utilities { } /** - * Returns a Bitmap representing the thumbnail of the specified Bitmap. - * - * @param bitmap The bitmap to get a thumbnail of. - * @param context The application's context. - * - * @return A thumbnail for the specified bitmap or the bitmap itself if the - * thumbnail could not be created. - */ - static Bitmap resampleIconBitmap(Bitmap bitmap, Context context) { - synchronized (sCanvas) { // we share the statics :-( - if (sIconWidth == -1) { - initStatics(context); - } - - if (bitmap.getWidth() == sIconWidth && bitmap.getHeight() == sIconHeight) { - return bitmap; - } else { - final Resources resources = context.getResources(); - return createIconBitmap(new BitmapDrawable(resources, bitmap), context); - } - } - } - - /** * Given a coordinate relative to the descendant, find the coordinate in a parent view's * coordinates. * @@ -330,12 +293,10 @@ public final class Utilities { private static void initStatics(Context context) { final Resources resources = context.getResources(); sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size); - sIconTextureWidth = sIconTextureHeight = sIconWidth; } public static void setIconSize(int widthPx) { sIconWidth = sIconHeight = widthPx; - sIconTextureWidth = sIconTextureHeight = widthPx; } public static void scaleRect(Rect r, float scale) { |