FIT2081 Lecture 9: Week 9
SupportMapFragment.getMapAsync(onMapReadyCallback this);
Sets%a%callback%obj%which%will%be%triggered%when%GoogleMap instance%is%
ready%to%be%used
•
Specifies%which%object%listens%for%an%onMapReady event
•
onMapReady(GoogleMap googleMap)
Manipulates%the%map%once%ready%to%be%used
•
Activity%hosting%this%has%to%implement OnMapReadyCallback
=%an%interface
void onMapReady(GoogleMap var1);
○
•
GoogleMap
To%manipulate,%a%reference%needs%to%be%obtained%from%the%input%
parameter%of%onMapReady
○
onMapClick
Similar%to%onClick,%but%has%LatLng instead%of%View as%a%
param
§
○
LatLng
○
=%container%to%put%values%for%latitude%and%longitude
To%put%view%on%the%location
googleMap.moveCamera
□
(CameraUpdateFactory
.newLatLng(melbourne));
§
○
•
Geocoder
List<Address> addresses = new ArrayList<>();
•
addresses = geocoder.getFromLocation(point.latitude,
point.longitude, 1);
Converts%the%double%values%latitude%and%longitude%into%addresses
But%since%they%likely%not%accurate%enough%due%to%decimal%points,%
possible%to%end%up%with%multiple%cities
Output%is%an%array%of%addresses%instead%of%one%specific%loc
§
○
Have%to%retrieve% first%cell%of%list,%the%most%likely%country%the%user%is%
referring%to,%using%addresses.get(0)
○
•
android.location.Address
=%a%class%representing%an%Address
(i.e.%a%set%of%Strings%describing%a%loc)
Has%many%methods%including:
get/setCountryCode()
○
get/setCountryName()
○
get/setUrl()
○
toString()
○
•
JSON%
After%data%has%arrived%successfully,%need%to%open%a%stream%to%it%and%
get%a%reader
InputStream =%a%class%used%to%read%data%frm%Internet,%
keyboard,%file%etc
○
new InputStreamReader(responseBody, charsetName
"UTF-8")
○
•
Use%JsonReader to%decode%data•
=%a%parser%that%reads%data%and%passes%into%fields,%objs%and%arrays
beginArray(), endArray()
○
hasNext(), nextName(), nextString()
○
skipValue()
○
endObject()
○
WebView
Layout
•
webView.setWebViewClient(new WebViewClient());
Deals%with%common%browser-calling%problem%and%ensures%app%
doesn't%ask%browser%app%on%device%to%open
○
•
webView.loadUrl(BASE_URL + selectedCountryName);
•
[under%onOptionsItemSelected]
NavUtils.navigateUpFromSameTask(sourceActivity);
Use%switch-case%to%handle%menu%item%clicks%as%usual
"Home"%means%top%level% of%app's%UI
○
"Up"%means%up%one%level%in%the%UI
○
•
CountryInfo_Student
The%View in%the%Fragment for%the%Snackbar to%be%displayed%in%is%obtained.
If%there%is%at%least%1%address%return%earlier%in%the%array,%it%take%the%first%
String in%the%array%(the%most%likely%city%the%user%is%referring%to)%and%starts%
obtaining%info%from%the%server%for%that%city%to%display%on%the%Snackbar.%If%
there%are%no%addresses%returned,%nothing%is%displayed%in%the%Snackbar.
For$link$https://restcountries.eu/rest/v2/name/India,
At$the$top$and$first$level$of$nesting,$describe$the$structure$of$the$return$
JSON.
There%are%full%arrays%of%2%objects.
Describe$the$detailed$structure$of$the$value$of$the$"languages"$property$for$
India.
For%the%languages%property,%2%objects%in%an%array,%with%each%object%having%4%
properties.
AsyncTask<String, String, CountryInfo> (background%thread)
3%generic%types:
Type%of%params%sent%to%task%upon%execution
doInBackground input%typei.
1.
Type%of%progress%units%published%during%background%computation2.
Type%of%result%of%background%computation
doInBackground return%type%must%be%the%same%as%
onPostExecute input%type
i.
3.
•
The%class%extending%this%will%be%executed%anonymously
new ClassName.execute(param)
○
•
Callbacks:
String… params
○
=%an%array%of%Strings.
3%dots%because%we%can't%tell%how%many%elements%will%be%
inside%the%array
Only%be%specified%during%runtime□
§
doInBackground(String… params)
Runs%on%non-UI%thread,when%class%extending%it%is%called%to%
execute
§
Input%parameter%can%be%accessed%using%index%(square%
brackets%[])
§
○
onProgressUpdate(String… values)
Runs%on%UI%thread
§
Invoked%by%system
§
super.onProgressUpdate();
§
○
onPostExecute(final CountryInfo countryInfo)
Runs%on%UI%thread,%right%after%the%doInBackground%callback%
has%finished%executing
§
Updates%all%the%views%and%display%with%updated%container
§
Maybe%assign%listener%for%button
§
○
The%thread%is%removed%immediately%after%all%this%has%finished
○
•
Week$9
Tuesday,% 29%May%2018
11:05
Document Summary
Sets a callback obj which will be triggered when googlemap instance is ready to be used. Specifies which object listens for an onmapready event onmapready(googlemap googlemap) Manipulates the map once ready to be used. To manipulate, a reference needs to be obtained from the input parameter of onmapready onmapclick. Similar to onclick, but has latlng instead of view as a param. = container to put values for latitude and longitude. To put view on the location googlemap. movecamera (cameraupdatefactory. List addresses = new arraylist<>(); addresses = geocoder. getfromlocation(point. latitude, point. longitude, 1); Converts the double values latitude and longitude into addresses. But since they likely not accurate enough due to decimal points, possible to end up with multiple cities. Output is an array of addresses instead of one specific loc. Have to retrieve first cell of list, the most likely country the user is referring to, using addresses. get(0) android. location. address. = a class representing an address (i. e. a set of strings describing a loc)