Code example for Canvas

Methods: clipPath, drawPath, drawRect, restore, save

0
 
	protected void draw(Canvas canvas) {
		if (mHidden) {
			return; 
		} 
		canvas.save();
		Path path = new Path();
		if (!hasFocus()) { 
			mOutlinePaint.setColor(0xFF000000);
			canvas.drawRect(mDrawRect, mOutlinePaint);
		} else { 
			Rect viewDrawingRect = new Rect();
			mContext.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, hasFocus() ? mFocusPaint
					: mNoFocusPaint);
 
			canvas.restore();
			canvas.drawPath(path, mOutlinePaint);
 
			if (mMode == ModifyMode.Grow) {
				if (mCircle) {
					int width = mResizeDrawableDiagonal.getIntrinsicWidth();
					int height = mResizeDrawableDiagonal.getIntrinsicHeight();