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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Paint glassPaint = new Paint();<br />

glassPaint.setShader(glassShader);<br />

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

canvas.drawOval(innerBoundingBox, glassPaint);<br />

glassGradientColors,<br />

glassGradientPositions,<br />

TileMode.CLAMP);<br />

18. All that’s left is to draw two more circles as clean borders for the inner and outer face boundaries.<br />

Then restore the canvas to upright, and fi nish the onDraw method.<br />

// Draw the outer ring<br />

canvas.drawOval(boundingBox, circlePaint);<br />

}<br />

// Draw the inner ring<br />

circlePaint.setStrokeWidth(2);<br />

canvas.drawOval(innerBoundingBox, circlePaint);<br />

canvas.restore();<br />

Bringing Map Overlays to Life<br />

In Chapter 7, you learned how to use Overlays to add annotation layers to MapViews. The Canvas used<br />

for annotating MapView Overlays is the same class as the one used to draw new View controls. As a<br />

result, all of the advanced features described so far in this section can be used to enhance map Overlays.<br />

That means you can use any of the draw methods, transparency, Shaders, Color Masks, and Filter<br />

Effects to create rich Overlays using the Android graphics framework.<br />

Interacting with Overlays<br />

Touch-screen interaction in MapViews is handled individually by each of its Overlays. To handle map<br />

taps within an Overlay, override the onTap event.<br />

The following code snippet shows an onTap implementation that receives the map coordinates of the<br />

tap and the MapView on which the tap occurred:<br />

@Override<br />

public boolean onTap(GeoPoint point, MapView map) {<br />

// Get the projection to convert to and from screen coordinates<br />

Projection projection = map.getProjection();<br />

}<br />

// Return true if we handled this onTap()<br />

return [ … hit test passed … ];<br />

The MapView can be used to obtain the Projection of the map when it was tapped. Used in conjunction<br />

with the GeoPoint parameter, you can determine the position on screen of the real-world longitude<br />

and latitude pressed.<br />

389

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

Saved successfully!

Ooh no, something went wrong!