CS 442: Assignment 4 – Know Your Government solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Uses: Location Services, Internet, Google APIs, Images, Picasso Library, Implicit Intents, TextView Links
App Highlights:
• This app will acquire and display an interactive list of political officials that represent the current location (or
a specified location) at each level of government.
• Android location services will be used to determine the user’s location.
• The Google Civic Information API will be used to acquire the government official data (via REST service and
JSON results).
• You will need to use a different layout for landscape orientation for 2 of the activities in this application.
Those details are specified later in the document.
• Clicking on an official’s list entry opens a detailed view of that individual government representative.
• Clicking on the photo of an official will display a Photo Activity, showing a larger version of the photo.
• An “About” activity will show application information (Author, Copyright data & Version)
• Your manifest should add permissions for ACCESS_FINE_LOCATION and INTERNET
• The application is made up of 4 activities, shown below:
1) Main Activity
RecyclerView list of government
officials (List scrolls up & down)
Display of current location (or
user-specified location)
Options Menu items for “about”
information and manual location
entry
Click on a government official’s
entry to open a new activity
containing detailed information
on the selected individual.
No separate landscape layout is
needed for the Main Activity.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 2 of 16
Photo of official (where available). NOTE, a default image should
be displayed when a photo is not specified (see below, middle)
Placeholder image should be displayed while photo is loading
(see below right)
Clicking on the photo opens Photo Detail Activity
Social Media (only
display data that is
provided).
All are clickable –
implicit intents.
Possible data items:
– Facebook
– Twitter
– Google+
– YouTube
Party logo for Democratic
& Republican. Otherwise,
no logo
2) Official Activity
Contact Information
(only display data that
is provided). All are
clickable – implicit
intents. Possible data
items:
– Office Address
– Phone Number
– Email address
– Website
The background color
of this activity is
based upon the
official’s political
party:
Republican = RED,
Democratic = BLUE,
Otherwise use BLACK
A ScrollView must be used here in case the
information does not completely fit on the visible
screen.
Basic official data
-Office
(i.e., U.S. Senator)
-Name
(i.e., Tammy Duckworth)
-Party
(i.e., Democratic)
Scrolls
Down
Display of
current location
(or user-specified
location w/city,
state only)
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 3 of 16
3) Photo Detail Activity
“Full-sized” image of official (where
available).
NOTE: This activity should not open if the
representative’s image is not specified.
Basic official data
1) Office (i.e., U.S. Senator)
2) Name (i.e., Richard J. Durbin)
The background color of
this activity is based upon
the official’s political
party:
Republican = RED,
Democratic = BLUE,
Otherwise use BLACK
Party logo for Democratic
& Republican. Otherwise,
no logo
Display of
current location
(or user-specified
location w/city,
state only)
Placeholder while image is
downloading
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 4 of 16
Required Landscape Layouts
App Title
API Attribution (clickable link to
https://developers.google.com/civicinformation/)
Full-sized background image
Application information (Author, Copyright
data & Version)
No separate landscape layout is needed
for the About Activity.
Photo Activity
Scrolls
Official Activity Down
4) About Activity
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 5 of 16
Internet Data:
Downloading data for the government officials requires a download via the Google Civic Information API. The
Civic Information API lets you enter a zip code or city/state name to look up the data properties for the elected
officials in those districts.
NOTE: You MUST sign up with Google to get an API key. Your API KEY must be supplied with all Google Civic
Information API queries. You can get a free API key by following the instructions at:
https://developers.google.com/civic-information/docs/using_api
Follow the instructions for “Acquiring and using an API key”. The type of credential you need to create is “API
Key” (not “OAuth client ID” and not “Service account key”). This is a very quick and easy process. The API key
will be a long string of characters. The results of Civic Information API calls are returned in JSON format. The
content of the returned results is described later in this section.
Query Format: https://www.googleapis.com/civicinfo/v2/representatives?key=Your-API-Key&address=zip-code
https://www.googleapis.com/civicinfo/v2/representatives?key=Your-API-Key&address=city
For example, if your API Key was “ABC123xyz” and the zip code was 60605, your full URL would be:
https://www.googleapis.com/civicinfo/v2/representatives?key=ABC123xyz&address=60605
For example, if your API Key was “ABC123xyz” and the city was Chicago, your full URL would be:
https://www.googleapis.com/civicinfo/v2/representatives?key=ABC123xyz&address=Chicago
Google Civic Information API Results Example:
The JSON Object results you receive contains 4 sections, described in detail below. The normalizedInput
section contains location details for the results provided. The divisions section lists political geographic
divisions, like a country, state, county, or legislative district (we do not need this section for our application).
The offices section lists the political positions governing the specified location. The officials section lists
people presently serving in the offices specified in the offices section.
High-level view of JSON Object results:
{
“normalizedInput”: {  We need this section, it is accessed as a JSONObject (described later)
…  Data will be here
},
“kind”: “civicinfo#representativeInfoResponse”,  We do not need this
“divisions”: {  We do not need this
…  Data will be here, we do not need this section
},
“offices”: [  We need this section, it is accessed as a JSONArray (described later)
…  Data will be here
],
“officials”: [  We need this section, it is accessed as a JSONArray (described later)
…  Data will be here
]
}
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 6 of 16
JSON Section Details (omitting those sections we will not use):
1) The “normalizedInput” JSONObject contains the following:
“normalizedInput”: {
“line1”: “”,
“city”: “Chicago”,  We want this for the location display in our activities
“state”: “IL”,  We want this for the location display in our activities
“zip”: “60654”  We want this for the location display in our activities
},
2) The “offices” JSONArray contains the following:
“offices”: [
{
“name”: “President of the United States”,
“divisionId”: “ocd-division/country:us”,
“levels”: [
“country”
],
“roles”: [
“headOfState”,
“headOfGovernment”
],
“officialIndices”: [
0
]
},

{
“name”: “United States Senate”,
“divisionId”: “ocd-division/country:us/state:il”,
“levels”: [
“country”
],
“roles”: [
“legislatorUpperBody”
],
“officialIndices”: [
2,
3
]
},
…  The above sections repeat many times, once per government office
],
We want this, the “office” title
We want this, it is the index into the “officials” JSONArray (see
the next section) which contains the details of the person that
holds this office.
NOTE: There can be more than one index as time offices have
multiple representatives.
We want this, the “office” title
We want this, it is the index into the “officials” JSONArray (see
the next section) which contains the details of the person that
holds this office.
NOTE: There can be more than one index as time offices have
multiple representatives.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 7 of 16
3) The “officials” JSONArray contains the following:
“officials”: [
{
“name”: “Donald J. Trump”,
“address”: [
{
“line1”: “The White House”,
“line2”: “1600 Pennsylvania Avenue NW”,
“city”: “Washington”,
“state”: “DC”,
“zip”: “20500”
}
],
“party”: “Republican”,
“phones”: [
“(202) 456-1111”
],
“urls”: [
“http://www.whitehouse.gov/”
],
“emails”: [
“email@address.com”
]
“photoUrl”: “https://www.whitehouse.gov/sites/whitehouse.gov/files/images/45/PE%20Color.jpg”,
“channels”: [
{
“type”: “GooglePlus”,
“id”: “+whitehouse”
},
{
“type”: “Facebook”,
“id”: “whitehouse”
},
{
“type”: “Twitter”,
“id”: “whitehouse”
},
{
“type”: “YouTube”,
“id”: “whitehouse”
}
]
},
{
…  The above section repeats many times, once per government official. Remember – the first
official in the JSONArray is index 0. The second official in this JSONArray is index 1, the third
second official in this JSONArray is index 2, and so on.
}
]
This is the first JSONObject is the first official (index 0). This index
corresponds to the “officialIndices” we found in the “offices”
section earlier.
This is the name of the person that holds this office.
This is the Address (check for possible line1, line2 & line3 –
concatenate them into one String), City, State & Zip Code of this
person’s office
This is the political party of this person: “Republican”,
“Democratic/Democrat”, or “Unknown”. Note this section might
also be omitted – consider that as party “Unknown”.
This person’s office phone number. There may be more than one
– just use the first entry. Note this section might also be
omitted.
This person’s office web site. There may be more than one – just
use the first entry. Note this section might also be omitted.
This person’s office email address. There may be more than one
– use only the first entry. Note this section might also be
omitted.
This is the URL to the person’s photo. Note this section might also be
omitted. In this case, use a “place holder” photo.
These are the user ids for the related social media channels. There will
be up to four entries. Possible entries are:
• GooglePlus  Ignore this one, Google+ has been deprecated
• Facebook
• Twitter
• YouTube
Some or all of these 4 social channel items might be omitted.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 8 of 16
Using Picasso for Photo Downloads
Downloading the photos of the officials in the Official Activity and the Photo Activity must use the Picasso library (as
was discussed in class). Note that you can turn on the Picasso logging if necessary, to get info on what the Picasso
library is doing by adding he following to your code once you have created the Picasso object:
picasso.setLoggingEnabled(true);
Social Media Implicit Intent Examples
The following are examples of how you should code the social-media implicit intents (some of these have been seen
already in class examples, but are reproduced here for convenience):
Twitter (example onClick method to be associated with the Twitter ImageView icon):
public void twitterClicked(View v) {
Intent intent = null;
String name = ;
try {
// get the Twitter app if possible
getPackageManager().getPackageInfo(“com.twitter.android”, 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“twitter://user?screen_name=” + name));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“https://twitter.com/” + name));
}
startActivity(intent);
}
Facebook (example onClick method to be associated with the Facebook ImageView icon):
public void facebookClicked(View v) {
String FACEBOOK_URL = “https://www.facebook.com/” + ;
String urlToUse;
PackageManager packageManager = getPackageManager();
try {
int versionCode = packageManager.getPackageInfo(“com.facebook.katana”, 0).versionCode;
if (versionCode >= 3002850) { //newer versions of fb app
urlToUse = “fb://facewebmodal/f?href=” + FACEBOOK_URL;
} else { //older versions of fb app
urlToUse = “fb://page/” + channels.get(“Facebook”);
}
} catch (PackageManager.NameNotFoundException e) {
urlToUse = FACEBOOK_URL; //normal web url
}
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
facebookIntent.setData(Uri.parse(urlToUse));
startActivity(facebookIntent);
}
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 9 of 16
YouTube (example onClick method to be associated with the YouTube ImageView icon):
public void youTubeClicked(View v) {
String name = ;
Intent intent = null;
try {
intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(“com.google.android.youtube”);
intent.setData(Uri.parse(“https://www.youtube.com/” + name));
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(“https://www.youtube.com/” + name)));
}
}
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 10 of 16
Provided Icons
To insure a consistent and professional appearance of our application, the following image files are being provided to
you for use in this assignment. You can simply download them, add them to your Android Studio project, and use
them with your ImageViews.
About Activity Background
Default Official Image
Bad photo URL image
Placeholder Image
Separator Image (to add to the
end of your list entry layout)
Facebook icon
Twitter icon
YouTube icon
Launcher Icon
Democratic Party Logo
Republican Party Logo
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 11 of 16
Application Behavior Diagrams:
1) Main Activity
The “info” options
menu item opens the
“About” activity.
Each political official entry
displays the office
(upper-left) and the official’s
name and political party
(lower-right). The political
party is in parenthesis.
A separator image should be
added to the end of each list
entry to create a nice break
between entries.
The “Location” options
menu item opens an
alert dialog that allows
the user to enter a
city/state or zip code
manually.
Click on an entry to open the
individual Representative
Activity
There is no need for a longpress/click capability here.
RecyclerView list
entries have their own
layout
Full location information
comes from the
normalizedInput section of
the JSON download.
On startup, the application should use the device’s
current location zip code to populate the list with
officials.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 12 of 16
2) Manually setting the location
3) Opening the About Activity
Enter a City, State or a Zip Code:
90001 .
CANCEL OK
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 13 of 16
4) Viewing an Individual Official
5) Interactive links on the official’s activity:
Click on an entry
to open the
individual Official
Activity
Scrolls
Down
Social media links. Where
supplied, the official’s social media
links will be displayed using the
social media’s icon. If available,
the icon is present – if not it is
absent (the icon should not be
displayed).
Click on the photo (where available) to
open the Photo Activity
Click the Party Logo when present to
go to the political party’s website:
Dem: https://democrats.org
Rep: https://www.gop.com
Click on the address (where
available) to open the office
location in Google Maps
Click on the phone number (where
available) to open the Phone App
with the phone number preloaded)
Click on the Email Address (where
available) to open the email app
with this address pre-loaded in the
new message
Click on the Website address
(where available) to open the
website in a browser.
Clicking on these will open the
related app (if installed) or will
default to opening the site in a
web browser.
Scrolls
Up
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 14 of 16
6) Viewing an individual Official’s Photo Activity:
7) If no location or no internet connection:
Click on the
Photo to open
the Photo
Activity
On StartUp or new specified
location query Official Activity Photo Activity
Data cannot be accessed/loaded
without an internet connection.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 15 of 16
Development Plan
1) Create the base app:
a. MainActivity with RecyclerView
b. Official Class
c. RecyclerView Adapter
d. RecyclerView ViewHolder
e. Create fake “dummy” officials to populate the list in the MainActivity onCreate.
f. Add the onClick methods. The onClick can open a Toast message for now.
g. Zip/City options-menu item opens the dialog, on entry you can open a Toast message for now.
h. Create the About Activity – opens when MainActivity “About” options menu item is selected.
2) Add the location code.
a. Add the location code that determines the device’s zip code (this happens in onCreate).
b. Instead of using that zip code to make the Google API call, you can open a Toast message that
displays the zip code for now.
3) Add the Official Activity:
a. This activity opens when an entry in the list of elected officials is clicked on.
b. You can use the data in your test (dummy) official objects to test this activity.
c. Any test data you don’t have (i.e., missing data) should be properly handled in your activity.
d. The social media ImageView onClick’s should open a Toast message that displays the name of
the social media for now.
e. Remember to create the separate layout for landscape orientation.
4) Add the Google Civic Information API elements:
a. Create the Google Civic Information API Runnable class.
b. Remove the use of dummy data from your app (now you will have real data).
c. Remove the location Toast message. Instead, here you use the device’s zip code (or a manually
entered location) to make the API call.
d. This should result in a populated list of Official objects in your MainActivity that is then
displayed in the RecyclerView.
e. Add the Photo Activity, opened when an official’s photo is clicked in the Official Activity
f. Remember to create the separate layout for landscape orientation.
5) Test the app very thoroughly and review your implementation against all requirements multiple times.
CS 442 Mobile Applications
Development (Android Section)
© Christopher Hield 16 of 16
Assignment Assistance
The TAs for our course is available to assist you with your assignment if needed. Questions on assignment
requirements and course concepts can be sent to the instructor.
Submissions & Grading
1) All submissions will be graded once the due-date arrives. NO resubmission can be made at that
point, regardless of the excuse. If you are not ready to be graded, DO NOT SUBMIT.
2) All submissions must conform to all requirements in this document, no exceptions. Please be sure
to carefully review this document against your implementation to insure you did not miss anything.
3) Submissions must consist of your zipped project folder (please execute Build =>Clean Project before
generating the zip file).
4) Submissions should reflect the concepts and practices we cover in class.
5) Grading will be based upon the presence and proper functionality of all features and behaviors
described in this document.
NOTE
This assignment is worth 400 points. This means (for example) that if you get 89% on this
assignment, your recorded score will be:
(89% * 400 points = 356 points)
If you do not understand anything in this handout, please ask.
Otherwise the assumption is that you understand the content.
Unsure? Ask!