Add shadow to Adaptive Icons
Bug: 35920618 Change-Id: Ib48a656f988d1f007c32ab15cb28d120fab1e94f
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user