Code example for Canvas

Methods: clipPathdrawPathdrawRectrestoresave

0
    @Override 
	public void draw(Canvas canvas) {
        if (mHidden) {
            return; 
        } 
        canvas.save();
        Path path = new Path();
        Rect viewDrawingRect = new Rect();
        getDrawingRect(viewDrawingRect);
        if (mCircle) {
            float width  = mDrawRect.width();
            float height = mDrawRect.height();
            path.addCircle(mDrawRect.left + (width  / 2),
                           mDrawRect.top + (height / 2),
                           width / 2,
                           Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);
        } else { 
            path.addRect(new RectF(mDrawRect), Path.Direction.CW);
            mOutlinePaint.setColor(0xFFFF8A00);
        } 
        canvas.clipPath(path, Region.Op.DIFFERENCE);
        canvas.drawRect(viewDrawingRect,mNoFocusPaint);
        if(mCollision){
            canvas.clipPath(path, Region.Op.REVERSE_DIFFERENCE);
            canvas.drawRect(viewDrawingRect,mFocusPaint);
        } 
 
        canvas.restore();
        canvas.drawPath(path, mOutlinePaint);
 
        if (mCircle) {
            int width  = mResizeDrawableDiagonal.getIntrinsicWidth();
            int height = mResizeDrawableDiagonal.getIntrinsicHeight();
 
Experience pair programming with AI  Get Codota for Java