diff options
4 files changed, 24 insertions, 20 deletions
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 736dfeba1..12170309b 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()); @@ -437,10 +438,9 @@ public class IconCache { * Updates {@param application} only if a valid entry is found. */ public synchronized void updateTitleAndIcon(AppInfo application) { - boolean usePackageIcon = application instanceof PromiseAppInfo; CacheEntry entry = cacheLocked(application.componentName, Provider.<LauncherActivityInfo>of(null), - application.user, usePackageIcon, application.usingLowResIcon); + application.user, false, application.usingLowResIcon); if (entry.icon != null && !isDefaultIcon(entry.icon, application.user)) { applyCacheEntry(entry, application); } @@ -538,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( @@ -635,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); @@ -768,7 +769,7 @@ public class IconCache { } private static final class IconDB extends SQLiteCacheHelper { - private final static int DB_VERSION = 11; + 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 4ae3649df..c525cd4bc 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; @@ -435,20 +436,19 @@ public class WidgetPreviewLoader { float shadowBlur = res.getDimension(R.dimen.widget_preview_shadow_blur); float keyShadowDistance = res.getDimension(R.dimen.widget_preview_key_shadow_distance); float corner = res.getDimension(R.dimen.widget_preview_corner_radius); - int shadowColor = ColorUtils.setAlphaComponent( - res.getColor(R.color.default_shadow_color_no_alpha), - ShadowGenerator.AMBIENT_SHADOW_ALPHA); RectF bounds = new RectF(shadowBlur, shadowBlur, width - shadowBlur, height - shadowBlur - keyShadowDistance); p.setColor(Color.WHITE); // Key shadow - p.setShadowLayer(shadowBlur, 0, keyShadowDistance, shadowColor); + p.setShadowLayer(shadowBlur, 0, keyShadowDistance, + ShadowGenerator.KEY_SHADOW_ALPHA << 24); c.drawRoundRect(bounds, corner, corner, p); // Ambient shadow - p.setShadowLayer(shadowBlur, 0, 0, shadowColor); + p.setShadowLayer(shadowBlur, 0, 0, + ColorUtils.setAlphaComponent(Color.BLACK, ShadowGenerator.AMBIENT_SHADOW_ALPHA)); c.drawRoundRect(bounds, corner, corner, p); p.clearShadowLayer(); @@ -482,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 f652a5c15..e671a82e9 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 b4118790c..6628971a5 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(); |