FileDocCategorySizeDatePackage
Outline.javaAPI DocAndroid 5.1 API6649Thu Mar 12 22:22:30 GMT 2015android.graphics

Outline

public final class Outline extends Object
Defines a simple shape, used for bounding graphical regions.

Can be computed for a View, or computed by a Drawable, to drive the shape of shadows cast by a View, or to clip the contents of the View.

see
android.view.ViewOutlineProvider
see
android.view.View#setOutlineProvider(android.view.ViewOutlineProvider)
see
Drawable#getOutline(Outline)

Fields Summary
public Path
mPath
public Rect
mRect
public float
mRadius
public float
mAlpha
Constructors Summary
public Outline()
Constructs an empty Outline. Call one of the setter methods to make the outline valid for use with a View.

public Outline(Outline src)
Constructs an Outline with a copy of the data in src.

        set(src);
    
Methods Summary
public booleancanClip()
Returns whether the outline can be used to clip a View.

Currently, only Outlines that can be represented as a rectangle, circle, or round rect support clipping.

see
{@link android.view.View#setClipToOutline(boolean)}

        return !isEmpty() && mRect != null;
    
public floatgetAlpha()
Returns the alpha represented by the Outline.

        return mAlpha;
    
public booleanisEmpty()
Returns whether the Outline is empty.

Outlines are empty when constructed, or if {@link #setEmpty()} is called, until a setter method is called

see
#setEmpty()

        return mRect == null && mPath == null;
    
public voidoffset(int dx, int dy)
Offsets the Outline by (dx,dy)

        if (mRect != null) {
            mRect.offset(dx, dy);
        } else if (mPath != null) {
            mPath.offset(dx, dy);
        }
    
public voidset(android.graphics.Outline src)
Replace the contents of this Outline with the contents of src.

param
src Source outline to copy from.

        if (src.mPath != null) {
            if (mPath == null) {
                mPath = new Path();
            }
            mPath.set(src.mPath);
            mRect = null;
        }
        if (src.mRect != null) {
            if (mRect == null) {
                mRect = new Rect();
            }
            mRect.set(src.mRect);
        }
        mRadius = src.mRadius;
        mAlpha = src.mAlpha;
    
public voidsetAlpha(float alpha)
Sets the alpha represented by the Outline - the degree to which the producer is guaranteed to be opaque over the Outline's shape.

An alpha value of 0.0f either represents completely transparent content, or content that isn't guaranteed to fill the shape it publishes.

Content producing a fully opaque (alpha = 1.0f) outline is assumed by the drawing system to fully cover content beneath it, meaning content beneath may be optimized away.

        mAlpha = alpha;
    
public voidsetConvexPath(Path convexPath)
Sets the Constructs an Outline from a {@link android.graphics.Path#isConvex() convex path}.

        if (convexPath.isEmpty()) {
            setEmpty();
            return;
        }

        if (!convexPath.isConvex()) {
            throw new IllegalArgumentException("path must be convex");
        }
        if (mPath == null) mPath = new Path();

        mPath.set(convexPath);
        mRect = null;
        mRadius = -1.0f;
    
public voidsetEmpty()
Sets the outline to be empty.

see
#isEmpty()

        mPath = null;
        mRect = null;
        mRadius = 0;
    
public voidsetOval(int left, int top, int right, int bottom)
Sets the outline to the oval defined by input rect.

        if (left >= right || top >= bottom) {
            setEmpty();
            return;
        }

        if ((bottom - top) == (right - left)) {
            // represent circle as round rect, for efficiency, and to enable clipping
            setRoundRect(left, top, right, bottom, (bottom - top) / 2.0f);
            return;
        }

        if (mPath == null) mPath = new Path();
        mPath.reset();
        mPath.addOval(left, top, right, bottom, Path.Direction.CW);
        mRect = null;
    
public voidsetOval(Rect rect)
Convenience for {@link #setOval(int, int, int, int)}

        setOval(rect.left, rect.top, rect.right, rect.bottom);
    
public voidsetRect(Rect rect)
Convenience for {@link #setRect(int, int, int, int)}

        setRect(rect.left, rect.top, rect.right, rect.bottom);
    
public voidsetRect(int left, int top, int right, int bottom)
Sets the Outline to the rounded rect defined by the input rect, and corner radius.

        setRoundRect(left, top, right, bottom, 0.0f);
    
public voidsetRoundRect(int left, int top, int right, int bottom, float radius)
Sets the Outline to the rounded rect defined by the input rect, and corner radius.

Passing a zero radius is equivalent to calling {@link #setRect(int, int, int, int)}

        if (left >= right || top >= bottom) {
            setEmpty();
            return;
        }

        if (mRect == null) mRect = new Rect();
        mRect.set(left, top, right, bottom);
        mRadius = radius;
        mPath = null;
    
public voidsetRoundRect(Rect rect, float radius)
Convenience for {@link #setRoundRect(int, int, int, int, float)}

        setRoundRect(rect.left, rect.top, rect.right, rect.bottom, radius);