# Lab 4: Services, Camera Overlay, and Wrapping Up the Game ## Tasks: 1. Tracking Service & Notification: Implement a tracking service for tracking a single cat. This service should remain active even if you close your app, and should alert you with a notification when you are getting close to the cat of your choice, and should record the location of the alert. In your Preferences, you will choose the type of the alert: sound, vibration, or just a notification with the recorded coordinates. The tracking API is described in server-protocol.txt. Note that requests may take up to several seconds to complete (due to a slower but more precise distance calculation). You will need to continually update the distance between you and the cat as your location changes. There should be a notification bar displaying this calculated distance in real time. The style of the notification bar should be roughly the same with Lab4.png. The notification bar contains a "STOP" button, by clicking it you can stop the service. On Android 8.0, you will need to use a foreground service for this task, as background services from that version onward will only receive location updates a few times an hour. Note that in the *hard mode* cats will now move randomly around the location reported in the cat list, so you will need to connect to the server to retrieve the distance and the direction to the cat. 2. History Fragment: Implement a history fragment with the list of cats you interact with. The list item should include the cat image, name, location, and an icon indicating whether you have petted the cat. We won't implement the "Ranking" fragment so feel free to delete it from your ViewPager and TabLayout. 3. Camera Overlay: In this part of the lab, you will use the library we provided (developed by Varun---thanks, Varun!) to overlay the image of a cat on top of your camera view---when facing in the right direction. Clicking the "Pet" button should open a camera view. By changing your phone's direction, you should be able to see the cat icon overlaid on top of the camera view. You will then be able to pet the cat by touching the icon within the camera view. See the README in the library repository: https://github.com/mishravarun/camera-overlay-demo 4. Map activity: (coordinating with service) Create two buttons on the game status panel; one is "Track" and another one is "Pet". The "Pet" button will be disabled if you have already petted the cat, while the "Track" button is always enabled. However, after you start tracking service, the "Track" button should become "Stop", so that you could stop the service. Other than clicking the stop button, selecting another cat should also stop the service, with an appropriate message to the user. Your map activity should be aware whether the service is running. If the tracking service is running and you are tracking a single cat, when you reopen your app and click "play", the Map activity should automatically select the cat you are tracking, and the two buttons should be "Stop" and "Pet". ## Terms and conditions: This assignment will be due next Thursday (Nov 9th) at 11:59 PM EST. Late assignments will get 10% credit docked for each day they are late. However, you will receive three (3) free 24-hour late submission passes for this course. Use them wisely. As usual, we will waive late penalties for extenuating circumstances such as travel and sickness (ask if in doubt). The user story below is intended as a general guidance to creating a sensible app interaction. Feel free to use your judgement as to what makes sense and is intuitive. Although you are free to explore third party libraries, the TAs will be able to provide limited help with issues with them. Extra credit will count for 20% of extra points. ## User Stories: 1. Supposing the user has already signed in, the first screen after opening the app will be the "Play" Fragment. 2. If the user swipes to the "History" Fragment, he should be able to see all the cats in the cat list. The user can tell whether the cat has been petted or not from the color of the icon on the right side. 3. If the user goes back to the "Play" Fragment, the user will see the greeting message with number of cats already petted. 4. By clicking the "Play" button, the map activity is invoked. As description in Lab3, the user can see cat markers on the map. If the user select one cat, he should see the cat info, and two buttons on the panel. If the cat has already been petted, the "Pet" button will be disabled, while the "Track" button is unchanged. 5. The user can track the cat by clicking the "Track" button. After clicking it, a notification will show up, and the "Track" button will change to "Stop". If the user click the "Stop" button or selects another cat, the service is killed and notification disappears. 6. While tracking, even if the user closes the app, the service will remain running and the user will receive notifications displaying the distance between the user and the selected cat in real time. 7. The user can stop tracking by clicking the "Stop" button on the notification bar. 8. While tracking, if the user opens the app again, and clicks the "Play" button, the state of the map activity should be restored. In particular, the cat being tracked should be selected, and the two buttons on the panel should be "Stop" and "Pet". Clicking the "Stop" button should stop the service. 9. The user may click the "Pet" button. Instead of simply sending the request of petting the cat as in Lab 3, a camera should be opened. The user can find where the cat is by holding the phone and turning it in different directions. (see Lab4.png) 10. The user will click the cat icon to send the request of petting the cat. If the user is close enough, the app will receive an OK message from the server and display the success activity. If the user is too far away, a toast with an error message should be shown. 11. User sign-out should result in stopping the tracking service. ## Extra Credits 1. For better UX/UI design (explain your design in your documentation!) 2. Notify your users when within a certain range of any cat: While tracking a cat, you'd want to notify the user when they are getting close to a cat (the tracked one or another cat). For example, the phone may vibrate once if the distance is less than 20 meters. The distance should be configurable via your settings fragment. 2 extra credits will be given for implementing this function. 3. In the hard mode, plot the positions of a cat on the map over time.