Code example for ShapeDrawable

Methods: setImageDrawable, getPaint, setIntrinsicHeight, setIntrinsicWidth

0
	 * @param h	The height in pixels 
	 * @param w	The width in pixels 
	 * @return 
	 */ 
	public ShapeDrawable drawOval(int c, int h, int w) {
		ShapeDrawable oval = new ShapeDrawable(new OvalShape());
		oval.setIntrinsicHeight(h);
		oval.setIntrinsicWidth(w);
		oval.getPaint().setColor(c);
		return oval;	
	} 
 
	public OnClickListener circleClick = new OnClickListener() {
		public void onClick(View v) { 
			selectedColor = v.getId(); 
			ImageView selected = (ImageView)v; 
			int id = selectedColor; // I use the id variable for readability. I didn't find "selectedColor + 1" to be very clear. 
			selected.setImageDrawable(drawOval(colors[id], hundredPixels, hundredPixels)); // This creates the "selected" color 
 
			// Return all "unselected" colors are their original size 
			for(int i = id + 1; i < colorArray.length; i++){ 
				colorArray[i].setImageDrawable(drawOval(colors[i], fortyPixels, fortyPixels)); 
			} 
 
			if(id > 0){ 
				for(int i = id -1; i > 0; i--){ 
					colorArray[i].setImageDrawable(drawOval(colors[i], fortyPixels, fortyPixels)); 
				} 
				colorArray[0].setImageDrawable(drawOval(colors[0], fortyPixels, fortyPixels)); 
			} 
 
		} 
	}; 
 
	public OnClickListener pegListener = new OnClickListener() {
		public void onClick(View v) { 
			int id = v.getId(); 
			ImageView selected = (ImageView)v; 
			selected.setImageDrawable(drawOval(colors[selectedColor], fortyPixels, fortyPixels)); // Replace the selected circle with a circle of the selected color 
			selected.setTag(selectedColor); // set the color tag for pattern comparison 
		} 
	}; 
 
	public OnClickListener checkButtonListener = new OnClickListener() {