lecture 13 mobile programming n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 13 Mobile Programming PowerPoint Presentation
Download Presentation
Lecture 13 Mobile Programming

Loading in 2 Seconds...

play fullscreen
1 / 32

Lecture 13 Mobile Programming - PowerPoint PPT Presentation


  • 167 Views
  • Uploaded on

Lecture 13 Mobile Programming. Google Maps Android API. Agenda. Generating SHA1 Fingerprint Signing up for API Key (as developer) Permissions MapFragment and GoogleMap object Layers MyLocation. Google Maps API Key.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture 13 Mobile Programming' - arlais


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
lecture 13 mobile programming

Lecture 13

Mobile Programming

Google Maps Android API

agenda
Agenda
  • Generating SHA1 Fingerprint
  • Signing up for API Key (as developer)
  • Permissions
  • MapFragment and GoogleMap object
  • Layers
  • MyLocation
google maps api key
Google Maps API Key
  • In order to use the Google Maps API, you first need to obtain an API key and configure your app
  • GoogleMap API v1 is obsolete!!
  • Now, you better use GoogleMap API v2.
    • https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw
    • Please read page 863 – 970 in your textbook!
getting the sha1 fingerprint
Getting the SHA1 Fingerprint
  • To register for a Maps API Key, you need to provide an SHA1 fingerprint of the certificate that you will use to sign your application
  • Navigate to C:\Documents and Settings\<User>\.android
  • Run the following command

keytool -list –v –keystore debug.keystore -alias androiddebugkey -storepass android -keypass android

  • Copy the text that comes after Certificate fingerprint (SHA1):
  • Go Google API Consoleand sign up for the Android Maps API
  • Save the generated API key, you will use it in your app.
use support webfragment
Use (Support) WebFragment
  • In the layout file:
    • You need define a <fragment>
    • Give it an id, so you can access it in source code.
    • Class=“com.google.android.gms.maps.MapFragment” or SupportMapFragment depending on the version of your phone.
use support webfragment1
Use (Support) WebFragment
  • In the java file:
  • SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView)
  • GoogleMap map = mapGrag.getMap();
  • CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(x, y), where x and y are double/float.
  • map.moveCamera(center)
  • CameraUpdate zoom = CameraUpdateFactory.zoomTo(15).
  • map.animateCamera(zoom)
add marker or overlayitem
Add Marker or OverlayItem
  • Create Marker object
    • MarkerOptionsmo = new MarkerOptions().position(LatLng).title(“text”).snippet(“text”).draggable(true);
  • Add a marker to the map object.
    • Map.addMarker(mo);
customized info window
Customized Info Window
  • Create a new class that implements InfoWindowAdapter
  • Class PopupAdapter implements InfoWindowAdapter{

LayoutInflater inflater;

PopupAdapter(LayoutInflater inflater){

this.inflater = inflater;

}

@Override

public View getInfoContents(Marker marker){

}

customized info window1
Customized Info Window
  • @Override

public View getInfoContents(Marker marker){

View popup = inflater.inflate(R.layout.popup, null);

TextView tv = (TextView) popup.findViewById();

tv.setText(Marker.getTitle);

return popup;

}

@Override

Public View getInfoWindow(Marker marker){ return null;}

customized info window2
Customized Info Window
  • In java file:
    • map.setInfoWindowAdapter(new PopuoAdapter(getLayoutInflater()));
find my location
Find My Location
  • In java file:
    • map.setMyLocationEnabled(true);
    • You must call map.setOnMyLocationChangeListener(Listener)
    • The listener must override the method:
      • Public void onMyLocationChange(Location lastKnownLocation)
map listeners
Map Listeners
  • setOnCameraChangeListener(this)
    • implement OnCameraChangeListener
    • Override public void onCameraChange(CameraPosition position)
  • setMyLocationChangeListener(this):
    • implement OnMyLocationChangeListener
    • Override public void onMyLocationChange(Location lastKnownLocation)
  • If you set marker.draggable(true)
    • Implement OnMarkerDragListener
    • Override three methods:
      • onMarkerDrag(Marker maker)
      • onMarkerDragEnd(Marker marker)
      • onMarkerDragStart(Marker marker)
guesture
Guesture
  • The user can change zoom level either by + and - buttons or via “pinch-to zoom” gestures
  • The user can change the center of the map via simple swipe gestures
  • The user can change the camera tilt via two-finger vertical swipes, so instead of a traditional top-down perspective, the user can see things on an angle
  • The user can change the orientation of the map via a two-finger rotating swipe, to change the typical “north is to the top of the map” to some other orientation
control
Control
  • You can enable and disable those gestures by:
    • setRotateGesturesEnabled()
    • setScrollGesturesEnabled() (for panning the map)
    • setTiltGesturesEnabled()
    • setZoomControlsEnabled() (for the + and - buttons)
    • setZoomGesturesEnabled() (for pinch-to-zoom)
    • SetCompassEnable()
json values
JSON Values
  • "title" : "IT Business Analyst Intern"
  • "organization" : "Medtronic"
  • "city" : "Brooklyn Park"
json arrays
JSON Arrays

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

json objects
JSON Objects

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/10" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

parsing json
Parsing JSON

JSONObject json = new JSONObject(raw);

final String moviePlot = "" + json.getString("Plot");

mTextMoviePlot.post(new Runnable() {

@Override

public void run() {

mTextMoviePlot.setText(moviePlot);

}

});

parsing json1
Parsing JSON

JSONObject json = new JSONObject(raw);

final String moviePlot = "" + json.getString("Plot");

mTextMoviePlot.post(new Runnable() {

@Override

public void run() {

mTextMoviePlot.setText(moviePlot);

}

});

JSONObject is a set of name/value mappings, can represent a JSON document

parsing json2
Parsing JSON

JSONObject json = new JSONObject(raw);

final String moviePlot = "" + json.getString("Plot");

mTextMoviePlot.post(new Runnable() {

@Override

public void run() {

mTextMoviePlot.setText(moviePlot);

}

});

Retrieve the plot of the movie

parsing json3
Parsing JSON

Parsing JSON is not always this simple however, but it's usually straightforward once you understand JSON

A JSONObject may consist of more JSONObjects, JSONArrays, Strings, Booleans, Integers, etc

parsing json4
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

parsing json5
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

This is a JSONObject

parsing json6
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

You can get title by calling getString("title") on the JSONObject

parsing json7
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

You can get organization by calling getString("organization") on the JSONObject

parsing json8
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

Etcetera, etcetera ...

parsing json9
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

This however, is not a String, but an array. Get this by calling getJSONArray() on the JSONObject

parsing json10
Parsing JSON

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

After which you can use the getters on the JSONArray to get the desired data

parsing json11
Parsing JSON

How would you represent this data using XML?

{

"title" : "IT Business Analyst Intern" ,

"organization" : "Medtronic" ,

"city" : "Brooklyn Park" ,

"state" : "MN" ,

"start_date" : "05/10" ,

"end_date" : "07/11" ,

"details" : [ "bla bla bla" , "drank some soda" , "hit manager in face with pie"]

}

parsing json12
Parsing JSON

See HttpGetJsonExample.tar

facebook api
FACEBOOK API

See FacebookApiExample.tar

See FacebookHello.tar

references
References
  • The Busy Coder's Guide to Android Development - Mark Murphy
  • Android Developers
  • The Mobile Lab at Florida State University