Presentation is loading. Please wait.

Presentation is loading. Please wait.

Route Tracker App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

Similar presentations


Presentation on theme: "Route Tracker App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved."— Presentation transcript:

1 Route Tracker App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

2

3 The Route Tracker App Monitors user’s location and bearing (direction) Virtually displays a route on a map (in red with black dots every 10 GPS data points received by app) There is a Start Tracking ToggleButton The map shifts as the user moves, so user’s location is centered on screen Map is oriented so that route tracking line is pointed in direction the user is traveling and that direction points to top of the device Android emulator does not emulate bearing data (in text) User can choose Map or Satellite options Touching map displays Google Maps street map (the default) At Stop Tracking – displays a dialog with total distance travelled and average speed ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

4

5

6

7 Test Driving the App Import the App Obtain a Google Maps API Key ▫ For only testing and debugging apps  The ADT Plugin automatically handles getting a debug certificate  Get the fingerprint value of the SDK Debug certificate (instructions at code.google.com/android/maps-apis/mapkey.html)  Use the fingerprint value to get your Google Maps API key (produced at code.google.com/android/maps-api-signup.html)  Replace the value of the String resource named google_maps_api_key in the strings.xml file with the Google Maps API key. ▫ For creating apps for distribution  Need a fingerprint of your Signing certificate ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

8 Running and Test-driving App On an Android device ▫ Will need Internet access on device ▫ Ensure device is set up correctly for testing and debugging apps (see Before You Begin) ▫ In Eclipse….Select Run As > Android Application  Select your device in Android Device Chooser window  Install app and run it ▫ To acquire GPS signal, must have line-of-sight with the GPS satellite  Go outside  When device recieves GPS signal, you’ll see a Toast  Now you can start tracking ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

9 Running and Test-driving App In an AVD ▫ Edit Android AVD (can use NexxusS) ▫ In the Edit AVD window, select the Google APIs) – API level # from Target list (10 for 2.3.3) ▫ Click Edit AVD ▫ Select that AVD and start it ▫ Run the App, selecting the newly edited AVD ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

10 Sending GPS data to an AVD with GPX files No actual GPS signal Load and “play”.gpx files Can create these files with free app GPSLogger ▫ Produces files in GPX version 1.0 ▫ Convert them to GPX version 1.1 using a tool you can get online for the Android emulator ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

11 Sending GPS data to an AVD with GPX files cont. To send GPS data from.gpx file to an AVD ▫ Once app is running in AVD, in Eclipse select Window>Open Perspective>DDMS ▫ In Devices tab, select your AVD ▫ In Emulator Control tab, click the GPX tab ▫ Click the Load GPS …button, locate and select one of the files in the GPXFiles folder ▫ Click Open ▫ In bottom half of GPX tab, select the file just opened and click play button ▫ Now you can click StartTracking…StopTracking ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

12 Technologies Overview AndroidManifest.xml file ▫ To access non-standard library (ie Google Maps API) need element ▫ Want most of screen for displaying map, so need to specify android:theme with a theme with no title bar ▫ To access shared Android services, need uses- permission element  Services that change power settings, obtain location data, control sleep  When user install app, the OS will tell the user the app requires these services, and asks user to confirm granting them ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

13 Technologies Overview ToggleButton ▫ New widget! ▫ Maintains an on-off state ▫ Gray bar – off state, Green bar- on state ▫ Subclass of CompoundButton ▫ Implement interface CompoundButton.OnCheckedChangeListener ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

14 Technologies Overview MapActivity, MapView and Overlay Classes ▫ All in com.google.android.maps package ▫ MapActivity is a subclass of Activity that manages a MapCiew ▫ MapView  displays maps from GoogleMaps API  Supports gestures to zoom and pan map  Additional functionality must be added programmatically ▫ Overlay  To display data on a MapView, create a subclass of Overlay  Override Overlay’s Draw method  Use GeoPoints to translate GPS data into points to re-center map ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

15 Technologies Overview Location Data ▫ Package android.location contains classes and interfaces for acquiring and using location data ▫ Class LocationManager – provides access to device’s location services  Provides capabilities to choose best location provider based on app’s requirements specified in Criteria object  Criteria settings: accuracy, battery usage, bearing, speed, altitude, monetary cost of provider  Request updates from location provider and delivered to LocationListener as Location objects ▫ Location object  Latitude, longitude, time ( may have altitude and speed) ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

16 Technologies Overview PowerManager Class ▫ Comes from package android.os ▫ Use sparingly ▫ Here, want device to track even if screen is off ▫ Acquires a WakeLock to prevent device from sleeping Display Class ▫ Provide’s access to display’s screen dimensions – used to scale maps so they fill screen as we rotate them ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

17 Building the GUI and Resource Files Create new Android project called Route Tracker Change AndroidManifest.xml file ▫ uses-library ▫ android:theme ▫ uses-permission Delete and create a new main.xml file ▫ Use FrameLayout (stacks components, most recent on top) ▫ Add ToggleButton in bottom right ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

18 Can be done in tab of AndroidManifest Editor

19 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Requires Internet access to download map and satellite images Requires precise location data to show user’s route on the map To receive mock data for testing purposes – necessary only during development, not production

20 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

21 Building the App Three classes ▫ RouteTracker (MapActivity subclass)  The main Activity RouteTracker is created when you create the project, but you must change its superclass from Activity to MapActivity in the source code  Only one MapActivity per process is currently supported. ▫ BearingFrameLayout – must add this class ▫ RouteOverlay – must add this class ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

22 UML Class Diagram RouteTracker:MapActivity OnCreate OnStart onStop +updateLocation isRouteDiplayed onCreateOptionsMenu onOptionsItemSelected Anonymous:LocationListener onLocationChanged onProviderDisabled onStatusChanged Anonymous:GpsStatus.Listener onGpsStatusChanged onProviderDisabled onStatusChanged Anonymous:onCheckedChangeListener onCheckedChanged BearingFrameLayout:FrameLayout BearingFrameLayout +getChildLayouParams dispatchDraw +setBearing +getMapView RouteOverlay:Overlay RouteOverlay +addPoint +reset draw Note: Class is anonymous, the object won’t be

23 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

24

25 Actually, creating FrameLayout that will have a MapView instance variable

26 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Adds our routeOverlay to mapView’s collection of Overlays

27 Configuring Criteria object Criteria object represents the app’s requested features and settings for a location provider setAccuracy – Criteria.ACCURACY_FINE indicates the app requires precise GPS data (uses more power) ▫ ACCURACY_COURSE and for 2.3 -> ACCURACY_HIGH, ACCURACY_MEDIUM, ACCURACY_LOW setBearingRequired – true indicates the bearing is required / used to orient map setCostAllowed – true indicates it’s OK for app to use data services that might incur costs ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

28 Configuring Criteria object setPowerRequirement – location providers require different amounts of power, want least amount ▫ Criteria.POWER_LOW,.NO_REQUIREMENT, POWER_HIGH, POWER_MEDIUM setAltitudeRequired – false indicates this is not required ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

29 For last quiz – be able to list several SystemServices used by the author

30 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. ms and distance in meters between location updates For demo purposes only. Use larger values to conserve battery. Corresponding release method

31 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Here it is.

32 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. 1E6 converts it to microdegrees… …and then integers.

33 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Uses a smooth animation. Number of degrees to the east of true north.

34 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Anonymous inner class, instantiated object is locationListener.

35 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

36

37

38

39

40  then button was toggled to stop tracking.

41 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Otherwise it was toggled to start tracking.

42 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

43

44

45

46

47

48

49

50

51

52 Draw the tracked route on the MapView. Called with true first to draw its shadow layer (map markers, etc.), then called again with false to draw the overlay itself.

53 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

54

55 Wrap Up Know the new features used in the manifest file ▫ Uses-library, android:theme, uses-permission New widgit ToggleButton and its event handler CompoundButton.OnCheckedChangedListener MapActivity and MapView methods LocationManager provides access to device’s location services and chose best location provider based on settings in Criteria object Know the settings that can be changed in a Criteria object Know system services used in this textbook Be able to tell me what your two most favorite concepts were that you learned in this class ©1992-2013 by Pearson Education, Inc. All Rights Reserved.


Download ppt "Route Tracker App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved."

Similar presentations


Ads by Google