14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 11: Advanced Android <strong>Development</strong><br />

388<br />

PointF rollStringCenter = new PointF(center.x-rollStringWidth / 2,<br />

innerBoundingBox.top+1+textHeight);<br />

canvas.drawText(rollString,<br />

rollStringCenter.x, rollStringCenter.y,<br />

textPaint);<br />

}<br />

// Otherwise draw a marker line<br />

else {<br />

canvas.drawLine(center.x, (int)innerBoundingBox.top,<br />

center.x, (int)innerBoundingBox.top + 5,<br />

markerPaint);<br />

}<br />

canvas.rotate(10, center.x, center.y);<br />

}<br />

canvas.restore();<br />

16. The fi nal step in creating the face is drawing the heading markers around the outside edge.<br />

canvas.save();<br />

canvas.rotate(-1*(bearing), px, py);<br />

double increment = 22.5;<br />

for (double i = 0; i < 360; i += increment)<br />

{<br />

CompassDirection cd = CompassDirection.values()[(int)(i / 22.5)];<br />

String headString = cd.toString();<br />

float headStringWidth = textPaint.measureText(headString);<br />

PointF headStringCenter = new PointF(center.x - headStringWidth / 2,<br />

boundingBox.top + 1 + textHeight);<br />

if (i % increment == 0)<br />

canvas.drawText(headString,<br />

headStringCenter.x, headStringCenter.y,<br />

textPaint);<br />

else<br />

canvas.drawLine(center.x, (int)boundingBox.top,<br />

center.x, (int)boundingBox.top + 3,<br />

markerPaint);<br />

canvas.rotate((int)increment, center.x, center.y);<br />

}<br />

canvas.restore();<br />

17. With the face complete, you get to add some fi nishing touches.<br />

Start by adding a “glass dome” over the top to give the illusion of a watch face. Using the radial<br />

gradient array you constructed earlier, create a new Shader and Paint object. Use them to<br />

draw a circle over the inner face that makes it look like it’s covered in glass.<br />

RadialGradient glassShader = new RadialGradient(px, py,<br />

(int)innerRadius,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!