5.10. Wrap-Up

In this chapter, you built a Flag Quiz app that tests a user’s ability to correctly identify country flags. A key feature of this chapter was using Fragments to create portions of an Activity’s GUI. You used two activities to display the QuizFragment and the Settings-Fragment when the app was running in portrait orientation, and one Activity to display both Fragments when the app was running on a tablet in landscape orientation—thus, making better use of the available screen real estate. You used a subclass of PreferenceFragment to automatically maintain and persist the app’s settings and a subclass of DialogFragment to display an AlertDialog to the user. We discussed portions of a Fragment’s lifecycle and showed how to use the FragmentManager to obtain a reference to a Fragment so that you could interact with it programmatically.

In portrait orientation, you used the app’s action menu to enable the user to display the SettingsActivity containing the SettingsFragment. To launch the SettingsActivity, you used an explicit Intent.

We showed how to use Android’s WindowManager to obtain a Display object so that you could determine whether the app was running on a tablet in landscape orientation. In this case, you prevented the menu from displaying because the SettingsFragment was already on the screen.

We demonstrated how to manage a large number of image resources using subfolders in the app’s assets folder and how to access those resources via an AssetManager. You created a Drawable from an image’s bytes by reading them from an InputStream, then displayed the Drawable in an ImageView.

You learned about additional subfolders of the app’s res folder—menu for storing menu resource files, anim for storing animation resource files and xml for storing raw XML data files. We also discussed how to use qualifiers to create a folder for storing a layout that should be used only on large devices in landscape orientation.

You used Toasts to briefly display minor error or informational messages. To display the next flag in the quiz after a short delay, you used a Handler, which executes a Runnable after a specified number of milliseconds. You learned that a Handler’s Runnable executes in the thread that created the Handler (the GUI thread in this app).

We defined an Animation in XML and applied it to the app’s ImageView when the user guessed incorrectly to provide visual feedback to the user. You learned how to log exceptions for debugging purposes with Android’s built-in logging mechanism and class Log. You also used additional classes and interfaces from the java.util package, including List, ArrayList, Collections and Set.

In Chapter 6, you’ll create a Cannon Game using multithreading and frame-by-frame animation. You’ll handle touch gestures to fire a cannon. You’ll learn how to create a game loop that updates the display as fast as possible to create smooth animations and to make the game feel like it executes at the same speed regardless of a given device’s processor speed. We’ll also show how to perform simple collision detection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset