Code example for Path

Methods: addOvalreset

0
     * @param width The width of the bounding rectangle 
     * @param height The height of the bounding rectangle 
     */ 
    public OvalShape(float x, float y, float width, float height) {
        mOval = new RectF(x, y, x + width, y + height);
        mPath = new Path();
        update(); 
    } 
 
    /** 
     * Creates new oval shape from specified double location and double size. 
     * @param x The x-coordinates of the bounding rectangle 
     * @param y The x-coordinates of the bounding rectangle 
     * @param width The width of the bounding rectangle 
     * @param height The height of the bounding rectangle 
     */ 
    public OvalShape(double x, double y, double width, double height) {
        mOval = new RectF((float)x, (float)y, (float)(x + width), (float)(y + height));
        mPath = new Path();
        update(); 
    } 
 
    /** 
     * Creates a new oval shape copying from specified oval shape 
     * @param ovalShape The specified oval shape 
     */ 
    public OvalShape(OvalShape ovalShape) {
        this(ovalShape.getX(), ovalShape.getY(), ovalShape.getWidth(), ovalShape.getHeight());
        this.mPath = ovalShape.mPath;
        this.mRegion = ovalShape.mRegion;
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public Path getPath() {
        Path path = new Path();
        path.addOval(mOval, Direction.CW);
        return path;
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void draw(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawOval(mOval, paint);
    } 
 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void fill(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.FILL);
        canvas.drawOval(mOval, paint);
    } 
 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void fillAndStroke(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawOval(mOval, paint);
    } 
 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void clip(Canvas canvas) {
        canvas.clipPath(mPath);
    } 
 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean contains(RectShape rect) {
        if (this.mRegion.contains((int)rect.getMinX(), (int)rect.getMinY()) &&
                this.mRegion.contains((int)rect.getMinX(), (int)(rect.getMaxY())) &&
                this.mRegion.contains((int)(rect.getMaxX()), (int)rect.getMinY()) &&
                this.mRegion.contains((int)(rect.getMaxX()), (int)(rect.getMaxY())) 
                ) { 
            return true; 
        } 
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean contains(float x, float y) {
        return mRegion.contains((int)x, (int)y);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean contains(float x, float y, float width, float height) {
        if (this.mRegion.contains((int)x, (int)y) &&
                this.mRegion.contains((int)x, (int)(y + height)) &&
                this.mRegion.contains((int)(x + width), (int)y) &&
                this.mRegion.contains((int)(x + width), (int)(y + height)) 
                ) { 
            return true; 
        } 
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean contains(PointF point) {
        return mRegion.contains((int)point.x, (int)point.y);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    @Deprecated 
    public RectShape getBounds() {
        return new RectShape(mRegion.getBounds());
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void getBounds(RectShape rect) {
        rect.setRect(mRegion.getBounds());
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(float x, float y, float width, float height) {
        Region region = new Region(mRegion);
        float tmpx, tmpy, tmpw, tmph;
 
        if (x < width + x) {
            tmpx = x;
            tmpw = width;
        } 
        else{ 
            tmpx = width + x;
            tmpw = Math.abs(width); 
        } 
        if (y < height + y) {
            tmpy = y;
            tmph = height;
        } 
        else{ 
            tmpy = height + y;
            tmph = Math.abs(height); 
        } 
        return region.op((int)tmpx, (int)tmpy, (int)(tmpx + tmpw), (int)(tmpy + tmph), Op.INTERSECT);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(Rect rect) {
        return intersects(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(RectShape rect) {
        return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public void translate(float x, float y) {
        this.mOval.left += x;
        this.mOval.top += y;
        this.mOval.right += x;
        this.mOval.bottom += y;
        update(); 
    } 
    /** 
     * Returns x-coordinate of bounds upper-left corner. 
     * @return The x-coordinate of bounds upper-left corner 
     */ 
    public float getX() { 
        return mOval.left;
    } 
 
    /** 
     * Returns y-coordinate of bounds upper-left corner. 
     * @return The y-coordinate of bounds upper-left corner 
     */ 
    public float getY() { 
        return mOval.top;
    } 
 
    /** 
     * Returns width of bounds. 
     * @return The width of bounds. 
     */ 
    public float getWidth() { 
        return mOval.width();
    } 
 
    /** 
     * Returns height of bounds. 
     * @return The height of bounds. 
     */ 
    public float getHeight() { 
        return mOval.height();
    } 
     
    /** 
     * Returns minimum x-coordinate of oval. 
     * @return minimum x-coordinate of oval 
     */ 
    public float getMinX() { 
        return getX(); 
    } 
     
    /** 
     * Returns maximum x-coordinate of oval. 
     * @return maximum x-coordinate of oval 
     */ 
    public float getMaxX() { 
        return mOval.right;
    } 
     
    /** 
     * Returns center x-coordinate of oval. 
     * @return center x-coordinate of oval 
     */ 
    public float getCenterX() { 
        return mOval.centerX();
    } 
     
    /** 
     * Returns minimum y-coordinate of oval. 
     * @return minimum y-coordinate of oval 
     */ 
    public float getMinY() { 
    	return getY(); 
    } 
     
    /** 
     * Returns maximum y-coordinate of oval. 
     * @return maximum y-coordinate of oval 
     */ 
    public float getMaxY() { 
        return mOval.bottom;
    } 
     
    /** 
     * Returns center y-coordinate of oval. 
     * @return center y-coordinate of oval 
     */ 
    public float getCenterY() { 
        return mOval.centerY();
    } 
     
    /** 
     * Updates the internal data required to draw. 
     */ 
    private void update() { 
        mPath.reset();
        mPath.addOval(mOval, Direction.CW);
        mRegion = new Region((int)mOval.left, (int)mOval.top, (int) mOval.right, (int) mOval.bottom);
        mRegion.setPath(mPath, mRegion);
    }