Implementing the Framework for the Favorite Place Feature

Before you can turn your attention to the more interesting aspects of adding LBS support to the Been There, Done That! application, you need to leverage many of the skills discussed in previous hours to develop the framework for the favorite place feature. This is a great way to exercise some of your new skills. To implement the feature, follow these steps:

1. Add any new String, Dimension, Color, or Drawable resources needed to support the layouts used by the feature.

2. Update the /res/layout/settings.xml layout file to add the new region at the bottom of the settings screen for launching the favorite place dialog and displaying the favorite location, if one is set, as shown in Figure 14.5.

FIGURE 14.5

The settings screen with the favorite place feature.

| Been There, Done That!

ft Settings

Password:

1 ' 1

Birth Dare:

L

* • f *

Favorite Place:

Favorite Place:

3. Add the /res/layout/fav_place_dialog.xml layout file to the project and implement the TextView, EditText, and Button controls the dialog requires, as shown in Figure 14.6.

4. Define three new game preference String values in the QuizActivity class. These preferences will be used by the application's SharedPreferences to store the user's favorite location name (String) as well as that location's latitude (float) and longitude (float).

5. Update the QuizSettingsActivity class to include a new dialog. First, define a dialog identifier (for example, PLACE_DIALOG_ID) in the class. Then update the onCreateDialog() and onPrepareDialog() methods of the class to build, initialize, and manage the new favorite place picker dialog.

FIGURE 14.6

The favorite place picker dialog.

Because each of these tasks has been covered in a previous hour, we do not go into too much detail here. However, here are a couple hints for getting things up and running:

► Add a helper method called initFavoritePlacePicker() to display the favorite place name (if it exists) and handle Button clicks that launch the favorite place picker dialog. This method should closely resemble the initPasswordChooser() and initDatePicker() methods.

► Build the new favorite place picker dialog much like the password dialog you implemented earlier. One of the key differences between this new dialog and the password dialog is that the new dialog contains a Button control for launching the Map application.

► Build the favorite place picker Dialog one step at a time. Begin by having the Dialog save the text inputted as the favorite place name. Next, to save some mock latitude and longitude information, along with the place name. When this is all working, add a View.OnClickListener() method for the map Button control and have it display a Toast message that says something like Map Button Clicked.

ByWay

The full implementation of these hints is available in the code provided at the book's website.

After you have implemented the framework to support the favorite place feature, you can turn your attention to more interesting matters, such as calculating the user's last known location and mapping GPS coordinates on a map.

0 0

Post a comment