Using hdpi icons in Launcher

Known issue: Default activity icon is still showing up as small
diff --git a/res/values-xlarge/dimens.xml b/res/values-xlarge/dimens.xml
index 742b59a..667f0e3 100644
--- a/res/values-xlarge/dimens.xml
+++ b/res/values-xlarge/dimens.xml
@@ -25,8 +25,8 @@
     <!-- The corner radius to draw the external drop icon rounded rect -->
     <dimen name="external_drop_icon_rect_radius">10dp</dimen>
     
-    <!-- Temporary scaled icon size -->
-    <dimen name="temp_scaled_icon_size">72dp</dimen>
+    <!-- Size of icons in workspace -->
+    <dimen name="app_icon_size">72dp</dimen>
 
     <!-- extra horizontal spacing between mini screen thumbnails ie. in all
          apps and in customization mode -->
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index c83986b..d6cd3ee 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -32,6 +32,9 @@
          button cluster in landscape) -->
     <dimen name="half_status_bar_height">12dip</dimen>
 
+    <!-- Size of icons in workspace -->
+    <dimen name="app_icon_size">50dp</dimen>
+
     <!-- height & width of the drop rectangle for the trash icon -->
     <dimen name="delete_zone_size">70dip</dimen>
     
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index 156bc20..28de388 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -639,7 +639,8 @@
 
             PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
                     R.layout.customize_paged_view_item, layout, false);
-            icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache, true);
+            icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache,
+                    ((LauncherApplication)mLauncher.getApplication()).getIconCache());
             switch (mCustomizationType) {
             case WallpaperCustomization:
                 icon.setOnClickListener(this);
diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java
index e692d20..dae84aa 100644
--- a/src/com/android/launcher2/FolderIcon.java
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -48,14 +48,14 @@
     }
 
     static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
-            UserFolderInfo folderInfo) {
+            UserFolderInfo folderInfo, IconCache iconCache) {
 
         FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
 
         final Resources resources = launcher.getResources();
-        Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
+        Drawable d = iconCache.getFullResIcon(resources, R.drawable.ic_launcher_folder);
         icon.mCloseIcon = d;
-        icon.mOpenIcon = resources.getDrawable(R.drawable.ic_launcher_folder_open);
+        icon.mOpenIcon = iconCache.getFullResIcon(resources, R.drawable.ic_launcher_folder_open);
         icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
         icon.setText(folderInfo.title);
         icon.setTag(folderInfo);
diff --git a/src/com/android/launcher2/IconCache.java b/src/com/android/launcher2/IconCache.java
index 81a786c..ae8c98a 100644
--- a/src/com/android/launcher2/IconCache.java
+++ b/src/com/android/launcher2/IconCache.java
@@ -16,13 +16,17 @@
 
 package com.android.launcher2;
 
+import com.android.launcher.R;
+
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
+import android.util.DisplayMetrics;
 
 import java.util.HashMap;
 
@@ -46,16 +50,49 @@
     private final Utilities.BubbleText mBubble;
     private final HashMap<ComponentName, CacheEntry> mCache =
             new HashMap<ComponentName, CacheEntry>(INITIAL_ICON_CACHE_CAPACITY);
+    private int mIconDpi;
 
     public IconCache(LauncherApplication context) {
         mContext = context;
         mPackageManager = context.getPackageManager();
         mBubble = new Utilities.BubbleText(context);
+        if (LauncherApplication.isScreenXLarge()) {
+            mIconDpi = DisplayMetrics.DENSITY_HIGH;
+        } else {
+            mIconDpi = context.getResources().getDisplayMetrics().densityDpi;
+        }
+        // need to set mIconDpi before getting default icon
         mDefaultIcon = makeDefaultIcon();
     }
 
+    public Drawable getFullResDefaultActivityIcon() {
+        return getFullResIcon(Resources.getSystem(),
+                com.android.internal.R.drawable.sym_def_app_icon);
+    }
+
+    public Drawable getFullResIcon(Resources resources, int iconId) {
+        return resources.getDrawableForDensity(iconId, mIconDpi);
+    }
+
+    public Drawable getFullResIcon(ResolveInfo info, PackageManager packageManager) {
+        Resources resources;
+        try {
+            resources = packageManager.getResourcesForApplication(
+                    info.activityInfo.applicationInfo);
+        } catch (PackageManager.NameNotFoundException e) {
+            resources = null;
+        }
+        if (resources != null) {
+            int iconId = info.activityInfo.getIconResource();
+            if (iconId != 0) {
+                return getFullResIcon(resources, iconId);
+            }
+        }
+        return getFullResDefaultActivityIcon();
+    }
+
     private Bitmap makeDefaultIcon() {
-        Drawable d = mPackageManager.getDefaultActivityIcon();
+        Drawable d = getFullResDefaultActivityIcon();
         Bitmap b = Bitmap.createBitmap(Math.max(d.getIntrinsicWidth(), 1),
                 Math.max(d.getIntrinsicHeight(), 1),
                 Bitmap.Config.ARGB_8888);
@@ -140,7 +177,7 @@
                 entry.title = info.activityInfo.name;
             }
             entry.icon = Utilities.createIconBitmap(
-                    info.activityInfo.loadIcon(mPackageManager), mContext);
+                    getFullResIcon(info, mPackageManager), mContext);
         }
         return entry;
     }
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 6b1290d..0ac42dd 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -993,12 +993,6 @@
 
         Bitmap b = info.getIcon(mIconCache);
 
-        if (LauncherApplication.isScreenXLarge()) {
-            // Temporarily, we are scaling up all shortcuts on the workspace
-            int scaledSize = getResources().getDimensionPixelSize(R.dimen.temp_scaled_icon_size);
-            b = Bitmap.createScaledBitmap(b, scaledSize, scaledSize, true);
-        }
-
         favorite.setCompoundDrawablesWithIntrinsicBounds(null,
                 new FastBitmapDrawable(b),
                 null, null);
@@ -1552,7 +1546,8 @@
 
         // Create the view
         FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
-                (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
+                (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()),
+                folderInfo, mIconCache);
         mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
     }
 
@@ -2987,7 +2982,7 @@
                 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
                     final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                             (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
-                            (UserFolderInfo) item);
+                            (UserFolderInfo) item, mIconCache);
                     workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
                             false);
                     break;
diff --git a/src/com/android/launcher2/LauncherApplication.java b/src/com/android/launcher2/LauncherApplication.java
index dab2b58..ed007dd 100644
--- a/src/com/android/launcher2/LauncherApplication.java
+++ b/src/com/android/launcher2/LauncherApplication.java
@@ -38,11 +38,13 @@
 
         super.onCreate();
 
-        mIconCache = new IconCache(this);
-        mModel = new LauncherModel(this, mIconCache);
+        // set sIsScreenXLarge and sScreenDensity *before* creating icon cache
         sIsScreenXLarge = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
         sScreenDensity = getResources().getDisplayMetrics().density;
 
+        mIconCache = new IconCache(this);
+        mModel = new LauncherModel(this, mIconCache);
+
         // Register intent receivers
         IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
         filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 67aa311..423a9d1 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -16,14 +16,7 @@
 
 package com.android.launcher2;
 
-import java.lang.ref.WeakReference;
-import java.net.URISyntaxException;
-import java.text.Collator;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
+import com.android.launcher.R;
 
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
@@ -52,7 +45,14 @@
 import android.os.SystemClock;
 import android.util.Log;
 
-import com.android.launcher.R;
+import java.lang.ref.WeakReference;
+import java.net.URISyntaxException;
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
 
 /**
  * Maintains in-memory state of the Launcher. It is expected that there should be only one
@@ -119,7 +119,7 @@
         mIconCache = iconCache;
 
         mDefaultIcon = Utilities.createIconBitmap(
-                app.getPackageManager().getDefaultActivityIcon(), app);
+                mIconCache.getFullResDefaultActivityIcon(), app);
 
         mAllAppsLoadDelay = app.getResources().getInteger(R.integer.config_allAppsBatchLoadDelay);
 
@@ -1469,7 +1469,8 @@
                 Resources resources = packageManager.getResourcesForApplication(packageName);
                 if (resources != null) {
                     final int id = resources.getIdentifier(resourceName, null, null);
-                    icon = Utilities.createIconBitmap(resources.getDrawable(id), context);
+                    icon = Utilities.createIconBitmap(
+                            mIconCache.getFullResIcon(resources, id), context);
                 }
             } catch (Exception e) {
                 // drop this.  we have other places to look for icons
@@ -1587,7 +1588,8 @@
                     Resources resources = packageManager.getResourcesForApplication(
                             iconResource.packageName);
                     final int id = resources.getIdentifier(iconResource.resourceName, null, null);
-                    icon = Utilities.createIconBitmap(resources.getDrawable(id), context);
+                    icon = Utilities.createIconBitmap(
+                            mIconCache.getFullResIcon(resources, id), context);
                 } catch (Exception e) {
                     Log.w(TAG, "Could not load shortcut icon: " + extra);
                 }
@@ -1614,7 +1616,7 @@
         return info;
     }
 
-    private static void loadLiveFolderIcon(Context context, Cursor c, int iconTypeIndex,
+    private void loadLiveFolderIcon(Context context, Cursor c, int iconTypeIndex,
             int iconPackageIndex, int iconResourceIndex, LiveFolderInfo liveFolderInfo) {
 
         int iconType = c.getInt(iconTypeIndex);
@@ -1624,13 +1626,14 @@
             String resourceName = c.getString(iconResourceIndex);
             PackageManager packageManager = context.getPackageManager();
             try {
-                Resources resources = packageManager.getResourcesForApplication(packageName);
-                final int id = resources.getIdentifier(resourceName, null, null);
-                liveFolderInfo.icon = Utilities.createIconBitmap(resources.getDrawable(id),
-                        context);
-            } catch (Exception e) {
+                Resources appResources = packageManager.getResourcesForApplication(packageName);
+                final int id = appResources.getIdentifier(resourceName, null, null);
                 liveFolderInfo.icon = Utilities.createIconBitmap(
-                        context.getResources().getDrawable(R.drawable.ic_launcher_folder),
+                        mIconCache.getFullResIcon(appResources, id), context);
+            } catch (Exception e) {
+                Resources resources = context.getResources();
+                liveFolderInfo.icon = Utilities.createIconBitmap(
+                        mIconCache.getFullResIcon(resources, R.drawable.ic_launcher_folder),
                         context);
             }
             liveFolderInfo.iconResource = new Intent.ShortcutIconResource();
@@ -1638,8 +1641,9 @@
             liveFolderInfo.iconResource.resourceName = resourceName;
             break;
         default:
+            Resources resources = context.getResources();
             liveFolderInfo.icon = Utilities.createIconBitmap(
-                    context.getResources().getDrawable(R.drawable.ic_launcher_folder),
+                    mIconCache.getFullResIcon(resources, R.drawable.ic_launcher_folder),
                     context);
         }
     }
diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java
index 6c6c4dc..89cf331 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -48,20 +48,17 @@
     private static HolographicOutlineHelper sHolographicOutlineHelper;
     private Bitmap mCheckedOutline;
     private Bitmap mHolographicOutline;
-    private Canvas mHolographicOutlineCanvas;
-    private Rect mDrawableClipRect;
     private Bitmap mIcon;
 
     private Object mIconCacheKey;
     private PagedViewIconCache mIconCache;
-    private int mScaledIconSize;
 
     private int mAlpha;
     private int mHolographicAlpha;
 
     private boolean mIsChecked;
 
-    // Highlight colours
+    // Highlight colors
     private int mHoloBlurColor;
     private int mHoloOutlineColor;
     private int mCheckedBlurColor;
@@ -113,15 +110,12 @@
         mHoloOutlineColor = a.getColor(R.styleable.PagedViewIcon_outlineColor, 0);
         mCheckedBlurColor = a.getColor(R.styleable.PagedViewIcon_checkedBlurColor, 0);
         mCheckedOutlineColor = a.getColor(R.styleable.PagedViewIcon_checkedOutlineColor, 0);
-        mScaledIconSize =
-            context.getResources().getDimensionPixelSize(R.dimen.temp_scaled_icon_size);
 
         a.recycle();
 
         if (sHolographicOutlineHelper == null) {
             sHolographicOutlineHelper = new HolographicOutlineHelper();
         }
-        mDrawableClipRect = new Rect();
 
         setFocusable(true);
         setBackgroundDrawable(null);
@@ -142,12 +136,7 @@
         mIconCacheKey = info;
         mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
 
-        if (scaleUp) {
-            mIcon = Bitmap.createScaledBitmap(info.iconBitmap, mScaledIconSize,
-                    mScaledIconSize, true);
-        } else {
-            mIcon = info.iconBitmap;
-        }
+        mIcon = info.iconBitmap;
         setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
         setText(info.title);
         setTag(info);
@@ -156,16 +145,13 @@
     }
 
     public void applyFromResolveInfo(ResolveInfo info, PackageManager packageManager,
-            PagedViewIconCache cache, boolean scaleUp) {
+            PagedViewIconCache cache, IconCache modelIconCache) {
         mIconCache = cache;
         mIconCacheKey = info;
         mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
 
-        mIcon = Utilities.createIconBitmap(info.loadIcon(packageManager), mContext);
-        if (scaleUp) {
-            mIcon = Bitmap.createScaledBitmap(mIcon, mScaledIconSize,
-                    mScaledIconSize, true);
-        }
+        mIcon = Utilities.createIconBitmap(
+                modelIconCache.getFullResIcon(info, packageManager), mContext);
         setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
         setText(info.loadLabel(packageManager));
         setTag(info);
diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java
index c67ff99..03a2a52 100644
--- a/src/com/android/launcher2/Utilities.java
+++ b/src/com/android/launcher2/Utilities.java
@@ -237,7 +237,7 @@
         final DisplayMetrics metrics = resources.getDisplayMetrics();
         final float density = metrics.density;
 
-        sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
+        sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size);
         sIconTextureWidth = sIconTextureHeight = sIconWidth + 2;
 
         sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 263c3a6..08e0460 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1767,7 +1767,7 @@
             break;
         case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
             view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher,
-                    cellLayout, ((UserFolderInfo) info));
+                    cellLayout, (UserFolderInfo) info, mIconCache);
             break;
         default:
             throw new IllegalStateException("Unknown item type: " + info.itemType);