You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
Drawable: fix theme not getting passed to newly inflated drawables
When Theme support was added, not everything was immediately updated to use theme information properly. This was fixed in a lot of places since then, but it seems not here.
This commit is contained in:
@@ -2216,7 +2216,7 @@ public class Resources {
|
|||||||
try {
|
try {
|
||||||
XmlResourceParser rp = loadXmlResourceParser(
|
XmlResourceParser rp = loadXmlResourceParser(
|
||||||
file, id, value.assetCookie, "drawable");
|
file, id, value.assetCookie, "drawable");
|
||||||
dr = Drawable.createFromXml(this, rp);
|
dr = Drawable.createFromXml(this, rp, theme);
|
||||||
rp.close();
|
rp.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
|
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
/* public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
|
/* public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
|
|
||||||
TypedArray a = r.obtainAttributes(attrs,
|
TypedArray a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.AnimationDrawable);
|
com.android.internal.R.styleable.AnimationDrawable);
|
||||||
|
|
||||||
super.inflateWithAttributes(r, parser, a,
|
super.inflateWithAttributes(r, parser, a,
|
||||||
@@ -262,7 +262,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = r.obtainAttributes(attrs, com.android.internal.R.styleable.AnimationDrawableItem);
|
a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.AnimationDrawableItem);
|
||||||
int duration = a.getInt(
|
int duration = a.getInt(
|
||||||
com.android.internal.R.styleable.AnimationDrawableItem_duration, -1);
|
com.android.internal.R.styleable.AnimationDrawableItem_duration, -1);
|
||||||
if (duration < 0) {
|
if (duration < 0) {
|
||||||
@@ -287,7 +287,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
+
|
+
|
||||||
" defining a drawable");
|
" defining a drawable");
|
||||||
}
|
}
|
||||||
dr = Drawable.createFromXmlInner(r, parser, attrs);
|
dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
mAnimationState.addFrame(dr, duration);
|
mAnimationState.addFrame(dr, duration);
|
||||||
|
|||||||
@@ -40,10 +40,12 @@ public class BitmapDrawable extends Drawable {
|
|||||||
|
|
||||||
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
final TypedArray a = r.obtainAttributes(attrs, R.styleable.BitmapDrawable);
|
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.BitmapDrawable);
|
||||||
if (a.hasValue(R.styleable.BitmapDrawable_src)) {
|
if (a.hasValue(R.styleable.BitmapDrawable_src)) {
|
||||||
|
try {
|
||||||
bitmap = ((BitmapDrawable)a.getDrawable(R.styleable.BitmapDrawable_src)).bitmap;
|
bitmap = ((BitmapDrawable)a.getDrawable(R.styleable.BitmapDrawable_src)).bitmap;
|
||||||
paintable = bitmap.getTexture();
|
paintable = bitmap.getTexture();
|
||||||
|
} catch (java.lang.Exception e) {e.printStackTrace();}
|
||||||
}
|
}
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import android.content.res.ColorStateList;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.content.res.Resources.Theme;
|
import android.content.res.Resources.Theme;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -154,6 +155,13 @@ public class Drawable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static TypedArray obtainAttributes(Resources r, Theme theme, AttributeSet set, int[] attrs) {
|
||||||
|
if (theme != null)
|
||||||
|
return theme.obtainStyledAttributes(set, attrs, 0, 0);
|
||||||
|
else
|
||||||
|
return r.obtainAttributes(set, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
public void clearColorFilter() {}
|
public void clearColorFilter() {}
|
||||||
|
|
||||||
public final int getLevel() {return 0;}
|
public final int getLevel() {return 0;}
|
||||||
@@ -202,12 +210,16 @@ public class Drawable {
|
|||||||
public boolean isProjected () {return false;}
|
public boolean isProjected () {return false;}
|
||||||
|
|
||||||
public static Drawable createFromXml(Resources resources, XmlResourceParser parser) throws XmlPullParserException, IOException {
|
public static Drawable createFromXml(Resources resources, XmlResourceParser parser) throws XmlPullParserException, IOException {
|
||||||
|
return createFromXml(resources, parser, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Drawable createFromXml(Resources resources, XmlResourceParser parser, Theme theme) throws XmlPullParserException, IOException {
|
||||||
int type;
|
int type;
|
||||||
while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
|
while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
|
||||||
if (type != XmlPullParser.START_TAG)
|
if (type != XmlPullParser.START_TAG)
|
||||||
throw new XmlPullParserException("No start tag found");
|
throw new XmlPullParserException("No start tag found");
|
||||||
|
|
||||||
return createFromXmlInner(resources, parser, parser, null);
|
return createFromXmlInner(resources, parser, parser, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
|
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
|
||||||
@@ -217,15 +229,15 @@ 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())) {
|
if ("selector".equals(parser.getName())) {
|
||||||
StateListDrawable drawable = new StateListDrawable();
|
StateListDrawable drawable = new StateListDrawable();
|
||||||
drawable.inflate(resources, parser, attrs, null);
|
drawable.inflate(resources, parser, attrs, theme);
|
||||||
return drawable;
|
return drawable;
|
||||||
} else if ("shape".equals(parser.getName())) {
|
} else if ("shape".equals(parser.getName())) {
|
||||||
GradientDrawable drawable = new GradientDrawable();
|
GradientDrawable drawable = new GradientDrawable();
|
||||||
drawable.inflate(resources, parser, attrs);
|
drawable.inflate(resources, parser, attrs, theme);
|
||||||
return drawable;
|
return drawable;
|
||||||
} else if ("bitmap".equals(parser.getName())) {
|
} else if ("bitmap".equals(parser.getName())) {
|
||||||
BitmapDrawable drawable = new BitmapDrawable();
|
BitmapDrawable drawable = new BitmapDrawable();
|
||||||
drawable.inflate(resources, parser, attrs, null);
|
drawable.inflate(resources, parser, attrs, theme);
|
||||||
return drawable;
|
return drawable;
|
||||||
} else if ("transition".equals(parser.getName())) {
|
} else if ("transition".equals(parser.getName())) {
|
||||||
return new Drawable();
|
return new Drawable();
|
||||||
@@ -234,11 +246,11 @@ public class Drawable {
|
|||||||
return new ColorDrawable(0);
|
return new ColorDrawable(0);
|
||||||
} else if ("vector".equals(parser.getName())) {
|
} else if ("vector".equals(parser.getName())) {
|
||||||
VectorDrawable drawable = new VectorDrawable();
|
VectorDrawable drawable = new VectorDrawable();
|
||||||
drawable.inflate(resources, parser, attrs, null);
|
drawable.inflate(resources, parser, attrs, theme);
|
||||||
return drawable;
|
return drawable;
|
||||||
} else if ("layer-list".equals(parser.getName())) {
|
} else if ("layer-list".equals(parser.getName())) {
|
||||||
LayerDrawable drawable = new LayerDrawable();
|
LayerDrawable drawable = new LayerDrawable();
|
||||||
drawable.inflate(resources, parser, attrs);
|
drawable.inflate(resources, parser, attrs, theme);
|
||||||
return drawable;
|
return drawable;
|
||||||
} else if ("nine-patch".equals(parser.getName())) {
|
} else if ("nine-patch".equals(parser.getName())) {
|
||||||
return new NinePatchDrawable(resources, null, null, null, null);
|
return new NinePatchDrawable(resources, null, null, null, null);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package android.graphics.drawable;
|
|||||||
|
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.content.res.Resources.Theme;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -850,12 +851,12 @@ public class GradientDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void inflate(Resources r, XmlPullParser parser,
|
public void inflate(Resources r, XmlPullParser parser,
|
||||||
AttributeSet attrs)
|
AttributeSet attrs, Theme theme)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
|
|
||||||
final GradientState st = mGradientState;
|
final GradientState st = mGradientState;
|
||||||
|
|
||||||
TypedArray a = r.obtainAttributes(attrs,
|
TypedArray a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.GradientDrawable);
|
com.android.internal.R.styleable.GradientDrawable);
|
||||||
|
|
||||||
// super.inflateWithAttributes(r, parser, a,
|
// super.inflateWithAttributes(r, parser, a,
|
||||||
@@ -904,7 +905,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
String name = parser.getName();
|
String name = parser.getName();
|
||||||
|
|
||||||
if (name.equals("size")) {
|
if (name.equals("size")) {
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.GradientDrawableSize);
|
com.android.internal.R.styleable.GradientDrawableSize);
|
||||||
int width = a.getDimensionPixelSize(
|
int width = a.getDimensionPixelSize(
|
||||||
com.android.internal.R.styleable.GradientDrawableSize_width, -1);
|
com.android.internal.R.styleable.GradientDrawableSize_width, -1);
|
||||||
@@ -913,7 +914,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
a.recycle();
|
a.recycle();
|
||||||
setSize(width, height);
|
setSize(width, height);
|
||||||
} else if (name.equals("gradient")) {
|
} else if (name.equals("gradient")) {
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.GradientDrawableGradient);
|
com.android.internal.R.styleable.GradientDrawableGradient);
|
||||||
int startColor = a.getColor(
|
int startColor = a.getColor(
|
||||||
com.android.internal.R.styleable.GradientDrawableGradient_startColor, 0);
|
com.android.internal.R.styleable.GradientDrawableGradient_startColor, 0);
|
||||||
@@ -1009,14 +1010,14 @@ public class GradientDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (name.equals("solid")) {
|
} else if (name.equals("solid")) {
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.GradientDrawableSolid);
|
com.android.internal.R.styleable.GradientDrawableSolid);
|
||||||
int argb = a.getColor(
|
int argb = a.getColor(
|
||||||
com.android.internal.R.styleable.GradientDrawableSolid_color, 0);
|
com.android.internal.R.styleable.GradientDrawableSolid_color, 0);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
setColor(argb);
|
setColor(argb);
|
||||||
} else if (name.equals("stroke")) {
|
} else if (name.equals("stroke")) {
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.GradientDrawableStroke);
|
com.android.internal.R.styleable.GradientDrawableStroke);
|
||||||
int width = a.getDimensionPixelSize(
|
int width = a.getDimensionPixelSize(
|
||||||
com.android.internal.R.styleable.GradientDrawableStroke_width, 0);
|
com.android.internal.R.styleable.GradientDrawableStroke_width, 0);
|
||||||
@@ -1033,7 +1034,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
a.recycle();
|
a.recycle();
|
||||||
} else if (name.equals("corners")) {
|
} else if (name.equals("corners")) {
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.DrawableCorners);
|
com.android.internal.R.styleable.DrawableCorners);
|
||||||
int radius = a.getDimensionPixelSize(
|
int radius = a.getDimensionPixelSize(
|
||||||
com.android.internal.R.styleable.DrawableCorners_radius, 0);
|
com.android.internal.R.styleable.DrawableCorners_radius, 0);
|
||||||
@@ -1057,7 +1058,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
a.recycle();
|
a.recycle();
|
||||||
} else if (name.equals("padding")) {
|
} else if (name.equals("padding")) {
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.GradientDrawablePadding);
|
com.android.internal.R.styleable.GradientDrawablePadding);
|
||||||
mPadding = new Rect(
|
mPadding = new Rect(
|
||||||
a.getDimensionPixelOffset(
|
a.getDimensionPixelOffset(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package android.graphics.drawable;
|
package android.graphics.drawable;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.content.res.Resources.Theme;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
@@ -106,13 +107,13 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
|
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
//super.inflate(r, parser, attrs);
|
//super.inflate(r, parser, attrs);
|
||||||
|
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawable);
|
TypedArray a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.LayerDrawable);
|
||||||
|
|
||||||
// mOpacityOverride = a.getInt(com.android.internal.R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
|
// mOpacityOverride = a.getInt(com.android.internal.R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = r.obtainAttributes(attrs,
|
a = obtainAttributes(r, theme, attrs,
|
||||||
com.android.internal.R.styleable.LayerDrawableItem);
|
com.android.internal.R.styleable.LayerDrawableItem);
|
||||||
|
|
||||||
int left = a.getDimensionPixelOffset(
|
int left = a.getDimensionPixelOffset(
|
||||||
@@ -159,7 +160,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or "
|
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or "
|
||||||
+ "child tag defining a drawable");
|
+ "child tag defining a drawable");
|
||||||
}
|
}
|
||||||
dr = Drawable.createFromXmlInner(r, parser, attrs);
|
dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dr != null)
|
if (dr != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user