- 3.1 Introduction
- 3.2 Test-Driving the Tip Calculator App
- 3.3 Technologies Overview
- 3.4 Building the GUI
- 3.5 Default Theme and Customizing Theme Colors
- 3.6 Adding the App's Logic
- 3.7 AndroidManifest.xml
- 3.8 Wrap-Up
3.2 Test-Driving the Tip Calculator App
Opening and Running the App
Perform the steps in Sections 1.9.1 and 1.9.3 to open the Tip Calculator app project in Android Studio and run the app on the Nexus 6 AVD. If you prefer, perform the steps in Section 1.9.4 to run the app on an Android phone.
Entering a Bill Total
Enter the bill total 56.32 by touching numbers on the numeric keypad. If you make a mistake, press the keypad’s delete button () to erase the last digit you entered. Even though the keypad contains a decimal point, the app is configured so that you may enter only the digits 0 through 9—other input buttons on the keypad are ignored and an Android device will vibrate to indicate when you touch an invalid input button. Each time you touch a digit or delete a digit, the app reads what you’ve entered so far, and
- converts it to a number
- divides the number by 100.0 and displays the new bill amount
- recalculates the tip and total amounts, based on the current tip percentage (15% by default) and
- displays in the Tip and Total TextViews the new tip and total amounts.
If you delete all the digits, the app redisplays Enter Amount in the blue TextView and displays 0.00 in the orange TextViews. The app divides the value by 100.0 and displays the result in the blue TextView. The app then calculates and updates the tip and total amounts in the orange TextViews.
All monetary amounts are displayed in locale-specific currency formats and the tip percentage is displayed in a locale-specific percentage format. For the U.S. locale, as you enter the four digits 5, 6, 3 and 2, the bill total is displayed successively as $0.05, $0.56, $5.63 and $56.32, respectively.
Selecting a Tip Percentage
Use the Seekbar—often called a slider in other GUI technologies—to specify the tip percentage. Drag the Seekbar’s thumb until the percentage reads 25% (Fig. 3.1(b)). As you drag the thumb, the tip and total update continuously. By default, the Seekbar allows you to select values from 0 to 100, but we specified a maximum value of 30 for this app.