Loading graphics/java/android/graphics/drawable/ShapeDrawable.java +62 −24 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.graphics.drawable.shapes.Shape; import android.content.res.Resources.Theme; import android.content.res.Resources.Theme; import android.util.AttributeSet; import android.util.AttributeSet; import com.android.internal.R; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -74,7 +75,7 @@ public class ShapeDrawable extends Drawable { * ShapeDrawable constructor. * ShapeDrawable constructor. */ */ public ShapeDrawable() { public ShapeDrawable() { this((ShapeState) null); this(new ShapeState(null), null, null); } } /** /** Loading @@ -83,17 +84,11 @@ public class ShapeDrawable extends Drawable { * @param s the Shape that this ShapeDrawable should be * @param s the Shape that this ShapeDrawable should be */ */ public ShapeDrawable(Shape s) { public ShapeDrawable(Shape s) { this((ShapeState) null); this(new ShapeState(null), null, null); mShapeState.mShape = s; mShapeState.mShape = s; } } private ShapeDrawable(ShapeState state) { mShapeState = new ShapeState(state); updateTintFilter(mTintFilter, state.mTint, state.mTintMode); } /** /** * Returns the Shape of this ShapeDrawable. * Returns the Shape of this ShapeDrawable. */ */ Loading Loading @@ -405,20 +400,8 @@ public class ShapeDrawable extends Drawable { throws XmlPullParserException, IOException { throws XmlPullParserException, IOException { super.inflate(r, parser, attrs, theme); super.inflate(r, parser, attrs, theme); TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.ShapeDrawable); final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.ShapeDrawable); updateStateFromTypedArray(a); int color = mShapeState.mPaint.getColor(); color = a.getColor(com.android.internal.R.styleable.ShapeDrawable_color, color); mShapeState.mPaint.setColor(color); boolean dither = a.getBoolean(com.android.internal.R.styleable.ShapeDrawable_dither, false); mShapeState.mPaint.setDither(dither); setIntrinsicWidth((int) a.getDimension(com.android.internal.R.styleable.ShapeDrawable_width, 0f)); setIntrinsicHeight((int) a.getDimension(com.android.internal.R.styleable.ShapeDrawable_height, 0f)); a.recycle(); a.recycle(); int type; int type; Loading @@ -438,6 +421,38 @@ public class ShapeDrawable extends Drawable { } } } } @Override public void applyTheme(Theme t) { super.applyTheme(t); final ShapeState state = mShapeState; if (state == null || state.mThemeAttrs == null) { return; } final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.ShapeDrawable); updateStateFromTypedArray(a); a.recycle(); } private void updateStateFromTypedArray(TypedArray a) { final ShapeState state = mShapeState; final Paint paint = state.mPaint; int color = paint.getColor(); color = a.getColor(R.styleable.ShapeDrawable_color, color); paint.setColor(color); boolean dither = paint.isDither(); dither = a.getBoolean(R.styleable.ShapeDrawable_dither, dither); paint.setDither(dither); setIntrinsicWidth((int) a.getDimension( R.styleable.ShapeDrawable_width, state.mIntrinsicWidth)); setIntrinsicHeight((int) a.getDimension( R.styleable.ShapeDrawable_height, state.mIntrinsicHeight)); } private void updateShape() { private void updateShape() { if (mShapeState.mShape != null) { if (mShapeState.mShape != null) { final Rect r = getBounds(); final Rect r = getBounds(); Loading Loading @@ -495,6 +510,7 @@ public class ShapeDrawable extends Drawable { * Defines the intrinsic properties of this ShapeDrawable's Shape. * Defines the intrinsic properties of this ShapeDrawable's Shape. */ */ final static class ShapeState extends ConstantState { final static class ShapeState extends ConstantState { int[] mThemeAttrs; int mChangingConfigurations; int mChangingConfigurations; Paint mPaint; Paint mPaint; Shape mShape; Shape mShape; Loading @@ -508,6 +524,7 @@ public class ShapeDrawable extends Drawable { ShapeState(ShapeState orig) { ShapeState(ShapeState orig) { if (orig != null) { if (orig != null) { mThemeAttrs = orig.mThemeAttrs; mPaint = orig.mPaint; mPaint = orig.mPaint; mShape = orig.mShape; mShape = orig.mShape; mTint = orig.mTint; mTint = orig.mTint; Loading @@ -522,14 +539,24 @@ public class ShapeDrawable extends Drawable { } } } } @Override public boolean canApplyTheme() { return mThemeAttrs != null; } @Override @Override public Drawable newDrawable() { public Drawable newDrawable() { return new ShapeDrawable(this); return new ShapeDrawable(this, null, null); } } @Override @Override public Drawable newDrawable(Resources res) { public Drawable newDrawable(Resources res) { return new ShapeDrawable(this); return new ShapeDrawable(this, res, null); } @Override public Drawable newDrawable(Resources res, Theme theme) { return new ShapeDrawable(this, res, theme); } } @Override @Override Loading @@ -538,6 +565,17 @@ public class ShapeDrawable extends Drawable { } } } } private ShapeDrawable(ShapeState state, Resources res, Theme theme) { if (theme != null && state.canApplyTheme()) { mShapeState = new ShapeState(state); applyTheme(theme); } else { mShapeState = state; } mTintFilter = updateTintFilter(mTintFilter, mShapeState.mTint, mShapeState.mTintMode); } /** /** * Base class defines a factory object that is called each time the drawable * Base class defines a factory object that is called each time the drawable * is resized (has a new width or height). Its resize() method returns a * is resized (has a new width or height). Its resize() method returns a Loading Loading
graphics/java/android/graphics/drawable/ShapeDrawable.java +62 −24 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.graphics.drawable.shapes.Shape; import android.content.res.Resources.Theme; import android.content.res.Resources.Theme; import android.util.AttributeSet; import android.util.AttributeSet; import com.android.internal.R; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -74,7 +75,7 @@ public class ShapeDrawable extends Drawable { * ShapeDrawable constructor. * ShapeDrawable constructor. */ */ public ShapeDrawable() { public ShapeDrawable() { this((ShapeState) null); this(new ShapeState(null), null, null); } } /** /** Loading @@ -83,17 +84,11 @@ public class ShapeDrawable extends Drawable { * @param s the Shape that this ShapeDrawable should be * @param s the Shape that this ShapeDrawable should be */ */ public ShapeDrawable(Shape s) { public ShapeDrawable(Shape s) { this((ShapeState) null); this(new ShapeState(null), null, null); mShapeState.mShape = s; mShapeState.mShape = s; } } private ShapeDrawable(ShapeState state) { mShapeState = new ShapeState(state); updateTintFilter(mTintFilter, state.mTint, state.mTintMode); } /** /** * Returns the Shape of this ShapeDrawable. * Returns the Shape of this ShapeDrawable. */ */ Loading Loading @@ -405,20 +400,8 @@ public class ShapeDrawable extends Drawable { throws XmlPullParserException, IOException { throws XmlPullParserException, IOException { super.inflate(r, parser, attrs, theme); super.inflate(r, parser, attrs, theme); TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.ShapeDrawable); final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.ShapeDrawable); updateStateFromTypedArray(a); int color = mShapeState.mPaint.getColor(); color = a.getColor(com.android.internal.R.styleable.ShapeDrawable_color, color); mShapeState.mPaint.setColor(color); boolean dither = a.getBoolean(com.android.internal.R.styleable.ShapeDrawable_dither, false); mShapeState.mPaint.setDither(dither); setIntrinsicWidth((int) a.getDimension(com.android.internal.R.styleable.ShapeDrawable_width, 0f)); setIntrinsicHeight((int) a.getDimension(com.android.internal.R.styleable.ShapeDrawable_height, 0f)); a.recycle(); a.recycle(); int type; int type; Loading @@ -438,6 +421,38 @@ public class ShapeDrawable extends Drawable { } } } } @Override public void applyTheme(Theme t) { super.applyTheme(t); final ShapeState state = mShapeState; if (state == null || state.mThemeAttrs == null) { return; } final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.ShapeDrawable); updateStateFromTypedArray(a); a.recycle(); } private void updateStateFromTypedArray(TypedArray a) { final ShapeState state = mShapeState; final Paint paint = state.mPaint; int color = paint.getColor(); color = a.getColor(R.styleable.ShapeDrawable_color, color); paint.setColor(color); boolean dither = paint.isDither(); dither = a.getBoolean(R.styleable.ShapeDrawable_dither, dither); paint.setDither(dither); setIntrinsicWidth((int) a.getDimension( R.styleable.ShapeDrawable_width, state.mIntrinsicWidth)); setIntrinsicHeight((int) a.getDimension( R.styleable.ShapeDrawable_height, state.mIntrinsicHeight)); } private void updateShape() { private void updateShape() { if (mShapeState.mShape != null) { if (mShapeState.mShape != null) { final Rect r = getBounds(); final Rect r = getBounds(); Loading Loading @@ -495,6 +510,7 @@ public class ShapeDrawable extends Drawable { * Defines the intrinsic properties of this ShapeDrawable's Shape. * Defines the intrinsic properties of this ShapeDrawable's Shape. */ */ final static class ShapeState extends ConstantState { final static class ShapeState extends ConstantState { int[] mThemeAttrs; int mChangingConfigurations; int mChangingConfigurations; Paint mPaint; Paint mPaint; Shape mShape; Shape mShape; Loading @@ -508,6 +524,7 @@ public class ShapeDrawable extends Drawable { ShapeState(ShapeState orig) { ShapeState(ShapeState orig) { if (orig != null) { if (orig != null) { mThemeAttrs = orig.mThemeAttrs; mPaint = orig.mPaint; mPaint = orig.mPaint; mShape = orig.mShape; mShape = orig.mShape; mTint = orig.mTint; mTint = orig.mTint; Loading @@ -522,14 +539,24 @@ public class ShapeDrawable extends Drawable { } } } } @Override public boolean canApplyTheme() { return mThemeAttrs != null; } @Override @Override public Drawable newDrawable() { public Drawable newDrawable() { return new ShapeDrawable(this); return new ShapeDrawable(this, null, null); } } @Override @Override public Drawable newDrawable(Resources res) { public Drawable newDrawable(Resources res) { return new ShapeDrawable(this); return new ShapeDrawable(this, res, null); } @Override public Drawable newDrawable(Resources res, Theme theme) { return new ShapeDrawable(this, res, theme); } } @Override @Override Loading @@ -538,6 +565,17 @@ public class ShapeDrawable extends Drawable { } } } } private ShapeDrawable(ShapeState state, Resources res, Theme theme) { if (theme != null && state.canApplyTheme()) { mShapeState = new ShapeState(state); applyTheme(theme); } else { mShapeState = state; } mTintFilter = updateTintFilter(mTintFilter, mShapeState.mTint, mShapeState.mTintMode); } /** /** * Base class defines a factory object that is called each time the drawable * Base class defines a factory object that is called each time the drawable * is resized (has a new width or height). Its resize() method returns a * is resized (has a new width or height). Its resize() method returns a Loading