Drawable: minor cleanup, add support for inflating adaptive-icon

This commit is contained in:
Mis012
2025-06-08 13:31:19 +02:00
parent 9461c47082
commit ed240daf66

View File

@@ -94,6 +94,10 @@ public class Drawable {
onBoundsChange(mBounds); onBoundsChange(mBounds);
} }
public void setBounds(Rect bounds) {
setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
}
public final Rect getBounds() { public final Rect getBounds() {
return mBounds; return mBounds;
} }
@@ -169,10 +173,6 @@ public class Drawable {
public final int getLevel() {return 0;} public final int getLevel() {return 0;}
public final boolean setLevel(int level) {return false;} public final boolean setLevel(int level) {return false;}
public void setBounds(Rect bounds) {
setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
}
public void setColorFilter(int color, PorterDuff.Mode mode) { public void setColorFilter(int color, PorterDuff.Mode mode) {
setColorFilter(new PorterDuffColorFilter(color, mode)); setColorFilter(new PorterDuffColorFilter(color, mode));
} }
@@ -229,36 +229,51 @@ public class Drawable {
} }
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
if ("selector".equals(parser.getName())) { switch (parser.getName()) {
case "selector": {
StateListDrawable drawable = new StateListDrawable(); StateListDrawable drawable = new StateListDrawable();
drawable.inflate(resources, parser, attrs, theme); drawable.inflate(resources, parser, attrs, theme);
return drawable; return drawable;
} else if ("shape".equals(parser.getName())) { }
case "shape": {
GradientDrawable drawable = new GradientDrawable(); GradientDrawable drawable = new GradientDrawable();
drawable.inflate(resources, parser, attrs, theme); drawable.inflate(resources, parser, attrs, theme);
return drawable; return drawable;
} else if ("bitmap".equals(parser.getName())) { } case "bitmap": {
BitmapDrawable drawable = new BitmapDrawable(); BitmapDrawable drawable = new BitmapDrawable();
drawable.inflate(resources, parser, attrs, theme); drawable.inflate(resources, parser, attrs, theme);
return drawable; return drawable;
} else if ("transition".equals(parser.getName())) { }
case "transition": {
return new Drawable(); return new Drawable();
} else if ("ripple".equals(parser.getName())) { }
case "ripple": {
// FIXME: the non-pressed state of RippleDrawable should be equivalent to this // FIXME: the non-pressed state of RippleDrawable should be equivalent to this
return new ColorDrawable(0); return new ColorDrawable(0);
} else if ("vector".equals(parser.getName())) { }
case "vector": {
VectorDrawable drawable = new VectorDrawable(); VectorDrawable drawable = new VectorDrawable();
drawable.inflate(resources, parser, attrs, theme); drawable.inflate(resources, parser, attrs, theme);
return drawable; return drawable;
} else if ("layer-list".equals(parser.getName())) { }
case "layer-list": {
LayerDrawable drawable = new LayerDrawable(); LayerDrawable drawable = new LayerDrawable();
drawable.inflate(resources, parser, attrs, theme); drawable.inflate(resources, parser, attrs, theme);
return drawable; return drawable;
} else if ("nine-patch".equals(parser.getName())) { }
case "nine-patch": {
return new NinePatchDrawable(resources, null, null, null, null); return new NinePatchDrawable(resources, null, null, null, null);
} else if ("animation-list".equals(parser.getName())) { }
case "animation-list": {
return new AnimationDrawable(); return new AnimationDrawable();
} }
case "adaptive-icon": {
AdaptiveIconDrawable drawable = new AdaptiveIconDrawable();
drawable.inflate(resources, parser, attrs, theme);
return drawable;
}
}
return null; return null;
} }