Code example for Canvas

Methods: drawArc, drawCircle, getClipBounds, restore, save, translate

0
	 * @param time in milliseconds 
	 * @param max the original time set in milliseconds 
	 */ 
	public void updateImage(Canvas canvas, int time, int max) {
	 
		canvas.save();
		 
		float p = (max == 0) ? 0 : (time/(float)max);
		int [] timeVec = TimerUtils.time2Mhs(time);
		if(mLastTime == null) mLastTime = timeVec;
		if(mLastTime[2] != timeVec[2]) mMsFlipper = !mMsFlipper;
		 
		float pSecond = (max == 0) ? 1 : (timeVec[2] + timeVec[3]/1000.0f )/60.0f; 		
		float thetaSecond = pSecond*360;
		 
		 
		if(mWidth != canvas.getClipBounds().width() || mHeight != canvas.getClipBounds().height())
			sizeChange(canvas.getClipBounds().width(),canvas.getClipBounds().height());
	 
		canvas.translate(mWidth/2.0f, mHeight/2.0f);
		 
		mSecondRect.set(-mSecondRadius, -mSecondRadius, mSecondRadius, mSecondRadius);
		mArcRect.set(-mRadius, -mRadius, mRadius, mRadius);
			 
		// Ms Arc 
		if(showMs){
			float pMs = (float)((timeVec[3]/1000.00));
			float thetaMs = pMs*360;
 
			mMsRect.set(-mMsRadius, -mMsRadius, mMsRadius, mMsRadius);		
			canvas.drawCircle(0,0,mMsRadius, (mMsFlipper) ? mCirclePaint : mMsPaint );
			canvas.drawArc(mMsRect, START_ANGLE, thetaMs, true, (mMsFlipper) ? mMsPaint: mCirclePaint);
		} 
		// We want to draw a very thin border 
		else{ 
			canvas.drawCircle(0,0,mMsRadius, mMsPaint );
		} 
	 
		// Gap between the ms and seconds 
		canvas.drawCircle(0,0,mMsGap,mInnerPaint);
				 
		//Second arc 
		canvas.drawCircle(0,0,mSecondRadius,mSecondBgPaint);
		canvas.drawArc(mSecondRect, START_ANGLE, thetaSecond, true, mSecondPaint);
		 
		// Gap between the seconds and the inner radius 
		canvas.drawCircle(0,0,mSecondGap,mInnerPaint);
		 
		// Background fill 
		canvas.drawCircle(0,0,mRadius,mCirclePaint);
		 
		// Main arc 
		canvas.drawArc(mArcRect,START_ANGLE,360*(1-p),true,mArcPaint);
		 
		// Inner paint 
		canvas.drawCircle(0,0,mInnerRadius,mInnerPaint);
		 
		mLastTime = timeVec;
		 
		canvas.restore();
	} 
}