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
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index bb71d77..47cca37 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -29,7 +29,6 @@
 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 @@
             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 60eb15f..550535e 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -3485,8 +3485,8 @@
         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 4b27837..44ccb6c 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -1050,7 +1050,7 @@
                     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 80d4b22..84eb8bf 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -54,8 +54,6 @@
 
     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 @@
      * 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 @@
     }
 
     /**
-     * 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
-            return icon;
-        } else {
-            // Icon is too small, render to a larger bitmap
-            final Resources resources = context.getResources();
-            return createIconBitmap(new BitmapDrawable(resources, icon), context);
+        synchronized (sCanvas) { // we share the statics :-(
+            if (sIconWidth == -1) {
+                initStatics(context);
+            }
         }
+        if (sIconWidth == icon.getWidth() && sIconHeight == icon.getHeight()) {
+            return icon;
+        }
+        return createIconBitmap(new BitmapDrawable(context.getResources(), icon), context);
     }
 
     /**
@@ -172,8 +159,8 @@
             }
 
             // 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 @@
     }
 
     /**
-     * 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 @@
     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) {