Lecture 3 & HW 3: Intents and Manifest
Last week, we built a color selector app. Now, it's a useful app by itself, but sometimes you might want a bit more functionality -- perhaps multiple utilities in an app, perhaps access to the world around it?. How about adding all of that to your existing app? Ready? Let’s go!
You are tasked with modifying your existing color selector app from HW 2. If you have not completed HW 2 yet, or you are unconfident with your solution, we'll share a good "baseline" HW 2 app below:
Baseline solution for HW2--Use only if you are unconfident with your own solution!
For clarity, we'll be referring to our original activity from HW 2 as rgbActivity and our new activity created in HW 3 as hsvActivity.
1. Create a new activity with HSV SeekBars (there should be three for hue, saturation, value) and add a button on rgbActivity that opens hsvActivity, and add a button on hsvActivty that opens rgbActivity. The text labels for the SeekBars should look like the ones below:
2. Make sure that when the activity changes, both color square and sliders change values accordingly. For example, if the color in rgbActivity is #cdcdcd, then when the activity changes to hsvActivity, the color square and sliders should also represent #cdcdcd.
3. In hsvActivity, add a button below the Seekbars that finds your current location color. Make sure to change the Seekbars and the color square accordingly when the button is pressed. Use the code snippet below to create a custom color for your location:
// enter location.latitude as a parameter
private fun getColorString(latitude : Double) : String = resources.getString(
((latitude % 1) * 100000).roundToInt().toString().padStart(6, '0')
// Can then use Color.parseColor to convert hex strings (which is what the
// above function does given the latitude) to Color.
It may be the case that your emulator will return a null location! The best way to test this feature is to use a physical device; however, if you don't have one, you can hardcode the latitude to test the feature, and comment out this hardcoded value before you submit.
Location permissions (with EasyPermissions) require the following dependencies to be added to your gradle file!
4. If the user denies location permission, display a
Snackbarthat states "Location permissions are not granted" and add a retry button in the
Snackbarthat requests for location permissions again (check this out for a tutorial on
5. Add a share button on rgbActivity that shares the color from the color square to other apps (through an
ACTION_SEND). The share message should say “Check out this color: <color hex>”
Give yourself ample time to try and set up the Location permission request flow (come to office hours ASAP if you are stuck)! See 3.5 Permissions, requesting location permissions, and getting the last location.
These are optional challenge problems, and completing each successfully will earn you 1 extra point per problem. If you do attempt a challenge problem, make sure to include a readme.txt that states which problem(s) you've attempted!
- Implement a two color palette where one color represents the longitude and one represents the latitude.
- Modify the RGB sliders to represent “degrees, minutes, seconds” for precision accuracy.
- Add a button to open Google Maps at that color’s location.
- Modify the HSV sliders to represent the X, Y, and Z readings from the gyroscope.
- Add a switch to enable/disable continuous reading of gyroscope color.
- (Note: You might need to test on physical device)
- Add the ability to save and retrieve a color from
- Display saved colors in a list on a third activity.
For this assignment, you may need to figure out a few things on your own. Some classes that may be helpful for this assignment include:
For basic functionality:
For challenge problems: