FileDocCategorySizeDatePackage
RoundRectShape.javaAPI DocAndroid 1.5 API4561Wed May 06 22:42:00 BST 2009android.graphics.drawable.shapes

RoundRectShape

public class RoundRectShape extends RectShape
Creates a rounded-corner rectangle. Optionally, an inset (rounded) rectangle can be included (to make a sort of "O" shape). The rounded rectangle can be drawn to a Canvas with its own draw() method, but more graphical control is available if you instead pass the RoundRectShape to a {@link android.graphics.drawable.ShapeDrawable}.

Fields Summary
private float[]
mOuterRadii
private android.graphics.RectF
mInset
private float[]
mInnerRadii
private android.graphics.RectF
mInnerRect
private android.graphics.Path
mPath
Constructors Summary
public RoundRectShape(float[] outerRadii, android.graphics.RectF inset, float[] innerRadii)
RoundRectShape constructor. Specifies an outer (round)rect and an optional inner (round)rect.

param
outerRadii An array of 8 radius values, for the outer roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners on the outer rectangle, pass null.
param
inset A RectF that specifies the distance from the inner rect to each side of the outer rect. For no inner, pass null.
param
innerRadii An array of 8 radius values, for the inner roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners on the inner rectangle, pass null. If inset parameter is null, this parameter is ignored.

        if (outerRadii.length < 8) {
            throw new ArrayIndexOutOfBoundsException(
                                        "outer radii must have >= 8 values");
        }
        if (innerRadii != null && innerRadii.length < 8) {
            throw new ArrayIndexOutOfBoundsException(
                                        "inner radii must have >= 8 values");
        }
        mOuterRadii = outerRadii;
        mInset = inset;
        mInnerRadii = innerRadii;
        
        if (inset != null) {
            mInnerRect = new RectF();
        }
        mPath = new Path();
    
Methods Summary
public android.graphics.drawable.shapes.RoundRectShapeclone()

        RoundRectShape shape = (RoundRectShape) super.clone();
        shape.mOuterRadii = mOuterRadii.clone();
        shape.mInnerRadii = mInnerRadii.clone();
        shape.mInset = new RectF(mInset);
        shape.mInnerRect = new RectF(mInnerRect);
        shape.mPath = new Path(mPath);
        return shape;
    
public voiddraw(android.graphics.Canvas canvas, android.graphics.Paint paint)

        canvas.drawPath(mPath, paint);
    
protected voidonResize(float w, float h)

        super.onResize(w, h);
        
        RectF r = rect();
        mPath.reset();

        if (mOuterRadii != null) {
            mPath.addRoundRect(r, mOuterRadii, Path.Direction.CW);
        } else {
            mPath.addRect(r, Path.Direction.CW);
        }
        if (mInnerRect != null) {
            mInnerRect.set(r.left + mInset.left, r.top + mInset.top,
                           r.right - mInset.right, r.bottom - mInset.bottom);
            if (mInnerRect.width() < w && mInnerRect.height() < h) {
                if (mInnerRadii != null) {
                    mPath.addRoundRect(mInnerRect, mInnerRadii,
                                       Path.Direction.CCW);
                } else {
                    mPath.addRect(mInnerRect, Path.Direction.CCW);
                }
            }
        }