Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Exercises

1. Visit http://developer.android.com and take a look around. Check out the


online Developer’s Guide and reference materials. Check out the Community
tab and considering signing up for the Android Beginners and Android
Developers Google Groups.
2. Add more text to the Droid #1 application. To do this, first add another
String resource to the strings.xml resource file and save this file. Next, use
the layout resource editor to modify the main.xml layout file to add a second
TextView control. Set the text attribute of the TextView control to your newly
created String resource. Finally, rerun the application in the emulator to see
the results.
3. Add to your Eclipse workspace one of the Android sample projects provided
with the Android SDK. Browse through the project files and then create a run
configuration and launch the sample application in the emulator.

Exercises
1. Launch the Android emulator and browse the settings available. Change the
language settings. Uninstall an application.
2. Launch the Android emulator and customize your home screen. Change the
wallpaper. Install an AppWidget. Get familiar with how the emulator tries to
mimic a real handset. Note the limitations, such as how the dialer works.
3. Try launching the Hierarchy Viewer tool with the Droid1 project you created
in Hour 1. Note how you can drill down to see the TextView controls you
created.

Exercises
1. Add a logging tag to your Droid1 project. Within the onCreate() callback
method, add an informational logging message, using the Log.i() method.
Run the application and view the log results.
2. Implement some of the Activity callback methods in addition to
onCreate(), such as onStart(), onRestart(), onResume(), onPause(),
onStop(), and onDestroy(). Add a log message to each callback method and
then run the application normally. View the log results to trace the application
life cycle. Next, try some other scenarios, such as pausing or suspending
the application and then resuming. Simulate an incoming call. Watch the
application log to see how the activity responds to such events.

Exercises
1. Add a new color resource with a value of #00ff00 to your Droid1 project.
Within the layout file, change the textColor attribute of the TextView control
to the color resource you just created. Rerun the application and view the
result.
2. Add a new dimension resource with a value of 22pt to your Droid1 project.
Within the layout file, change the textSize attribute of the TextView control
to the dimension resource you just created. Rerun the application and view
the result.
3. Add a new drawable graphics file resource to your Droid1 project. Within the
layout file, add an ImageView control and set its src attribute to the drawable
resource you just created. Rerun the application and view the result.
4. Add a raw text file resource to the Droid1 project. Use the openRawResource()
method to create an InputStream object and read the file. Output the contents
of the file to the log by using the Log.v() method. Rerun the application
and view the result.

Exercises
1. Create a new icon for the Droid1 project.
2. Create another Activity class. Edit the permissions to use a permission of
your choice. Also, try to use feature without requesting the appropriate permission
and observe the results.
3. Perform a modification to the manifest file using the manifest file editor.
Observe the changes made by looking at the XML. Attempt to do the same by
just editing the XML.

Exercises
1. Add a preference to the application preferences called lastLaunch. Have the
QuizSplashActivity read and save the current time each time the
onCreate() method is called. When this preference is read, log it using the
Log.i() method.
2. Create a set of activity-level preferences for QuizSettingsActivity, using the
getPreferences() method instead of the getSharedPreferences() method.

UNIT-II
Exercises
1. Modify LayoutAnimationController to apply animations of each child view
within a TableRow control in random order by using the setOrder() method
with a value of 2 (random).
2. Modify LayoutAnimationController to apply animations to each child view
within a TableLayout control instead of each TableRow control. View the
resulting animation.
3. Modify the splash screen layout to play a short video instead of animating the
ImageView controls. First replace the TableLayout control with a VideoView
control. Then set the URI of VideoView to the URL of a web video in the
appropriate format, using the Uri.parse() method and the VideoView control’s
setVideoURI() method. Finally, remove AnimationListener and use a
VideoView control’s OnCompletionListener instead to transition to the main
menu screen when the video completes.

Exercises
1. Review some of the other data adapters available for use with the ListView
control. Update the ListView control so that each list item contains an
ImageView icon and the TextView control. (Hint: Implement a custom data
adapter.)
2. Add a third option to the game screen’s options menu to allow the user to
access the scores screen.
3. Modify the LinearLayout control of menu.xml to include an animation that
fades in so that the entire main menu screen fades in.

Exercises
1. Launch the application and click each of the links in the help screen text.
Note how easy it can be to integrate Android applications into the Android
platform. Try launching some other kinds of intents and seeing what
happens. For a good list of intents, check out the Intents Registry at
http://www.openintents.org/en/intentstable.
2. Add a third tab to the scores screen to display the user’s current score. Make
the content of this new tab different from the other two tabs by including a
TextView control instead of a TableLayout control. The user’s current score
will be be stored as an application preference.
Exercises
1. Add a Toast to the Password Dialog Button click handler. Make it display the
message “Clicked!” when the Button is clicked.
2. Modify each EditText control to save its contents when the user presses the
up key (KEYCODE_DPAD_UP) or down key (KEYCODE_DPAD_DOWN) on the directional
keypad in addition to the Enter key (KEYCODE_ENTER).
3. Implement a Clear button that deletes all game preferences, using the
clear() method of SharedPreferences.Editor. Don’t forget to call the
commit() method.

Exercises
1. Update the DatePickerDialog onDateSet() method to save the date of birth
to a TextView to display on the main settings screen.
2. Update the password dialog to display the status of the password (set or unset)
in a TextView on the main settings screen.

Exercises
1. Add a new option to the options menu of the game screen to reset the trivia
quiz. Make sure you clear only the appropriate game settings, not all of the
preferences, in SharedPreferences.
2. Modify the application to use a different data structure, like a linked list,
instead of a Hashtable.

UNIT-III
Exercises
1. Use the Bitmap class to modify an avatar in some way before saving it to the
application file. For example, use the Matrix class to invert all the colors in
the graphic (inversion).
2. Use the createScaledBitmap() method of the Bitmap class to generate a
scaled version (thumbnail) of a avatar graphic.

Exercises
1. Modify the favorite place picker dialog to take GPS latitude and longitude
data that the user inputs.
2. Modify the favorite place picker dialog to allow the user to configure the zoom
level of the map shown.
3. Modify the Been There, Done That! application to save altitude information
along with the latitude and longitude settings.

Exercises
1. Test the Been There, Done That! application in a variety of network situations.
Modify the emulator settings to simulate a slow network and then run the
application and view the results.
2. Modify the application to use the Thread and Handler methods for background
processing instead of the AsyncTask method.
3. Modify the application to download the next batch of trivia questions in the
background prior to running out of existing questions in the batch.
Exercises
1. Use the hashed unique device ID and the URL http://tqs.mamlambo.com/getplayer
to perform a GET request to retrieve player info and load up the settings
with the data from the server. Pass in just the playerId to get public
data or pass in playerId and password to get all the data (this is what you’ll
need for a full recovery).
2. Add a new feature to the application to allow players to suggest for new trivia
questions via SMS to the developer.
3. Add a new feature to the application that allows players to suggest new trivia
questions—with images—by uploading them via multipart MIME POST to
http://tqs.mamlambo.com/suggest, with a player identifier form field
(playerId), question text form field (question), and question image form
field (questionImage), with the image data done in the same way as for the
avatar image used in this hour.

Exercises
1. Modify the Scores of Friends tab of the scores screen to display each friend’s
avatar as well as each score. (Hint: The URL for each friend’s avatar is included
in the XML score data downloaded from the application server.)
2. Modify the scores screen to add another tab, showing the scores of players
who have added this player as a friend (in other words, players who are
watching this player’s score). The application server has the appropriate query
implemented. Use the same URL but add the variable followers and set it to
the string true (for example,
“http://tqs.mamlambo.com/scores.jsp?playerId=##&followers=true”).
3. Review the development API documentation of the third-party social networking
service of your choice. Consider implementing a simple feature for the
Been There, Done That! application which accesses that networking service in
an interesting way. For example, you might post a tweet to the player’s Twitter
feed each time that player answers a quiz question in the affirmative (for
example, “Player X has climbed Mount Everest!”).
4. Add a feature to send a text message to the user’s friend to challenge him or
her to beat the user’s score.

UNIT-IV
Exercises
1. Add a new set of string resource values to the Been There, Done That! application
in the language or locale of your choice. Test the results in the Android
emulator and on a real handset (if it supports the language/locale you chose).
2. Change the Been There, Done That! application so that it loads a custom
drawable or color resource for a specific language or locale. For example,
change the planet graphic on the main menu to something more specific to
that language/locale. Test the results in the Android emulator and on a real
handset (if it supports the language/locale you chose).

Exercises
1. Test the Been There, Done That! application on a handset. Change to landscape
mode and ensure that all screens of the application display correctly.
Add landscape-specific layout resources where needed (the splash screen and
game play screen, at a minimum).
2. Compile the Been There, Done That! application for a variety of target SDK
versions and test them on handsets or the emulator with the appropriate AVD.
Exercises
1. Think of three different ways a local SQLite database could be used to
enhance the Been There, Done That! application.
2. Review the various system services that can be requested by using the
getSystemService() method. The various services are defined in the
android.content.Context class.
3. Review the Been There, Done That! application and identify three functional
areas where you could design and use custom View controls. What would
those custom controls do?
4. Many Android applications have the same look because they rely on the
default theme provided by the platform. Add theme definitions to the layout
screens in the Been There, Done That! application. This way, the application
will have a custom look that will be consistent across Android devices, regardless
of what their default theme is.

Exercises
1. Develop a high-level test plan for the Been There, Done That! application.
2. Write a test case for validating that a user’s avatar uploads correctly.
3. Review the various agreements you have encountered in beginning to develop
Android applications (such as the Android SDK License Agreement and
Google Maps API Terms and Conditions). Identify any test cases that might be
required for compliance with these agreements.

UNIT-V
Exercises
1. Choose one of the Been There, Done That! builds from this book (from any
hour). Export the APK package file and digitally sign it.
2. Install the Been There, Done That! application package on a handset by using
the adb command-line utility.

Exercises
1. Create a developer account for yourself on the Android Market.
2. Browse through the Android Market (on a handset or on the Android Market
website). Think of an idea for an application and determine what category
and price range for that application in the Android Market.
3. Go write a fabulous and exciting application, and then share it with the
world.

You might also like