Flag Quiz Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Test drive app Quiz progress Current Flag Answer options
© by Pearson Education, Inc. All Rights Reserved.
# #FFFFCC #00CC00 #FF0000
© by Pearson Education, Inc. All Rights Reserved.
The answer Buttons will be dynamically added. NOTE: There are 3 rows, but two of them may be left empty.
© by Pearson Education, Inc. All Rights Reserved.
The answer Buttons © by Pearson Education, Inc. All Rights Reserved. When you answer, “What type of resource…?” Select as the root element Button.
Creating Shake Animation Defined in an.xml file (SURPRISE!) Right click the layout folder, select New > Other In the Android node, select Android XML file, click Next> to display the New Android XML File In the File text field enter the name incorrect_shake.xml Under “What type of resource….?”, select the Animation radio button. ▫ Puts the new file into the project’s res/anim folder At bottom of dialog, select set as the animation’s root element Click finish Configure properties © by Pearson Education, Inc. All Rights Reserved.
3 translate animations in this animation set Animation set may contain Any combination of tweened animations: Alpha (transparency) Scale Translate (moves a view within parent) rotate fromXDelta is View’s offset when animation starts toXDelta is offset when It ends How long animation last in milliseconds So animations don’t run in parallel
Technologies Overview Using App’s Assets Folder ▫ Can drag folders of images to here ▫ Must be accessed via AssetManager to open InputStream to read file Using Menu ▫ Override Activity’s onCreateOptionsMenu ▫ onOptionsItemSelected is the event handler method that responds to user’s selection Using Runnable ▫ Use a Handler object to execute Runnable to delay displaying next flag © by Pearson Education, Inc. All Rights Reserved.
Technologies Overview Applying Animation to an ImageView ▫ Use AnimationUtils static method loadAnimation to load animation from.xml file ▫ Specify # times animation should repeat with method setRepeatCount ▫ Call startAnimation to perform the animation Logging Exception Messages ▫ For debugging purposes ▫ Use try/catch blocks when processing files ▫ Can view logged messages with Android logcat tool. © by Pearson Education, Inc. All Rights Reserved.
Using ArrayList Import package for this templated data structure Expandable “array” Can access like an array, has methods, process with for each loop private List list; list = new ArrayList (); int numItems = list.size(); list[i] = myString; myString = list.get(index); for (String s : list) //use s somehow; can’t change it if (s.equals(keyString)) count++; list.add(anotherString); list.remove (index); or list.remove(theString); list.clear(); Collections.shuffle (list); © by Pearson Education, Inc. All Rights Reserved.
Also a HashMap Using HashMap ▫ To store region names and corresponding Boolean values to indicate if region is enable or not ▫ Has methods we’ll see ▫ Can be processed with a for each loop We are using ArrayList and HashMap objects, but their references are of type List and Map, resp. ▫ Good Java practice, so we can change data structures easily without affecting rest of app’s code Also using interface Set when we want all keys in the HashMap © by Pearson Education, Inc. All Rights Reserved.
Building the FlagQuizGame App © by Pearson Education, Inc. All Rights Reserved. Data Structures Error logging Folders of images
© by Pearson Education, Inc. All Rights Reserved.
AndroidManifest File New Features android:theme attribute ▫ A theme is a set of styles that specify the appearance of a GUI’s components ▫ List of predefined styles and themes on the web android:screenOrientation ▫ The FlagQuizGame app should always be in portrait mode © by Pearson Education, Inc. All Rights Reserved.
AndroidManifest Editor /Application Tab © by Pearson Education, Inc. All Rights Reserved.
AndroidManifest File © by Pearson Education, Inc. All Rights Reserved.