diff --git a/src/api-impl/android/content/res/Resources.java b/src/api-impl/android/content/res/Resources.java index 1f74e924..0700d46f 100644 --- a/src/api-impl/android/content/res/Resources.java +++ b/src/api-impl/android/content/res/Resources.java @@ -2216,7 +2216,7 @@ public class Resources { try { XmlResourceParser rp = loadXmlResourceParser( file, id, value.assetCookie, "drawable"); - dr = Drawable.createFromXml(this, rp); + dr = Drawable.createFromXml(this, rp, theme); rp.close(); } catch (Exception e) { Trace.traceEnd(Trace.TRACE_TAG_RESOURCES); diff --git a/src/api-impl/android/graphics/drawable/AnimationDrawable.java b/src/api-impl/android/graphics/drawable/AnimationDrawable.java index 59e6e409..0978bddd 100644 --- a/src/api-impl/android/graphics/drawable/AnimationDrawable.java +++ b/src/api-impl/android/graphics/drawable/AnimationDrawable.java @@ -234,7 +234,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An /* public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { - TypedArray a = r.obtainAttributes(attrs, + TypedArray a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.AnimationDrawable); super.inflateWithAttributes(r, parser, a, @@ -262,7 +262,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An 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( com.android.internal.R.styleable.AnimationDrawableItem_duration, -1); if (duration < 0) { @@ -287,7 +287,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An + " defining a drawable"); } - dr = Drawable.createFromXmlInner(r, parser, attrs); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } mAnimationState.addFrame(dr, duration); diff --git a/src/api-impl/android/graphics/drawable/BitmapDrawable.java b/src/api-impl/android/graphics/drawable/BitmapDrawable.java index 757c36cf..b30d9fa2 100644 --- a/src/api-impl/android/graphics/drawable/BitmapDrawable.java +++ b/src/api-impl/android/graphics/drawable/BitmapDrawable.java @@ -40,10 +40,12 @@ public class BitmapDrawable extends Drawable { public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) 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)) { + try { bitmap = ((BitmapDrawable)a.getDrawable(R.styleable.BitmapDrawable_src)).bitmap; paintable = bitmap.getTexture(); + } catch (java.lang.Exception e) {e.printStackTrace();} } a.recycle(); } diff --git a/src/api-impl/android/graphics/drawable/Drawable.java b/src/api-impl/android/graphics/drawable/Drawable.java index 8825a3b1..50ff767f 100644 --- a/src/api-impl/android/graphics/drawable/Drawable.java +++ b/src/api-impl/android/graphics/drawable/Drawable.java @@ -14,6 +14,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.content.res.Resources.Theme; +import android.content.res.TypedArray; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; @@ -154,6 +155,13 @@ public class Drawable { 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 final int getLevel() {return 0;} @@ -202,12 +210,16 @@ public class Drawable { public boolean isProjected () {return false;} 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; 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); + return createFromXmlInner(resources, parser, parser, theme); } 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 { if ("selector".equals(parser.getName())) { StateListDrawable drawable = new StateListDrawable(); - drawable.inflate(resources, parser, attrs, null); + drawable.inflate(resources, parser, attrs, theme); return drawable; } else if ("shape".equals(parser.getName())) { GradientDrawable drawable = new GradientDrawable(); - drawable.inflate(resources, parser, attrs); + drawable.inflate(resources, parser, attrs, theme); return drawable; } else if ("bitmap".equals(parser.getName())) { BitmapDrawable drawable = new BitmapDrawable(); - drawable.inflate(resources, parser, attrs, null); + drawable.inflate(resources, parser, attrs, theme); return drawable; } else if ("transition".equals(parser.getName())) { return new Drawable(); @@ -234,11 +246,11 @@ public class Drawable { return new ColorDrawable(0); } else if ("vector".equals(parser.getName())) { VectorDrawable drawable = new VectorDrawable(); - drawable.inflate(resources, parser, attrs, null); + drawable.inflate(resources, parser, attrs, theme); return drawable; } else if ("layer-list".equals(parser.getName())) { LayerDrawable drawable = new LayerDrawable(); - drawable.inflate(resources, parser, attrs); + drawable.inflate(resources, parser, attrs, theme); return drawable; } else if ("nine-patch".equals(parser.getName())) { return new NinePatchDrawable(resources, null, null, null, null); diff --git a/src/api-impl/android/graphics/drawable/GradientDrawable.java b/src/api-impl/android/graphics/drawable/GradientDrawable.java index 80d4a37b..dd4a9f11 100644 --- a/src/api-impl/android/graphics/drawable/GradientDrawable.java +++ b/src/api-impl/android/graphics/drawable/GradientDrawable.java @@ -18,6 +18,7 @@ package android.graphics.drawable; import android.content.res.ColorStateList; import android.content.res.Resources; +import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; @@ -850,12 +851,12 @@ public class GradientDrawable extends Drawable { } public void inflate(Resources r, XmlPullParser parser, - AttributeSet attrs) + AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { final GradientState st = mGradientState; - TypedArray a = r.obtainAttributes(attrs, + TypedArray a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.GradientDrawable); // super.inflateWithAttributes(r, parser, a, @@ -904,7 +905,7 @@ public class GradientDrawable extends Drawable { String name = parser.getName(); if (name.equals("size")) { - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.GradientDrawableSize); int width = a.getDimensionPixelSize( com.android.internal.R.styleable.GradientDrawableSize_width, -1); @@ -913,7 +914,7 @@ public class GradientDrawable extends Drawable { a.recycle(); setSize(width, height); } else if (name.equals("gradient")) { - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.GradientDrawableGradient); int startColor = a.getColor( com.android.internal.R.styleable.GradientDrawableGradient_startColor, 0); @@ -1009,14 +1010,14 @@ public class GradientDrawable extends Drawable { } } else if (name.equals("solid")) { - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.GradientDrawableSolid); int argb = a.getColor( com.android.internal.R.styleable.GradientDrawableSolid_color, 0); a.recycle(); setColor(argb); } else if (name.equals("stroke")) { - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.GradientDrawableStroke); int width = a.getDimensionPixelSize( com.android.internal.R.styleable.GradientDrawableStroke_width, 0); @@ -1033,7 +1034,7 @@ public class GradientDrawable extends Drawable { } a.recycle(); } else if (name.equals("corners")) { - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.DrawableCorners); int radius = a.getDimensionPixelSize( com.android.internal.R.styleable.DrawableCorners_radius, 0); @@ -1057,7 +1058,7 @@ public class GradientDrawable extends Drawable { } a.recycle(); } else if (name.equals("padding")) { - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.GradientDrawablePadding); mPadding = new Rect( a.getDimensionPixelOffset( diff --git a/src/api-impl/android/graphics/drawable/LayerDrawable.java b/src/api-impl/android/graphics/drawable/LayerDrawable.java index 753c31a9..4ca375b0 100644 --- a/src/api-impl/android/graphics/drawable/LayerDrawable.java +++ b/src/api-impl/android/graphics/drawable/LayerDrawable.java @@ -17,6 +17,7 @@ package android.graphics.drawable; import android.content.res.Resources; +import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.ColorFilter; @@ -106,13 +107,13 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { } // @Override - public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) + public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { //super.inflate(r, parser, attrs); 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); @@ -131,7 +132,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { continue; } - a = r.obtainAttributes(attrs, + a = obtainAttributes(r, theme, attrs, com.android.internal.R.styleable.LayerDrawableItem); int left = a.getDimensionPixelOffset( @@ -159,7 +160,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { throw new XmlPullParserException(parser.getPositionDescription() + ": tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } - dr = Drawable.createFromXmlInner(r, parser, attrs); + dr = Drawable.createFromXmlInner(r, parser, attrs, theme); } if (dr != null)