bCourses assignment https://bcourses.berkeley.edu/courses/1469435/assignments/7877915
starter code: https://github.com/cs160-spring2018/prog3-starter
- Viewing Landmarks and how far away they are
- Accessing a landmark message board
- Posting / retrieving comments from a message board using Firebase
- display a recycler view with a cell for each landmark in bear_statues.json. Each cell should contain:
- the landmark name
- the landmark image: use the bear_images included in the starter code
- the distance between that landmark and your user's last updated location
- an "update location" button. when pressed, you should fetch the user's location and update each of the landmark's distances
You can locate your user using android's locationing api's. Since these api's are a part of Google Play Services, you will need to run an emulator with Google Play Services already installed (i.e., Nexus 5 or 5x) or install Google Play Services to an existing emulator.
- use the starter code for the message board portion of the app as an example of how to create a recylcer view, adapter, and custom cells
- Here is an example of a simple location tracking app: https://github.com/googlesamples/android-play-location/tree/master/LocationUpdates. You may find it helpful to add the code from MainActivity file into your own app to test out location services. Do note that you are not required to continuously track location updates, as is done in this example.
- If you are using a simulator for testing, you can simulate location updates via the Location tab in your simulator's "Extended Controls" menu. Below is a screenshot of what this menu looks like, using a simple location app provided at https://github.com/googlesamples/android-play-location/tree/master/LocationUpdates.
- Users should only be able to access a location's message board if they are within 10 feet of that location.
// returns true if location A is less than 10 meters away from location B
Math.round(locationA.distanceTo(locationB)) < 10
To present the message board, you will need to use an Intent
Intent goToSecondActivityIntent = new Intent(FirstActivity.this, SecondActivity.class);
FirstActivity.this.startActivity(SecondActivity);
To pass data through an intent to the next activity, you can use the putExtra
and getExtras
methods.
FirstActivity.java
String hello = "hello";
goToSecondActivityIntent.putExtra("helloString", hello);
SecondActivity.java
Intent goToSecondActivityIntent = getIntent();
Bundle intentExtras = goToSecondActivityIntent.getExtras();
if(bundle!=null) {
String helloString =(String) intentExtras.get("helloString");
// do something with helloString
}
We have provided starter code for this part of the assignment. These files are included in the starter code repo:
- Comment model file: Comment.java
- layout files
- activity file: CommentFeedActivity.java
- recylcer view adapter and view holder: CommentFeedAdapter.java
You will need to:
- link this provided comment feed to a database
Tip: You can use the Uri
class to get a reference to images in your drawable folder. Use this along with ImageView.setImageUri
to set an image view's image to that resource image's Uri.
// get the imageUri from a drawable resource file
Uri imageUri = Uri.parse("android.resource://" + [your package name] + "/drawable/" + [your image name]);
// display uri in your image view
mImageView.setImageURI(imageUri);
We recommend you use the Firebase Realtime Database for this assignment, since it is built into Android Studio.
Android Studio walks you through most of the process of setting up the database, but here is guide on setting up and reading and writing to your database: https://github.com/cs160-spring2018/cs160-proj3-spec/blob/master/firebase_guide.md. The Firebase documentation online is very extensive, too!