for (ResolveInfo info : matches) {
adapter.setNotifyOnChange(false);
- adapter.add(makeAndCacheApplicationInfo(packageManager, cache, info));
+ adapter.add(makeAndCacheApplicationInfo(packageManager, cache, info, launcher));
}
adapter.sort(new ApplicationInfoComparator());
final ApplicationInfo applicationInfo = findIntent(adapter,
info.activityInfo.applicationInfo.packageName, info.activityInfo.name);
if (applicationInfo != null) {
- updateAndCacheApplicationInfo(packageManager, info, applicationInfo);
+ updateAndCacheApplicationInfo(packageManager, info, applicationInfo, launcher);
changed = true;
}
}
}
private void updateAndCacheApplicationInfo(PackageManager packageManager, ResolveInfo info,
- ApplicationInfo applicationInfo) {
+ ApplicationInfo applicationInfo, Context context) {
- updateApplicationInfoTitleAndIcon(packageManager, info, applicationInfo);
+ updateApplicationInfoTitleAndIcon(packageManager, info, applicationInfo, context);
ComponentName componentName = new ComponentName(
info.activityInfo.applicationInfo.packageName, info.activityInfo.name);
info.activityInfo.applicationInfo.packageName, info.activityInfo.name);
if (applicationInfo == null) {
toAdd.add(makeAndCacheApplicationInfo(launcher.getPackageManager(),
- mAppInfoCache, info));
+ mAppInfoCache, info, launcher));
changed = true;
} else {
- updateAndCacheApplicationInfo(launcher.getPackageManager(), info, applicationInfo);
+ updateAndCacheApplicationInfo(
+ launcher.getPackageManager(), info, applicationInfo, launcher);
changed = true;
}
}
}
private static ApplicationInfo makeAndCacheApplicationInfo(PackageManager manager,
- HashMap<ComponentName, ApplicationInfo> appInfoCache, ResolveInfo info) {
+ HashMap<ComponentName, ApplicationInfo> appInfoCache, ResolveInfo info,
+ Context context) {
ComponentName componentName = new ComponentName(
info.activityInfo.applicationInfo.packageName,
application = new ApplicationInfo();
application.container = ItemInfo.NO_ID;
- updateApplicationInfoTitleAndIcon(manager, info, application);
+ updateApplicationInfoTitleAndIcon(manager, info, application, context);
application.setActivity(componentName,
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
}
private static void updateApplicationInfoTitleAndIcon(PackageManager manager, ResolveInfo info,
- ApplicationInfo application) {
+ ApplicationInfo application, Context context) {
application.title = info.loadLabel(manager);
if (application.title == null) {
application.title = info.activityInfo.name;
}
- application.icon = info.activityInfo.loadIcon(manager);
+ application.icon =
+ Utilities.createIconThumbnail(info.activityInfo.loadIcon(manager), context);
application.filtered = false;
}
for (int i = 0; i < count && !mStopped; i++) {
ResolveInfo info = apps.get(i);
ApplicationInfo application =
- makeAndCacheApplicationInfo(manager, appInfoCache, info);
+ makeAndCacheApplicationInfo(manager, appInfoCache, info, launcher);
if (action.add(application) && !mStopped) {
launcher.runOnUiThread(action);
}
if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
- info = getApplicationInfo(manager, intent);
+ info = getApplicationInfo(manager, intent, launcher);
} else {
info = getApplicationInfoShortcut(c, launcher, iconTypeIndex,
iconPackageIndex, iconResourceIndex, iconIndex);
/**
* Make an ApplicationInfo object for an application
*/
- private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent) {
+ private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent,
+ Context context) {
final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
if (resolveInfo == null) {
final ApplicationInfo info = new ApplicationInfo();
final ActivityInfo activityInfo = resolveInfo.activityInfo;
- info.icon = activityInfo.loadIcon(manager);
+ info.icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context);
if (info.title == null || info.title.length() == 0) {
info.title = activityInfo.loadLabel(manager);
}
try {
Resources resources = packageManager.getResourcesForApplication(packageName);
final int id = resources.getIdentifier(resourceName, null, null);
- info.icon = resources.getDrawable(id);
+ info.icon = Utilities.createIconThumbnail(resources.getDrawable(id), launcher);
} catch (Exception e) {
info.icon = packageManager.getDefaultActivityIcon();
}
package com.android.launcher;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.graphics.Bitmap;
static Drawable createIconThumbnail(Drawable icon, Context context) {
if (sIconWidth == -1) {
final Resources resources = context.getResources();
- sIconWidth = sIconHeight = (int) resources.getDimension(
- android.R.dimen.app_icon_size);
+ sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
}
int width = sIconWidth;
int height = sIconHeight;
- final int iconWidth = icon.getIntrinsicWidth();
- final int iconHeight = icon.getIntrinsicHeight();
-
+ float scale = 1.0f;
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
+ } else if (icon instanceof BitmapDrawable) {
+ float displayDensity = context.getResources().getDisplayMetrics().density;
+ BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
+ Bitmap bitmap = bitmapDrawable.getBitmap();
+ float iconDensity = bitmap.getDensityScale();
+ scale = displayDensity / iconDensity;
+
+ // Scale the bitmap to the screen density size if it's not loaded at the same density.
+ if (scale != 1.0f) {
+ icon = bitmapDrawable = new BitmapDrawable(bitmap);
+ bitmapDrawable.setDensityScale(scale);
+ }
}
+ int iconWidth = icon.getIntrinsicWidth();
+ int iconHeight = icon.getIntrinsicHeight();
if (width > 0 && height > 0) {
- if (width < iconWidth || height < iconHeight) {
+ if (width < iconWidth || height < iconHeight || scale != 1.0f) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {