Code example for Canvas

Methods: clipPath, drawPath, drawRect, restore, save

0
     
    protected void draw(Canvas canvas) {
        if (mHidden)
            return; 
         
        canvas.save();
        mPath.reset();
        if (!hasFocus()) { 
            mOutlinePaint.setColor(0xFF000000);
            canvas.drawRect(mDrawRect, mOutlinePaint);
        } else { 
            mContext.getDrawingRect(mViewDrawingRect);
            if (mCircle) {
                float width  = mDrawRect.width()  - (getPaddingLeft() + getPaddingRight());
                float height = mDrawRect.height() - (getPaddingTop()  + getPaddingBottom());
                mPath.addCircle(
                        mDrawRect.left + getPaddingLeft() + (width  / 2), 
                        mDrawRect.top  + getPaddingTop()  + (height / 2),
                        width / 2, 
                        Path.Direction.CW);
                mOutlinePaint.setColor(0xFFEF04D6);
            } else { 
                mPath.addRect(new RectF(mDrawRect), Path.Direction.CW);
                mOutlinePaint.setColor(0xFFFF8A00);
            } 
            canvas.clipPath(mPath, Region.Op.DIFFERENCE);
            canvas.drawRect(mViewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
 
            canvas.restore();
            canvas.drawPath(mPath, mOutlinePaint);
 
            if (mMode == ModifyMode.Grow) {
                if (mCircle) {
                    int width  = mResizeDrawableDiagonal.getIntrinsicWidth();
                    int height = mResizeDrawableDiagonal.getIntrinsicHeight();