Fix mode icon sharing in modes list
Modes sharing the same icon would also share the applied tint (e.g. all with the "active" tint even if only the last one of them is active). (Although it should never happen, also removed a potential NPE for mode icons without ConstantState). Fixes: 367131481 Test: manual Flag: android.app.modes_ui Change-Id: I56867783310ea57f2e92c866ff0b5b53ac86bf37
This commit is contained in:
@@ -60,7 +60,7 @@ class IconUtil {
|
|||||||
|
|
||||||
private static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon,
|
private static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon,
|
||||||
@AttrRes int colorAttr) {
|
@AttrRes int colorAttr) {
|
||||||
icon = icon.mutate();
|
icon = mutateDrawable(context.getResources(), icon);
|
||||||
icon.setTintList(Utils.getColorAttr(context, colorAttr));
|
icon.setTintList(Utils.getColorAttr(context, colorAttr));
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
@@ -218,9 +218,9 @@ class IconUtil {
|
|||||||
|
|
||||||
private static Drawable composeIcons(Resources res, Drawable outer, ColorStateList outerColor,
|
private static Drawable composeIcons(Resources res, Drawable outer, ColorStateList outerColor,
|
||||||
@Px int outerSizePx, Drawable icon, ColorStateList iconColor, @Px int iconSizePx) {
|
@Px int outerSizePx, Drawable icon, ColorStateList iconColor, @Px int iconSizePx) {
|
||||||
Drawable background = checkNotNull(outer.getConstantState()).newDrawable(res).mutate();
|
Drawable background = mutateDrawable(res, outer);
|
||||||
background.setTintList(outerColor);
|
background.setTintList(outerColor);
|
||||||
Drawable foreground = checkNotNull(icon.getConstantState()).newDrawable(res).mutate();
|
Drawable foreground = mutateDrawable(res, icon);
|
||||||
foreground.setTintList(iconColor);
|
foreground.setTintList(iconColor);
|
||||||
|
|
||||||
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, foreground });
|
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, foreground });
|
||||||
@@ -232,4 +232,13 @@ class IconUtil {
|
|||||||
layerDrawable.setBounds(0, 0, outerSizePx, outerSizePx);
|
layerDrawable.setBounds(0, 0, outerSizePx, outerSizePx);
|
||||||
return layerDrawable;
|
return layerDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Drawable mutateDrawable(Resources res, Drawable drawable) {
|
||||||
|
Drawable.ConstantState cs = drawable.getConstantState();
|
||||||
|
if (cs != null) {
|
||||||
|
return cs.newDrawable(res).mutate();
|
||||||
|
} else {
|
||||||
|
return drawable.mutate();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user