Code example for Canvas

Methods: drawBitmap, drawOval, drawRect, restore, save, translate

0
		 * @param markerPosX 
		 * @param markerPosY 
		 */ 
		private void mark2DPalette(Canvas canvas, int markerPosX, int markerPosY) {
			mPosMarker.setColor(Color.BLACK);
			canvas.drawOval(new RectF(markerPosX - 5, markerPosY - 5, markerPosX + 5, markerPosY + 5), mPosMarker);
			mPosMarker.setColor(Color.WHITE);
			canvas.drawOval(new RectF(markerPosX - 3, markerPosY - 3, markerPosX + 3, markerPosY + 3), mPosMarker);
		} 
 
		/** 
		 * Draw a line across the slider to indicate its current value. 
		 * @param canvas 
		 * @param markerPos 
		 */ 
		private void markVerSlider(Canvas canvas, int markerPos) {
			mPosMarker.setColor(Color.BLACK);
			canvas.drawRect(new Rect(0, markerPos - 2, SLIDER_THICKNESS, markerPos + 3), mPosMarker);
			mPosMarker.setColor(Color.WHITE);
			canvas.drawRect(new Rect(0, markerPos, SLIDER_THICKNESS, markerPos + 1), mPosMarker);
		} 
 
		/** 
		 * Frame the slider to indicate that it has trackball focus. 
		 * @param canvas 
		 */ 
		private void hilightFocusedVerSlider(Canvas canvas) {
			mPosMarker.setColor(Color.WHITE);
			canvas.drawRect(new Rect(0, 0, SLIDER_THICKNESS, PALETTE_DIM), mPosMarker);
			mPosMarker.setColor(Color.BLACK);
			canvas.drawRect(new Rect(2, 2, SLIDER_THICKNESS - 2, PALETTE_DIM - 2), mPosMarker);
		} 
 
		/** 
		 * Frame the 2D palette to indicate that it has trackball focus. 
		 * @param canvas 
		 */ 
		private void hilightFocusedOvalPalette(Canvas canvas) {
			mPosMarker.setColor(Color.WHITE);
			canvas.drawOval(new RectF(-PALETTE_RADIUS, -PALETTE_RADIUS, PALETTE_RADIUS, PALETTE_RADIUS), mPosMarker);
			mPosMarker.setColor(Color.BLACK);
			canvas.drawOval(new RectF(-PALETTE_RADIUS + 2, -PALETTE_RADIUS + 2, PALETTE_RADIUS - 2, PALETTE_RADIUS - 2), mPosMarker);
		} 
 
		//NEW_METHOD_WORK_NEEDED_HERE 
		//To add a new method, replicate the basic draw functions here.  Use the 2D palette or 1D sliders as templates for the new method. 
		/** 
		 * Draw the UI for HSV with angular H and radial S combined in 2D and a 1D V slider. 
		 * @param canvas 
		 */ 
		private void drawHSV1Palette(Canvas canvas) {
			canvas.save();
 
			canvas.translate(PALETTE_POS_X, PALETTE_POS_Y);
 
			//Draw the 2D palette 
			canvas.translate(PALETTE_CENTER_X, PALETTE_CENTER_Y);
			canvas.drawOval(new RectF(-PALETTE_RADIUS, -PALETTE_RADIUS, PALETTE_RADIUS, PALETTE_RADIUS), mOvalHueSat);
			canvas.drawOval(new RectF(-PALETTE_RADIUS, -PALETTE_RADIUS, PALETTE_RADIUS, PALETTE_RADIUS), mValDimmer);
			if (mFocusedControl == 0)
				hilightFocusedOvalPalette(canvas);
			mark2DPalette(canvas, mCoord[0], mCoord[1]);
			canvas.translate(-PALETTE_CENTER_X, -PALETTE_CENTER_Y);
 
			//Draw the 1D slider 
			canvas.translate(PALETTE_DIM, 0);
			canvas.drawBitmap(mVerSliderBM, 0, 0, null);
			if (mFocusedControl == 1)
				hilightFocusedVerSlider(canvas);
			markVerSlider(canvas, mCoord[2]);
 
			canvas.restore();
		} 
 
		/** 
		 * Initialize the current color chooser's UI (set its color parameters and set its palette and slider values accordingly). 
		 */