FileDocCategorySizeDatePackage
Region.javaAPI DocAndroid 5.1 API13855Thu Mar 12 22:22:30 GMT 2015android.graphics

Region

public class Region extends Object implements android.os.Parcelable

Fields Summary
private static final int
MAX_POOL_SIZE
private static final android.util.Pools.SynchronizedPool
sPool
public final long
mNativeRegion
public static final Parcelable.Creator
CREATOR
Constructors Summary
public Region()
Create an empty region

        this(nativeConstructor());
    
public Region(Region region)
Return a copy of the specified region

        this(nativeConstructor());
        nativeSetRegion(mNativeRegion, region.mNativeRegion);
    
public Region(Rect r)
Return a region set to the specified rectangle

        mNativeRegion = nativeConstructor();
        nativeSetRect(mNativeRegion, r.left, r.top, r.right, r.bottom);
    
public Region(int left, int top, int right, int bottom)
Return a region set to the specified rectangle

        mNativeRegion = nativeConstructor();
        nativeSetRect(mNativeRegion, left, top, right, bottom);
    
Region(long ni)

        if (ni == 0) {
            throw new RuntimeException();
        }
        mNativeRegion = ni;
    
private Region(long ni, int dummy)

        this(ni);
    
Methods Summary
public native booleancontains(int x, int y)
Return true if the region contains the specified point

public intdescribeContents()

    
       
        return 0;
    
public booleanequals(java.lang.Object obj)

        if (obj == null || !(obj instanceof Region)) {
            return false;
        }
        Region peer = (Region) obj;
        return nativeEquals(mNativeRegion, peer.mNativeRegion);
    
protected voidfinalize()

        try {
            nativeDestructor(mNativeRegion);
        } finally {
            super.finalize();
        }
    
public PathgetBoundaryPath()
Return the boundary of the region as a new Path. If the region is empty, the path will also be empty.

        Path path = new Path();
        nativeGetBoundaryPath(mNativeRegion, path.ni());
        return path;
    
public booleangetBoundaryPath(Path path)
Set the path to the boundary of the region. If the region is empty, the path will also be empty.

        return nativeGetBoundaryPath(mNativeRegion, path.ni());
    
public RectgetBounds()
Return a new Rect set to the bounds of the region. If the region is empty, the Rect will be set to [0, 0, 0, 0]

        Rect r = new Rect();
        nativeGetBounds(mNativeRegion, r);
        return r;
    
public booleangetBounds(Rect r)
Set the Rect to the bounds of the region. If the region is empty, the Rect will be set to [0, 0, 0, 0]

        if (r == null) {
            throw new NullPointerException();
        }
        return nativeGetBounds(mNativeRegion, r);
    
public native booleanisComplex()
Return true if the region contains more than one rectangle

public native booleanisEmpty()
Return true if this region is empty

public native booleanisRect()
Return true if the region contains a single rectangle

private static native longnativeConstructor()

private static native longnativeCreateFromParcel(android.os.Parcel p)

private static native voidnativeDestructor(long native_region)

private static native booleannativeEquals(long native_r1, long native_r2)

private static native booleannativeGetBoundaryPath(long native_region, long native_path)

private static native booleannativeGetBounds(long native_region, Rect rect)

private static native booleannativeOp(long native_dst, int left, int top, int right, int bottom, int op)

private static native booleannativeOp(long native_dst, Rect rect, long native_region, int op)

private static native booleannativeOp(long native_dst, long native_region1, long native_region2, int op)

private static native booleannativeSetPath(long native_dst, long native_path, long native_clip)

private static native booleannativeSetRect(long native_dst, int left, int top, int right, int bottom)

private static native voidnativeSetRegion(long native_dst, long native_src)

private static native java.lang.StringnativeToString(long native_region)

private static native booleannativeWriteToParcel(long native_region, android.os.Parcel p)

final longni()

        return mNativeRegion;
    
public static android.graphics.Regionobtain()

return
An instance from a pool if such or a new one.
hide

        Region region = sPool.acquire();
        return (region != null) ? region : new Region();
    
public static android.graphics.Regionobtain(android.graphics.Region other)

return
An instance from a pool if such or a new one.
param
other Region to copy values from for initialization.
hide

        Region region = obtain();
        region.set(other);
        return region;
    
public booleanop(Rect r, android.graphics.Region$Op op)
Perform the specified Op on this region and the specified rect. Return true if the result of the op is not empty.

        return nativeOp(mNativeRegion, r.left, r.top, r.right, r.bottom,
                        op.nativeInt);
    
public booleanop(int left, int top, int right, int bottom, android.graphics.Region$Op op)
Perform the specified Op on this region and the specified rect. Return true if the result of the op is not empty.

        return nativeOp(mNativeRegion, left, top, right, bottom,
                        op.nativeInt);
    
public booleanop(android.graphics.Region region, android.graphics.Region$Op op)
Perform the specified Op on this region and the specified region. Return true if the result of the op is not empty.

        return op(this, region, op);
    
public booleanop(Rect rect, android.graphics.Region region, android.graphics.Region$Op op)
Set this region to the result of performing the Op on the specified rect and region. Return true if the result is not empty.

        return nativeOp(mNativeRegion, rect, region.mNativeRegion,
                        op.nativeInt);
    
public booleanop(android.graphics.Region region1, android.graphics.Region region2, android.graphics.Region$Op op)
Set this region to the result of performing the Op on the specified regions. Return true if the result is not empty.

        return nativeOp(mNativeRegion, region1.mNativeRegion,
                        region2.mNativeRegion, op.nativeInt);
    
public booleanquickContains(Rect r)
Return true if the region is a single rectangle (not complex) and it contains the specified rectangle. Returning false is not a guarantee that the rectangle is not contained by this region, but return true is a guarantee that the rectangle is contained by this region.

        return quickContains(r.left, r.top, r.right, r.bottom);
    
public native booleanquickContains(int left, int top, int right, int bottom)
Return true if the region is a single rectangle (not complex) and it contains the specified rectangle. Returning false is not a guarantee that the rectangle is not contained by this region, but return true is a guarantee that the rectangle is contained by this region.

public booleanquickReject(Rect r)
Return true if the region is empty, or if the specified rectangle does not intersect the region. Returning false is not a guarantee that they intersect, but returning true is a guarantee that they do not.

        return quickReject(r.left, r.top, r.right, r.bottom);
    
public native booleanquickReject(int left, int top, int right, int bottom)
Return true if the region is empty, or if the specified rectangle does not intersect the region. Returning false is not a guarantee that they intersect, but returning true is a guarantee that they do not.

public native booleanquickReject(android.graphics.Region rgn)
Return true if the region is empty, or if the specified region does not intersect the region. Returning false is not a guarantee that they intersect, but returning true is a guarantee that they do not.

public voidrecycle()
Recycles an instance.

hide

        setEmpty();
        sPool.release(this);
    
public voidscale(float scale)
Scale the region by the given scale amount. This re-constructs new region by scaling the rects that this region consists of. New rectis are computed by scaling coordinates by float, then rounded by roundf() function to integers. This may results in less internal rects if 0 < scale < 1. Zero and Negative scale result in an empty region. If this region is empty, do nothing.

hide

        scale(scale, null);
    
public native voidscale(float scale, android.graphics.Region dst)
Set the dst region to the result of scaling this region by the given scale amount. If this region is empty, then dst will be set to empty.

hide

public booleanset(android.graphics.Region region)
Set the region to the specified region.

        nativeSetRegion(mNativeRegion, region.mNativeRegion);
        return true;
    
public booleanset(Rect r)
Set the region to the specified rectangle

        return nativeSetRect(mNativeRegion, r.left, r.top, r.right, r.bottom);
    
public booleanset(int left, int top, int right, int bottom)
Set the region to the specified rectangle

        return nativeSetRect(mNativeRegion, left, top, right, bottom);
    
public voidsetEmpty()
Set the region to the empty region

        nativeSetRect(mNativeRegion, 0, 0, 0, 0);
    
public booleansetPath(Path path, android.graphics.Region clip)
Set the region to the area described by the path and clip. Return true if the resulting region is non-empty. This produces a region that is identical to the pixels that would be drawn by the path (with no antialiasing).

        return nativeSetPath(mNativeRegion, path.ni(), clip.mNativeRegion);
    
public java.lang.StringtoString()

        return nativeToString(mNativeRegion);
    
public voidtranslate(int dx, int dy)
Translate the region by [dx, dy]. If the region is empty, do nothing.

        translate(dx, dy, null);
    
public native voidtranslate(int dx, int dy, android.graphics.Region dst)
Set the dst region to the result of translating this region by [dx, dy]. If this region is empty, then dst will be set to empty.

public final booleanunion(Rect r)

        return op(r, Op.UNION);
    
public voidwriteToParcel(android.os.Parcel p, int flags)
Write the region and its pixels to the parcel. The region can be rebuilt from the parcel by calling CREATOR.createFromParcel().

param
p Parcel object to write the region data into

        if (!nativeWriteToParcel(mNativeRegion, p)) {
            throw new RuntimeException();
        }