Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Notes

654 views

Published on

  • Be the first to comment

  • Be the first to like this

Notes

  1. 1. Comp194-MA
  2. 2. Introduction <ul><li>Android includes a rich widget toolkit. </li></ul><ul><li>Cool ones: a Google Map, MediaPlayer, Photo Gallery, ect </li></ul><ul><li>The best way to figure out the widgets is to experiment with them. </li></ul><ul><li>These slides will walk through the GeoFlickr app. </li></ul>
  3. 3. GeoFlickr <ul><li>GeoFlickr retrieves the user’s current GPS coordinates and pulls flickr photos around that location. </li></ul><ul><li>The app uses Android’s Gallery widget to display the retrieved photos. </li></ul><ul><li>It also uses Android threads and handlers so the UI doesn’t freeze </li></ul>
  4. 4. Screenshots Home screen Loading Screen
  5. 5. Screenshots Photos outside MFA “ onclick” behavior
  6. 6. Juicy bits <ul><li>GeoFlickr uses Android threads as well as the LocationManager service to determine GPS coordinates. </li></ul><ul><li>We’ll walk through how to set up LocationManager and throw out some snippets for threading. </li></ul>
  7. 7. Location, Location, Location <ul><li>Location based services are some of the most exciting applications of mobile apps. </li></ul><ul><li>The Android SDK exposes it’s GPS service through the LocationManager service. </li></ul><ul><li>Applications can either poll the service for updates or opt to receive updates when the device moves by a certain amount. </li></ul>
  8. 8. Setup <ul><li>Before an application can access location service it needs to set up permissions in the AndroidManifest file. </li></ul><ul><li>The Eclipse plugin provides a GUI to add the appropriate XML tags to the file. </li></ul><ul><li>Open “AndroidManifest.xml” and select the “Permissions” tab on the bottom. </li></ul>
  9. 9. Setup contd. <ul><li>Add the following as “Uses Permission” </li></ul><ul><li>android.permission.ACCESS_MOCK_LOCATION </li></ul><ul><li>android.permission.ACCESS_COARSE_LOCATION </li></ul><ul><li>android.permission.ACCESS_FINE_LOCATION </li></ul><ul><li>If you want to use sockets add: android.permission.INTERNET </li></ul>
  10. 10. Setting up DDMS <ul><li>Since the emulator doesn’t have a physical GPS, the DDMS console allows developer’s to send fake GPS coordinates to the emulator. </li></ul><ul><li>To bring up DDMS in Eclipse: Window->Open Perspective->Other->DDMS </li></ul><ul><li>To enable LogCat logging in Eclipse: Window->Preferences->Android->DDMS and change the log level to info. </li></ul>
  11. 11. DDMS Send GPS coords Logging System info
  12. 12. LocationManager code <ul><li>Register for location updates: </li></ul><ul><li>LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); </li></ul><ul><li>flickrLocationReciever flReciever = new flickrLocationReciever(); </li></ul><ul><li>locationManager. requestLocationUpdates( locationManager.getProviders( true).get(0), 5, 10, flReciever); </li></ul><ul><li>public class flickrLocationReciever implements LocationListener { </li></ul><ul><li> @Override </li></ul><ul><li>public void onLocationChanged(final Location arg0) { </li></ul><ul><li>// do things </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  13. 13. Gallery Adapters <ul><li>Android’s gallery widget accepts an adapter object to facilitate rendering. </li></ul><ul><li>Adapter’s are flexible because they allow developer’s to respond to gallery events in a particular fashion. </li></ul><ul><li>They also allow developer’s to change how gallery items will render. </li></ul>
  14. 14. Gallery Code <ul><li>ImageAdapter ia = new ImageAdapter(this); </li></ul><ul><li>Gallery ga = ((Gallery) findViewById(R.id. imageGallery)); </li></ul><ul><li>ga.setAdapter(ia); </li></ul><ul><li>public class ImageAdapter extends BaseAdapter { </li></ul><ul><ul><li>// override all the methods and do stuff </li></ul></ul><ul><li>} </li></ul>
  15. 15. Threading <ul><li>Using threads for background tasks is important because it allows the UI to remain responsive. </li></ul><ul><li>Android implements threads using the standard Java threading model. </li></ul><ul><li>Events are raised using the “Message” class and handled using the “Handler” class. </li></ul>
  16. 16. Threading code <ul><li>Thread t = new Thread() { </li></ul><ul><li>public void run(){ </li></ul><ul><li>// do stuff </li></ul><ul><li>// let the handler know we are done </li></ul><ul><li>handler.sendEmptyMessage(1); </li></ul><ul><li>}} </li></ul><ul><li>T.start(); </li></ul><ul><li>private Handler handler = new Handler(){ </li></ul><ul><li>public void handleMessage(Message msg) { </li></ul><ul><li>// handle the end of the thread </li></ul><ul><li>}} </li></ul>
  17. 17. Playing With Google Maps <ul><li>Android has a built in widget for the maps called MapView </li></ul><ul><li>MapView requires an API key which is based off something called “keystore”. </li></ul><ul><li>Since we are running in Debug environment we can use the debug.keystore that android creates us in ~/.andriod/debug.keystore usually </li></ul>
  18. 18. Getting your Maps API Key <ul><li>First get your md5 finger print </li></ul><ul><ul><li>daum@daum ~/.android $ keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android androiddebugkey, Jan 26, 2009, PrivateKeyEntry, Certificate fingerprint (MD5): B8:F5:D9:31:8D:19:C6:13:86:7F:4F:B3:A4:C9:A2:CC </li></ul></ul><ul><li>Take the B8…….CC to http://code.google.com/android/maps-api-signup.html and get your API key </li></ul><ul><li>When you implement the MapView widget add android:apiKey=“YOUR KEY” to the widget </li></ul>
  19. 19. Maps Require the Internet <ul><li>GoogleMaps requires that you have access to the internet so your application needs permission to use the internet </li></ul><ul><li>Add the permission as a child under “manifest” in AndriodManifest.xml </li></ul><ul><ul><li><uses-permission android:name=“android.permission.INTERNET” /> </li></ul></ul><ul><li>Now you should be able to simply load the map </li></ul>
  20. 20. Map Troubleshooting <ul><li>If you see the Map but none of the actual tiles are loading on the map there are two possible problems </li></ul><ul><ul><li>You do not have the correct API key, make sure you are using your debug one (or your production one if you are publishing the app) </li></ul></ul><ul><ul><li>Your application does not have access to the Internet </li></ul></ul><ul><li>If you check both of the above problems, you most likely will end with a map that works </li></ul>
  21. 21. A map with no tools is no Map at all <ul><li>Now we have a map, but we cannot click on it, zoom in or out on it. To make it clickable you can in the MapView widget in the xml add </li></ul><ul><ul><li>android:clickable=“true” </li></ul></ul><ul><li>Now you can click but we still cannot zoom. There is a zoom widget called ZoomControl! </li></ul><ul><ul><li>Get the ZoomControl from the MapView </li></ul></ul><ul><ul><ul><li>Mapview.getZoomControls() </li></ul></ul></ul><ul><ul><li>Add it to the a linear layout at the bottom of the map to make them visible </li></ul></ul><ul><ul><ul><li>linearLayout.addView(Mapview.getZoomControls() </li></ul></ul></ul><ul><ul><li>Now we have a function map! </li></ul></ul>

×