From 7ed61012187b0d7a85a96bdbe396fbe74540bf2b Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Wed, 26 Apr 2017 13:42:12 -0700 Subject: [PATCH] Only apply legacy treatment on app icons that is targeting O For shortcuts, always apply legacy treatment. b/37357483 Change-Id: I45f373ee0bb9436bc5029c88855ecb80b93fe277 --- src/com/android/launcher3/IconCache.java | 12 +++++++----- src/com/android/launcher3/WidgetPreviewLoader.java | 3 ++- .../android/launcher3/graphics/LauncherIcons.java | 14 ++++++++------ .../launcher3/widget/PendingItemDragHelper.java | 3 ++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 2a8397c49f..12170309b9 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -37,6 +37,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Handler; import android.os.Process; import android.os.SystemClock; @@ -194,7 +195,7 @@ public class IconCache { protected Bitmap makeDefaultIcon(UserHandle user) { Drawable unbadged = getFullResDefaultActivityIcon(); - return LauncherIcons.createBadgedIconBitmap(unbadged, user, mContext); + return LauncherIcons.createBadgedIconBitmap(unbadged, user, mContext, Build.VERSION_CODES.O); } /** @@ -380,7 +381,7 @@ public class IconCache { if (entry == null) { entry = new CacheEntry(); entry.icon = LauncherIcons.createBadgedIconBitmap(getFullResIcon(app), app.getUser(), - mContext); + mContext, app.getApplicationInfo().targetSdkVersion); } entry.title = app.getLabel(); entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser()); @@ -537,7 +538,8 @@ public class IconCache { if (info != null) { entry.icon = LauncherIcons.createBadgedIconBitmap( - getFullResIcon(info), info.getUser(), mContext); + getFullResIcon(info), info.getUser(), mContext, + infoProvider.get().getApplicationInfo().targetSdkVersion); } else { if (usePackageIcon) { CacheEntry packageEntry = getEntryForPackageLocked( @@ -634,7 +636,7 @@ public class IconCache { // Load the full res icon for the application, but if useLowResIcon is set, then // only keep the low resolution icon instead of the larger full-sized icon Bitmap icon = LauncherIcons.createBadgedIconBitmap( - appInfo.loadIcon(mPackageManager), user, mContext); + appInfo.loadIcon(mPackageManager), user, mContext, appInfo.targetSdkVersion); Bitmap lowResIcon = generateLowResIcon(icon, mPackageBgColor); entry.title = appInfo.loadLabel(mPackageManager); entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user); @@ -767,7 +769,7 @@ public class IconCache { } private static final class IconDB extends SQLiteCacheHelper { - private final static int DB_VERSION = 12; + private final static int DB_VERSION = 13; private final static int RELEASE_VERSION = DB_VERSION + (FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ? 0 : 1); diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index fc3b668877..c525cd4bc0 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -22,6 +22,7 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.os.Build; import android.os.CancellationSignal; import android.os.Handler; import android.os.UserHandle; @@ -481,7 +482,7 @@ public class WidgetPreviewLoader { RectF boxRect = drawBoxWithShadow(c, p, size, size); Bitmap icon = LauncherIcons.createScaledBitmapWithoutShadow( - mutateOnMainThread(info.getFullResIcon(mIconCache)), mContext); + mutateOnMainThread(info.getFullResIcon(mIconCache)), mContext, Build.VERSION_CODES.O); Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight()); boxRect.set(0, 0, iconSize, iconSize); diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index f652a5c159..e671a82e92 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -32,6 +32,7 @@ import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.PaintDrawable; +import android.os.Build; import android.os.Process; import android.os.UserHandle; @@ -94,13 +95,13 @@ public class LauncherIcons { * The bitmap is also visually normalized with other icons. */ public static Bitmap createBadgedIconBitmap( - Drawable icon, UserHandle user, Context context) { + Drawable icon, UserHandle user, Context context, int iconAppTargetSdk) { IconNormalizer normalizer; float scale = 1f; if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) { normalizer = IconNormalizer.getInstance(context); - if (Utilities.isAtLeastO()) { + if (Utilities.isAtLeastO() && iconAppTargetSdk >= Build.VERSION_CODES.O) { boolean[] outShape = new boolean[1]; AdaptiveIconDrawable dr = (AdaptiveIconDrawable) context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate(); @@ -148,13 +149,13 @@ public class LauncherIcons { * Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually * normalized with other icons and has enough spacing to add shadow. */ - public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context) { + public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context, int iconAppTargetSdk) { RectF iconBounds = new RectF(); IconNormalizer normalizer; float scale = 1f; if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) { normalizer = IconNormalizer.getInstance(context); - if (Utilities.isAtLeastO()) { + if (Utilities.isAtLeastO() && iconAppTargetSdk >= Build.VERSION_CODES.O) { boolean[] outShape = new boolean[1]; AdaptiveIconDrawable dr = (AdaptiveIconDrawable) context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate(); @@ -179,7 +180,7 @@ public class LauncherIcons { /** * Adds a shadow to the provided icon. It assumes that the icon has already been scaled using - * {@link #createScaledBitmapWithoutShadow(Drawable, Context)} + * {@link #createScaledBitmapWithoutShadow(Drawable, Context, int)} */ public static Bitmap addShadowToIcon(Bitmap icon, Context context) { return ShadowGenerator.getInstance(context).recreateIcon(icon); @@ -318,7 +319,8 @@ public class LauncherIcons { IconCache cache = app.getIconCache(); Bitmap unbadgedBitmap = unbadgedDrawable == null ? cache.getDefaultIcon(Process.myUserHandle()) - : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context); + : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context, + Build.VERSION_CODES.O); if (!badged) { return unbadgedBitmap; diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java index b4118790c7..6628971a59 100644 --- a/src/com/android/launcher3/widget/PendingItemDragHelper.java +++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java @@ -22,6 +22,7 @@ import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Build; import android.view.View; import android.widget.RemoteViews; @@ -115,7 +116,7 @@ public class PendingItemDragHelper extends DragPreviewProvider { } else { PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) mAddInfo; Drawable icon = createShortcutInfo.activityInfo.getFullResIcon(app.getIconCache()); - preview = LauncherIcons.createScaledBitmapWithoutShadow(icon, launcher); + preview = LauncherIcons.createScaledBitmapWithoutShadow(icon, launcher, Build.VERSION_CODES.O); mAddInfo.spanX = mAddInfo.spanY = 1; scale = ((float) launcher.getDeviceProfile().iconSizePx) / preview.getWidth();