FileDocCategorySizeDatePackage
RoundRectDrawable.javaAPI DocAndroid 5.1 API4083Thu Mar 12 22:22:56 GMT 2015android.support.v7.widget

RoundRectDrawable

public class RoundRectDrawable extends android.graphics.drawable.Drawable
Very simple drawable that draws a rounded rectangle background with arbitrary corners and also reports proper outline for L.

Simpler and uses less resources compared to GradientDrawable or ShapeDrawable.

Fields Summary
private float
mRadius
private final android.graphics.Paint
mPaint
private final android.graphics.RectF
mBoundsF
private final android.graphics.Rect
mBoundsI
private float
mPadding
private boolean
mInsetForPadding
private boolean
mInsetForRadius
Constructors Summary
public RoundRectDrawable(int backgroundColor, float radius)


         
        mRadius = radius;
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mPaint.setColor(backgroundColor);
        mBoundsF = new RectF();
        mBoundsI = new Rect();
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas)

        canvas.drawRoundRect(mBoundsF, mRadius, mRadius, mPaint);
    
public intgetOpacity()

        return PixelFormat.TRANSLUCENT;
    
public voidgetOutline(android.graphics.Outline outline)

        outline.setRoundRect(mBoundsI, mRadius);
    
floatgetPadding()

        return mPadding;
    
public floatgetRadius()

        return mRadius;
    
protected voidonBoundsChange(android.graphics.Rect bounds)

        super.onBoundsChange(bounds);
        updateBounds(bounds);
    
public voidsetAlpha(int alpha)

        // not supported because older versions do not support
    
public voidsetColor(int color)

        mPaint.setColor(color);
        invalidateSelf();
    
public voidsetColorFilter(android.graphics.ColorFilter cf)

        // not supported because older versions do not support
    
voidsetPadding(float padding, boolean insetForPadding, boolean insetForRadius)

        if (padding == mPadding && mInsetForPadding == insetForPadding &&
                mInsetForRadius == insetForRadius) {
            return;
        }
        mPadding = padding;
        mInsetForPadding = insetForPadding;
        mInsetForRadius = insetForRadius;
        updateBounds(null);
        invalidateSelf();
    
voidsetRadius(float radius)

        if (radius == mRadius) {
            return;
        }
        mRadius = radius;
        updateBounds(null);
        invalidateSelf();
    
private voidupdateBounds(android.graphics.Rect bounds)

        if (bounds == null) {
            bounds = getBounds();
        }
        mBoundsF.set(bounds.left, bounds.top, bounds.right, bounds.bottom);
        mBoundsI.set(bounds);
        if (mInsetForPadding) {
            float vInset = calculateVerticalPadding(mPadding, mRadius, mInsetForRadius);
            float hInset = calculateHorizontalPadding(mPadding, mRadius, mInsetForRadius);
            mBoundsI.inset((int) Math.ceil(hInset), (int) Math.ceil(vInset));
            // to make sure they have same bounds.
            mBoundsF.set(mBoundsI);
        }