Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. 2 3 The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.

Similar presentations


Presentation on theme: "1. 2 3 The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories."— Presentation transcript:

1 1

2 2

3 3 The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories

4 4

5 5 Control the quiz difficulty by specifying whether to display two, four, six or eight guess. Buttons, and by choosing the world regions that should be included in the quiz.

6 6

7 7

8 8 uses an animation to shake the flag horizontally and

9 9

10 10 Technologies Overview modify the menu’s XML file by providing an icon for the Settings menu item and specifying that the icon should be displayed directly on the app bar. The options menu is an object of class Menu (package android.view). You override Activity method onCreateOptionsMenu When the user selects a menu item, Activity method onOptionsItemSelected responds to the selection.

11 11 Technologies Overview A fragment typically represents a reusable portion of an Activity’s user interface, but may also represent reusable program logic. App uses fragments to create and manage portions of the app’s GUI. Combine several fragments to create user interfaces that make better use of tablet screen sizes. Interchange fragments to make your GUIs more dynamic Class Fragment (package android.app) is the base class of all fragments.

12 12 The Flag Quiz app defines the following direct and indirect Fragment subclasses: Class MainActivityFragment: Displays the quiz’s GUI and defines the quiz’s logic. two layouts for MainActivity—one for devices in portrait orientation and one only for tablets in landscape orientation. Class SettingsActivityFragment: subclass of PreferenceFragment automatically maintains an app’s user preferences in a file associated with the app. class PreferenceFragment uses that file to build an appropriate preferences GUI Technologies Overview

13 13 Technologies Overview When you finish a quiz, the app creates an anonymous subclass of DialogFragment and displays an AlertDialog containing the quiz results. Fragments must be hosted by an Activity. Not independently. onCreate— is called when a Fragment is created. onCreateView— is called after onCreate to build and return a View containing the Fragment’s GUI.

14 14 Technologies Overview An Activity manages its Fragments via a FragmentManager accessible via Activity’s getFragmentManager method. FragmentTransactions to dynamically add, remove and transition between Fragments. Settings are stored persistently in a file as key–value pairs—each key enables you to quickly look up a corresponding value. a file is manipulated via class SharedPreferences

15 15 Technologies Overview A PreferenceFragment uses Preference objects to manage app settings and stores those settings in a file via a SharedPreferences object. Preference subclass ListPreference to manage the number of guess Buttons displayed for each flag and Preference subclass MultiSelectListPreference to manage the world regions to include in the quiz. PreferenceManager object to access and interact with the app’s default SharedPreferences file.

16 16 Technologies Overview To modify a SharedPreferences file’s contents, use SharedPreferences.Editor object App’s flag images are loaded into the app only when needed and are located in the app’s assets folder. assets subfolders are accessed via an AssetManager Folder names that begin with anim contain XML files that define tweened animations, which can change an object’s transparency, size, position and rotation over time. two layouts that present MainActivity’s contents:

17 17 Technologies Overview A Toast briefly displays a message, then disappears from the screen. The app displays the correct answer for two seconds before displaying the next flag. Use a Handler class. Handler method postDelayed receives as arguments a Runnable to execute and a delay in milliseconds. AnimationUtils static method loadAnimation to load the animation from an XML file that describes the animation’s options.

18 18 Technologies Overview Display messages, options and confirmations to app users via AlertDialogs. An AlertDialog is a modal dialog—when it’s displayed, the user cannot interact with the app until the dialog is dismissed (closed). Use AlertDialog.Builder object, then use it to create the AlertDialog.

19 19 Technologies Overview Android uses a technique known as intent messaging to communicate information between activities within one app or activities in separate apps. AndroidManifest.xml file specify intent filters indicating actions the Activity is capable of handling. An Activity is launched by using an Intent that indicates an action to be performed and the data on which to perform that action. Implicit and Explicit Intents All activities in an Android app must be listed in the app’s manifest.xml file.

20 20 Strings.xml

21 21

22 22

23 23

24 24

25 25

26 26

27 27

28 28

29 29

30 30

31 31

32 32

33 33

34 34

35 35

36 36

37 37 Using Fragments to create portions of an Activity’s GUI. Used two activities to display the MainActivityFragment and the SettingsActivityFragment when the app was running in portrait orientation. Used 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. Conclusion

38 38 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. 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. Conclusion


Download ppt "1. 2 3 The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories."

Similar presentations


Ads by Google