Code example for Canvas

Methods: drawArc, drawLine, drawRect, restore, rotate, save, translate

0
	protected void onDraw(final Canvas canvas) {
 
		// All of our positions are using our internal coordinate system. 
		// Instead of translating 
		// them we let Canvas do the work for us. 
		canvas.translate(mTranslationOffsetX, mTranslationOffsetY);
 
		final float progressRotation = getCurrentRotation();
 
		// draw the background 
		if (!mOverrdraw) {
			canvas.drawArc(mCircleBounds, 270, -(360 - progressRotation), false, mBackgroundColorPaint);
		} 
 
		// draw the progress or a full circle if overdraw is true 
		canvas.drawArc(mCircleBounds, 270, mOverrdraw ? 360 : progressRotation, false, mProgressColorPaint);
 
		// draw the marker at the correct rotated position 
		if (mIsMarkerEnabled) {
			final float markerRotation = getMarkerRotation();
 
			canvas.save();
			canvas.rotate(markerRotation - 90);
			canvas.drawLine((float) (mThumbPosX + mThumbRadius / 2 * 1.4), mThumbPosY,
					(float) (mThumbPosX - mThumbRadius / 2 * 1.4), mThumbPosY, mMarkerColorPaint);
			canvas.restore();
		} 
 
		// draw the thumb square at the correct rotated position 
		canvas.save();
		canvas.rotate(progressRotation - 90);
		// rotate the square by 45 degrees 
		canvas.rotate(45, mThumbPosX, mThumbPosY);
		final RectF rect = new RectF();
		rect.left = mThumbPosX - mThumbRadius / 3;
		rect.right = mThumbPosX + mThumbRadius / 3;
		rect.top = mThumbPosY - mThumbRadius / 3;
		rect.bottom = mThumbPosY + mThumbRadius / 3;
		canvas.drawRect(rect, mThumbColorPaint);
		canvas.restore();
	} 
 
	/* (non-Javadoc) 
	 * @see android.view.View#onMeasure(int, int) 
	 */