Code example for Path

Methods: addRoundRectreset

0
     */ 
    public RoundRectShape(float x, float y, float width, float height, float rx, float ry) {
        this.mRect = new RectF(x, y, x + width, y + height);
        this.mRX = rx;
        this.mRY = ry;
        mPath = new Path();
        update(); 
    } 
     
    /** 
     * Creates new RoundRectShape shape, copying from specified rounded corner rectangle. 
     * @param rect The specified rounded corner rectangle 
     */ 
    public RoundRectShape(RoundRectShape rect) {
        this(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), rect.getRx(), rect.getRy());
         
        mPath = new Path(rect.mPath);
        mRegion = new Region(rect.mRegion);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public Path getPath() {
        return mPath;
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public void draw(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(mPath, paint);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public void fill(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.FILL);
        canvas.drawPath(mPath, paint);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public void fillAndStroke(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawPath(mPath, paint);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public void clip(Canvas canvas) {
        canvas.clipPath(mPath);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public boolean contains(RectShape rect) {
        return contains(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    } 
 
    /** 
     * {@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() {
        RectF rect = new RectF();
        mPath.computeBounds(rect, false);
        return new RectShape(rect);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    public void getBounds(RectShape rect) {
        mPath.computeBounds(this.rectBuffer, false);
        rect.setRectF(this.rectBuffer);
    } 
     
    /** 
     * {@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.mRect.left += x;
        this.mRect.top += y;
        this.mRect.right += x;
        this.mRect.bottom += y;
    } 
 
    /** 
     * Returns this x-coordinate of rounded corner rectangle bound. 
     * @return this x-coordinate of rounded corner rectangle bound 
     */ 
    public float getX() { 
        return mRect.left;
    } 
 
    /** 
     * Returns this x-coordinate. 
     * @return this x-coordinate 
     */ 
    public void setX(float x) {
        this.mRect.left = x;
    } 
 
    /** 
     * Returns this y-coordinate of rounded corner rectangle bound. 
     * @return this y-coordinate of rounded corner rectangle bound 
     */ 
    public float getY() { 
        return mRect.top;
    } 
 
    /** 
     * Returns this y-coordinate. 
     * @return this y-coordinate 
     */ 
    public void setY(float y) {
        this.mRect.top = y;
    } 
 
    /** 
     * Returns this width. 
     * @return this width 
     */ 
    public float getWidth() { 
        return mRect.width();
    } 
 
    /** 
     * Returns this width. 
     * @return this width 
     */ 
    public void setWidth(float width) {
        this.mRect.right = getMinX() + width;
    } 
 
    /** 
     * Returns this height. 
     * @return this height 
     */ 
    public float getHeight() { 
        return mRect.height();
    } 
 
    /** 
     * Returns this height. 
     * @return this height 
     */ 
    public void setHeight(float height) {
        this.mRect.bottom = getMinY() + height;
    } 
     
    /** 
     * Return x-radius of the rounded corners. 
     */ 
    public float getRx() { 
        return mRX;
    } 
 
 
    /** 
     * Sets x-radius of the rounded corners. 
     * @param ry The x-radius of the rounded corners 
     */ 
    public void setRx(float rx) {
        this.mRX = rx;
    } 
 
    /** 
     * Return y-radius of the rounded corners. 
     * @return The y-radius of the rounded corners 
     */ 
    public float getRy() { 
        return mRY;
    } 
 
    /** 
     * Sets y-radius of the rounded corners. 
     * @param ry The y-radius of the rounded corners 
     */ 
    public void setRy(float ry) {
        this.mRY = ry;
    } 
 
    /** 
     * Returns minimum x-coordinate of this rounded corner rectangle. 
     * @return minimum x-coordinate of this rounded corner rectangle 
     */ 
    public float getMinX() { 
        return getX(); 
    } 
     
    /** 
     * Returns maximum x-coordinate of this rounded corner rectangle. 
     * @return maximum x-coordinate of this rounded corner rectangle 
     */ 
    public float getMaxX() { 
        return mRect.right;
    } 
     
    /** 
     * Returns center x-coordinate of this rounded corner rectangle. 
     * @return center x-coordinate of this rounded corner rectangle 
     */ 
    public float getCenterX() { 
        return mRect.centerX();
    } 
     
    /** 
     * Returns maximum y-coordinate of this rounded corner rectangle. 
     * @return maximum y-coordinate of this rounded corner rectangle 
     */ 
    public float getMinY() { 
        return getY(); 
    } 
     
    /** 
     * Returns maximum y-coordinate of this rounded corner rectangle. 
     * @return maximum y-coordinate of this rounded corner rectangle 
     */ 
    public float getMaxY() { 
        return mRect.bottom;
    } 
     
    /** 
     * Returns center y-coordinate of this rounded corner rectangle. 
     * @return center y-coordinate of this rounded corner rectangle 
     */ 
    public float getCenterY() { 
        return mRect.centerY();
    } 
     
    /** 
     * Updates the internal data required to draw. 
     */ 
    private void update() { 
        mPath.reset();
        mPath.addRoundRect(mRect, mRX, mRY, Direction.CW);
        mRegion = new Region((int)getMinX(), (int)getMinY(), (int) getMaxX(), (int) getMaxY());
        mRegion.setPath(mPath, mRegion);
    } 
 
    /** 
Stop searching for code, let great code find you!  Add Codota to your java IDE