summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2010-11-01 11:52:08 -0700
committerMichael Jurka <mikejurka@google.com>2010-11-01 23:06:54 -0700
commitc9a961952d1a057029874f8426b90181f6876034 (patch)
tree6fdc472bd30aef76a6d650da0f60a5640dfb390d /src
parent7da1025bd7f15b04cf55c79b73e94e5e1bc959d9 (diff)
downloadandroid_packages_apps_Trebuchet-c9a961952d1a057029874f8426b90181f6876034.tar.gz
android_packages_apps_Trebuchet-c9a961952d1a057029874f8426b90181f6876034.tar.bz2
android_packages_apps_Trebuchet-c9a961952d1a057029874f8426b90181f6876034.zip
Using hdpi icons in Launcher
Known issue: Default activity icon is still showing up as small
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/CustomizePagedView.java3
-rw-r--r--src/com/android/launcher2/FolderIcon.java6
-rw-r--r--src/com/android/launcher2/IconCache.java41
-rw-r--r--src/com/android/launcher2/Launcher.java11
-rw-r--r--src/com/android/launcher2/LauncherApplication.java6
-rw-r--r--src/com/android/launcher2/LauncherModel.java42
-rw-r--r--src/com/android/launcher2/PagedViewIcon.java24
-rw-r--r--src/com/android/launcher2/Utilities.java2
-rw-r--r--src/com/android/launcher2/Workspace.java2
9 files changed, 81 insertions, 56 deletions
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index 156bc20bb..28de3883d 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -639,7 +639,8 @@ public class CustomizePagedView extends PagedView
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 e692d2058..dae84aac9 100644
--- a/src/com/android/launcher2/FolderIcon.java
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -48,14 +48,14 @@ public class FolderIcon extends DimmableBubbleTextView implements DropTarget {
}
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 81a786ca7..ae8c98a60 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 @@ public class IconCache {
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 @@ public class IconCache {
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 6b1290de8..0ac42ddfe 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -993,12 +993,6 @@ public final class Launcher extends Activity
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 @@ public final class Launcher extends Activity
// 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 @@ public final class Launcher extends Activity
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 dab2b588a..ed007dd67 100644
--- a/src/com/android/launcher2/LauncherApplication.java
+++ b/src/com/android/launcher2/LauncherApplication.java
@@ -38,11 +38,13 @@ public class LauncherApplication extends Application {
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 67aa31126..423a9d1fa 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.RemoteException;
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 @@ public class LauncherModel extends BroadcastReceiver {
mIconCache = iconCache;
mDefaultIcon = Utilities.createIconBitmap(
- app.getPackageManager().getDefaultActivityIcon(), app);
+ mIconCache.getFullResDefaultActivityIcon(), app);
mAllAppsLoadDelay = app.getResources().getInteger(R.integer.config_allAppsBatchLoadDelay);
@@ -1469,7 +1469,8 @@ public class LauncherModel extends BroadcastReceiver {
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 @@ public class LauncherModel extends BroadcastReceiver {
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 @@ public class LauncherModel extends BroadcastReceiver {
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 @@ public class LauncherModel extends BroadcastReceiver {
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);
+ Resources appResources = packageManager.getResourcesForApplication(packageName);
+ final int id = appResources.getIdentifier(resourceName, null, null);
+ liveFolderInfo.icon = Utilities.createIconBitmap(
+ mIconCache.getFullResIcon(appResources, id), context);
} catch (Exception e) {
+ 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);
}
liveFolderInfo.iconResource = new Intent.ShortcutIconResource();
@@ -1638,8 +1641,9 @@ public class LauncherModel extends BroadcastReceiver {
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 6c6c4dcd4..89cf331dd 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -48,20 +48,17 @@ public class PagedViewIcon extends TextView implements Checkable {
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 @@ public class PagedViewIcon extends TextView implements Checkable {
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 @@ public class PagedViewIcon extends TextView implements Checkable {
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 class PagedViewIcon extends TextView implements Checkable {
}
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 c67ff99de..03a2a528a 100644
--- a/src/com/android/launcher2/Utilities.java
+++ b/src/com/android/launcher2/Utilities.java
@@ -237,7 +237,7 @@ final class Utilities {
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 263c3a6da..08e04605e 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1767,7 +1767,7 @@ public class Workspace extends SmoothPagedView
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);