Add shadow to Adaptive Icons

Bug: 35920618

Change-Id: Ib48a656f988d1f007c32ab15cb28d120fab1e94f
This commit is contained in:
Hyunyoung Song
2017-03-02 12:36:08 -08:00
parent d8745db015
commit da9ac1f01a
2 changed files with 14 additions and 2 deletions
@@ -201,7 +201,7 @@ public class LauncherIcons {
int textureWidth = iconBitmapSize;
int textureHeight = iconBitmapSize;
final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
Bitmap.Config.ARGB_8888);
final Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
@@ -218,6 +218,16 @@ public class LauncherIcons {
icon.setBounds(sOldBounds);
canvas.setBitmap(null);
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO()) {
try {
Class clazz = Class.forName("android.graphics.drawable.AdaptiveIconDrawable");
if (clazz.isAssignableFrom(icon.getClass())) {
bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
}
} catch (Exception e) {
// do nothing
}
}
return bitmap;
}
}
@@ -233,7 +243,7 @@ public class LauncherIcons {
}
try {
Class clazz = Class.forName("android.graphics.drawable.MaskableIconDrawable");
Class clazz = Class.forName("android.graphics.drawable.AdaptiveIconDrawable");
if (!clazz.isAssignableFrom(drawable.getClass())) {
Drawable maskWrapper =
context.getDrawable(R.drawable.mask_drawable_wrapper).mutate();
@@ -44,4 +44,6 @@ public final class FeatureFlags {
public static final boolean BADGE_ICONS = true;
// When enabled, icons not supporting {@link MaskableIconDrawable} will be wrapped in this class.
public static final boolean LEGACY_ICON_TREATMENT = false;
// When enabled, adaptive icons would have shadows baked when being stored to icon cache.
public static final boolean ADAPTIVE_ICON_SHADOW = true;
}