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 7: Maps, Geocoding, and Location-Based Services<br />

246<br />

}<br />

}<br />

}<br />

RectF oval = new RectF(myPoint.x-rad, myPoint.y-rad,<br />

myPoint.x+rad, myPoint.y+rad);<br />

canvas.drawOval(oval, paint);<br />

6. Return to the EarthquakeMap class. Within the onCreate method, create a Cursor that<br />

returns the earthquakes you want to display on the map. Use this Cursor to create a new<br />

EarthquakeOverlay before adding the new instance to the Map View’s list of overlays.<br />

Cursor earthquakeCursor;<br />

@Override<br />

public void onCreate(Bundle icicle) {<br />

super.onCreate(icicle);<br />

setContentView(R.layout.earthquake_map);<br />

String earthquakeURI = EarthquakeProvider.CONTENT_URI;<br />

earthquakeCursor = getContentResolver().query(earthquakeURI,<br />

null, null, null, null);<br />

}<br />

MapView earthquakeMap = (MapView)findViewById(R.id.map_view);<br />

EarthquakeOverlay eo = new EarthquakeOverlay(earthquakeCursor);<br />

earthquakeMap.getOverlays().add(eo);<br />

7. Finally, override onResume to call requery on the Earthquake result set whenever this Activity<br />

becomes visible. Also, override onPause and onDestroy to optimize use of the Cursor resources.<br />

@Override<br />

public void onResume() {<br />

earthquakeCursor.requery();<br />

super.onResume();<br />

}<br />

@Override<br />

public void onPause() {<br />

earthquakeCursor.deactivate();<br />

super.onPause();<br />

}<br />

@Override<br />

public void onDestroy() {<br />

earthquakeCursor.close();<br />

super.onDestroy();<br />

}<br />

8. If you run the application and select Earthquake Map from the main menu, your application<br />

should appear as shown in Figure 7-8.

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

Saved successfully!

Ooh no, something went wrong!