In this chapter, you created the interactive Tip Calculator app. We discussed the app’s capabilities, then you test-drove it to calculate the tip and total, based on the bill amount. You built the app’s GUI using Android Studio’s layout editor, Component Tree window and Properties window. You also edited the layout’s XML and used the Theme Editor to customize the Theme.AppCompat.Light.DarkActionBar theme’s primary, dark primary and accent colors that were set by the IDE when you created the project. We presented the code for class MainActivity, a subclass of AppCompatActivity (and an indirect subclass of Activity) that defined the app’s logic.
In the app’s GUI, you used a GridLayout to arrange the views into rows and columns. You displayed text in TextViews and received input from an EditText and a SeekBar.
The MainActivity class required many Java object-oriented programming capabilities, including classes, objects, methods, interfaces, anonymous inner classes and inheritance. We explained the notion of inflating the GUI from its XML file into its screen representation. You learned about Android’s Activity class and part of the Activity lifecycle. In particular, you overrode the onCreate method to initialize the app when it’s launched. In the onCreate method, you used Activity method findViewById to get references to each of the views the app interacts with programmatically. You defined an anonymous inner class that implements the TextWatcher interface so the app can calculate new tips and totals as the user enters the bill amount in the EditText. You also defined an anonymous inner class that implements the OnSeekBarChangeListener interface so the app can calculate a new tip and total as the user changes the tip percentage by moving the SeekBar’s thumb.
Finally, you edited the AndroidManifest.xml file to specify that the MainActivity supports only portrait orientation and that the MainActivity should always display the keypad. We also discussed the other elements that Android Studio placed in the manifest when you created the project.
In Chapter 4, you’ll build the Flag Quiz app in which the user is shown a graphic of a country’s flag and must guess the country from 2, 4, 6 or 8 choices. You’ll use a menu and checkboxes to customize the quiz, specifying the number of guess options and limiting the flags to specific regions of the world.