Methods Summary |
---|
public void | applyTheme(android.content.res.Resources.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();
// Update local properties.
initializeWithState(state, t.getResources());
|
public void | clearMutated()
super.clearMutated();
mMutated = false;
|
public void | draw(android.graphics.Canvas canvas)
final Rect r = getBounds();
final ShapeState state = mShapeState;
final Paint paint = state.mPaint;
final int prevAlpha = paint.getAlpha();
paint.setAlpha(modulateAlpha(prevAlpha, state.mAlpha));
// only draw shape if it may affect output
if (paint.getAlpha() != 0 || paint.getXfermode() != null || paint.hasShadowLayer()) {
final boolean clearColorFilter;
if (mTintFilter != null && paint.getColorFilter() == null) {
paint.setColorFilter(mTintFilter);
clearColorFilter = true;
} else {
clearColorFilter = false;
}
if (state.mShape != null) {
// need the save both for the translate, and for the (unknown)
// Shape
final int count = canvas.save();
canvas.translate(r.left, r.top);
onDraw(state.mShape, canvas, paint);
canvas.restoreToCount(count);
} else {
canvas.drawRect(r, paint);
}
if (clearColorFilter) {
paint.setColorFilter(null);
}
}
// restore
paint.setAlpha(prevAlpha);
|
public int | getAlpha()
return mShapeState.mAlpha;
|
public int | getChangingConfigurations()
return super.getChangingConfigurations()
| mShapeState.mChangingConfigurations;
|
public ConstantState | getConstantState()
mShapeState.mChangingConfigurations = getChangingConfigurations();
return mShapeState;
|
public int | getIntrinsicHeight()
return mShapeState.mIntrinsicHeight;
|
public int | getIntrinsicWidth()
return mShapeState.mIntrinsicWidth;
|
public int | getOpacity()
if (mShapeState.mShape == null) {
final Paint p = mShapeState.mPaint;
if (p.getXfermode() == null) {
final int alpha = p.getAlpha();
if (alpha == 0) {
return PixelFormat.TRANSPARENT;
}
if (alpha == 255) {
return PixelFormat.OPAQUE;
}
}
}
// not sure, so be safe
return PixelFormat.TRANSLUCENT;
|
public void | getOutline(android.graphics.Outline outline)
if (mShapeState.mShape != null) {
mShapeState.mShape.getOutline(outline);
outline.setAlpha(getAlpha() / 255.0f);
}
|
public boolean | getPadding(android.graphics.Rect padding)
if (mShapeState.mPadding != null) {
padding.set(mShapeState.mPadding);
return true;
} else {
return super.getPadding(padding);
}
|
public android.graphics.Paint | getPaint()Returns the Paint used to draw the shape.
return mShapeState.mPaint;
|
public android.graphics.drawable.ShapeDrawable$ShaderFactory | getShaderFactory()Returns the ShaderFactory used by this ShapeDrawable for requesting a
{@link android.graphics.Shader}.
return mShapeState.mShaderFactory;
|
public android.graphics.drawable.shapes.Shape | getShape()Returns the Shape of this ShapeDrawable.
return mShapeState.mShape;
|
public void | inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)
super.inflate(r, parser, attrs, theme);
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.ShapeDrawable);
updateStateFromTypedArray(a);
a.recycle();
int type;
final int outerDepth = parser.getDepth();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
final String name = parser.getName();
// call our subclass
if (!inflateTag(name, r, parser, attrs)) {
android.util.Log.w("drawable", "Unknown element: " + name +
" for ShapeDrawable " + this);
}
}
// Update local properties.
initializeWithState(mShapeState, r);
|
protected boolean | inflateTag(java.lang.String name, android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)Subclasses override this to parse custom subelements. If you handle it,
return true, else return super.inflateTag(...).
if ("padding".equals(name)) {
TypedArray a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.ShapeDrawablePadding);
setPadding(
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_left, 0),
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_top, 0),
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_right, 0),
a.getDimensionPixelOffset(
com.android.internal.R.styleable.ShapeDrawablePadding_bottom, 0));
a.recycle();
return true;
}
return false;
|
private void | initializeWithState(android.graphics.drawable.ShapeDrawable$ShapeState state, android.content.res.Resources res)Initializes local dynamic properties from state. This should be called
after significant state changes, e.g. from the One True Constructor and
after inflating or applying a theme.
mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
|
public boolean | isStateful()
final ShapeState s = mShapeState;
return super.isStateful() || (s.mTint != null && s.mTint.isStateful());
|
private static int | modulateAlpha(int paintAlpha, int alpha)
int scale = alpha + (alpha >>> 7); // convert to 0..256
return paintAlpha * scale >>> 8;
|
public Drawable | mutate()
if (!mMutated && super.mutate() == this) {
if (mShapeState.mPaint != null) {
mShapeState.mPaint = new Paint(mShapeState.mPaint);
} else {
mShapeState.mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
}
if (mShapeState.mPadding != null) {
mShapeState.mPadding = new Rect(mShapeState.mPadding);
} else {
mShapeState.mPadding = new Rect();
}
try {
mShapeState.mShape = mShapeState.mShape.clone();
} catch (CloneNotSupportedException e) {
return null;
}
mMutated = true;
}
return this;
|
protected void | onBoundsChange(android.graphics.Rect bounds)
super.onBoundsChange(bounds);
updateShape();
|
protected void | onDraw(android.graphics.drawable.shapes.Shape shape, android.graphics.Canvas canvas, android.graphics.Paint paint)Called from the drawable's draw() method after the canvas has been set to
draw the shape at (0,0). Subclasses can override for special effects such
as multiple layers, stroking, etc.
shape.draw(canvas, paint);
|
protected boolean | onStateChange(int[] stateSet)
final ShapeState state = mShapeState;
if (state.mTint != null && state.mTintMode != null) {
mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
return true;
}
return false;
|
public void | setAlpha(int alpha)Set the alpha level for this drawable [0..255]. Note that this drawable
also has a color in its paint, which has an alpha as well. These two
values are automatically combined during drawing. Thus if the color's
alpha is 75% (i.e. 192) and the drawable's alpha is 50% (i.e. 128), then
the combined alpha that will be used during drawing will be 37.5% (i.e.
96).
mShapeState.mAlpha = alpha;
invalidateSelf();
|
public void | setColorFilter(android.graphics.ColorFilter cf)
mShapeState.mPaint.setColorFilter(cf);
invalidateSelf();
|
public void | setDither(boolean dither)
mShapeState.mPaint.setDither(dither);
invalidateSelf();
|
public void | setIntrinsicHeight(int height)Sets the intrinsic (default) height for this shape.
mShapeState.mIntrinsicHeight = height;
invalidateSelf();
|
public void | setIntrinsicWidth(int width)Sets the intrinsic (default) width for this shape.
mShapeState.mIntrinsicWidth = width;
invalidateSelf();
|
public void | setPadding(int left, int top, int right, int bottom)Sets padding for the shape.
if ((left | top | right | bottom) == 0) {
mShapeState.mPadding = null;
} else {
if (mShapeState.mPadding == null) {
mShapeState.mPadding = new Rect();
}
mShapeState.mPadding.set(left, top, right, bottom);
}
invalidateSelf();
|
public void | setPadding(android.graphics.Rect padding)Sets padding for this shape, defined by a Rect object. Define the padding
in the Rect object as: left, top, right, bottom.
if (padding == null) {
mShapeState.mPadding = null;
} else {
if (mShapeState.mPadding == null) {
mShapeState.mPadding = new Rect();
}
mShapeState.mPadding.set(padding);
}
invalidateSelf();
|
public void | setShaderFactory(android.graphics.drawable.ShapeDrawable$ShaderFactory fact)Sets a ShaderFactory to which requests for a
{@link android.graphics.Shader} object will be made.
mShapeState.mShaderFactory = fact;
|
public void | setShape(android.graphics.drawable.shapes.Shape s)Sets the Shape of this ShapeDrawable.
mShapeState.mShape = s;
updateShape();
|
public void | setTintList(android.content.res.ColorStateList tint)
mShapeState.mTint = tint;
mTintFilter = updateTintFilter(mTintFilter, tint, mShapeState.mTintMode);
invalidateSelf();
|
public void | setTintMode(android.graphics.PorterDuff.Mode tintMode)
mShapeState.mTintMode = tintMode;
mTintFilter = updateTintFilter(mTintFilter, mShapeState.mTint, tintMode);
invalidateSelf();
|
private void | updateShape()
if (mShapeState.mShape != null) {
final Rect r = getBounds();
final int w = r.width();
final int h = r.height();
mShapeState.mShape.resize(w, h);
if (mShapeState.mShaderFactory != null) {
mShapeState.mPaint.setShader(mShapeState.mShaderFactory.resize(w, h));
}
}
invalidateSelf();
|
private void | updateStateFromTypedArray(android.content.res.TypedArray a)
final ShapeState state = mShapeState;
final Paint paint = state.mPaint;
// Account for any configuration changes.
state.mChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
state.mThemeAttrs = a.extractThemeAttrs();
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));
final int tintMode = a.getInt(R.styleable.ShapeDrawable_tintMode, -1);
if (tintMode != -1) {
state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN);
}
final ColorStateList tint = a.getColorStateList(R.styleable.ShapeDrawable_tint);
if (tint != null) {
state.mTint = tint;
}
|