Drawable: implement GradientDrawable.inflate() and Drawable.createFromXmlInner()

This commit is contained in:
Julian Winkler
2024-05-19 15:06:17 +02:00
parent dd3965df8a
commit 765f01e715
3 changed files with 19 additions and 17 deletions

View File

@@ -176,15 +176,26 @@ public class Drawable {
while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
if (type != XmlPullParser.START_TAG)
throw new XmlPullParserException("No start tag found");
return createFromXmlInner(resources, parser, parser, null);
}
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
return createFromXmlInner(resources, parser, attrs, null);
}
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
if ("selector".equals(parser.getName())) {
StateListDrawable drawable = new StateListDrawable();
drawable.inflate(resources, parser, parser, null);
drawable.inflate(resources, parser, attrs, null);
return drawable;
} else if ("shape".equals(parser.getName())) {
return new GradientDrawable();
GradientDrawable drawable = new GradientDrawable();
drawable.inflate(resources, parser, attrs);
return drawable;
} else if ("bitmap".equals(parser.getName())) {
BitmapDrawable drawable = new BitmapDrawable();
drawable.inflate(resources, parser, parser, null);
drawable.inflate(resources, parser, attrs, null);
return drawable;
} else if ("transition".equals(parser.getName())) {
return new Drawable();
@@ -193,7 +204,7 @@ public class Drawable {
return new ColorDrawable(0);
} else if ("vector".equals(parser.getName())) {
VectorDrawable drawable = new VectorDrawable();
drawable.inflate(resources, parser, parser, null);
drawable.inflate(resources, parser, attrs, null);
return drawable;
} else if ("layer-list".equals(parser.getName())) {
return new LayerDrawable();
@@ -201,14 +212,6 @@ public class Drawable {
return null;
}
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs) {
return createFromXmlInner(resources, parser, attrs, null);
}
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) {
return null;
}
public static Drawable createFromResourceStream(Resources resources, TypedValue value, InputStream is, String file,
Object object) {
Path path = Paths.get(android.os.Environment.getExternalStorageDirectory().getPath(), file);

View File

@@ -850,7 +850,6 @@ public class GradientDrawable extends Drawable {
return !mRect.isEmpty();
}
/* @Override
public void inflate(Resources r, XmlPullParser parser,
AttributeSet attrs)
throws XmlPullParserException, IOException {
@@ -860,8 +859,8 @@ public class GradientDrawable extends Drawable {
TypedArray a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.GradientDrawable);
super.inflateWithAttributes(r, parser, a,
com.android.internal.R.styleable.GradientDrawable_visible);
// super.inflateWithAttributes(r, parser, a,
// com.android.internal.R.styleable.GradientDrawable_visible);
int shapeType = a.getInt(
com.android.internal.R.styleable.GradientDrawable_shape, RECTANGLE);
@@ -1078,7 +1077,7 @@ public class GradientDrawable extends Drawable {
}
mGradientState.computeOpacity();
}*/
}
private static float getFloatOrFraction(TypedArray a, int index, float defaultValue) {
TypedValue tv = a.peekValue(index);

View File

@@ -155,7 +155,7 @@ public class StateListDrawable extends DrawableContainer {
+ ": <item> tag requires a 'drawable' attribute or "
+ "child tag defining a drawable");
}
// dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
}
state.addStateSet(states, dr);