Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.

Similar presentations


Presentation on theme: "© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp."— Presentation transcript:

1 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp for Developers Using Java, 3E Chapter 8: Design! Using a DatePicker on a Tablet 1 Android Boot Camp for Developers Using Java, 3rd Ed.

2 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Objectives In this chapter, you learn to: Create an Android project on a tablet Understand tablet specifications Follow design principles for the Android tablet Add a second Android Virtual Device Add a custom launcher and tablet theme Understand the Calendar class Use date, time, and clock controls Determine the system date 2 Android Boot Camp for Developers Using Java, 3rd Ed.

3 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Objectives (continued) Display a DatePicker control Launch a dialog box containing a DatePicker control Code an onDateSetListener method to await user interaction Determine the date entered on a calendar control Test an application on a tablet emulator 3 Android Boot Camp for Developers Using Java, 3rd Ed.

4 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Application Android Apps not limited to phones Tablets are used to –Connect to the Internet –Play games –Use social media –Check e-mail –And more… 4 Android Boot Camp for Developers Using Java, 3rd Ed.

5 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Application (continued) 5 Android Boot Camp for Developers Using Java, 3rd Ed.

6 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Application (continued) Steps to complete the App: 1. Add an Android Virtual Device specifically designed for tablets. 2. Add the images used in this project. 3. Change the theme and icon for the tablet display. 4. Create a custom XML file with a Table layout. 5. Add and initialize the TextView controls and the Button control. 6. Initialize a DatePickerDialog with the present date and listen for the user to select a date. 7. Return the selected date. 8. Display the selected reservation date in the TextView control. 6 Android Boot Camp for Developers Using Java, 3rd Ed.

7 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Application Native applications are programs locally installed on a specific platform (phone or tablet) An emulated application is converted in real time to run on a variety of platforms (various screens) Android tablet apps create an optimal user experience Different devices have different screen sizes –Common size is between 7.3 and 10.1 inches, 2560 x 1600 pixel resolution and 16:10 screen ratio iPad Air is 9.7 inches, 2048 x 1536 and 4:3 7 Android Boot Camp for Developers Using Java, 3rd Ed.

8 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Application (continued) 8 Android Boot Camp for Developers Using Java, 3rd Ed.

9 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Design Best Practices for Tablets Keep screens uncluttered and use large controls Make the design simple and make the app intuitive Leave out “cool” interactions that distract the user Use flexible dimension values such as dp and sp instead of px or pt Provide higher resolution – make your app look great on any screen size Create a unique experience for phone and tablet designs Use larger fonts than with a phone app. Consider printing out your user interface design to see how it looks 9 Android Boot Camp for Developers Using Java, 3rd Ed.

10 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Adding an Android Virtual Device for the Tablet 10 Android Boot Camp for Developers Using Java, 3rd Ed. Uses Android Honeycomb 3.2 (API 13) operating system –The minimum required SDK should be set to API 13: Android 3.2 (Honeycomb) to cover the oldest Android tablets –Set the Target SDK to the newest SDK available Must add Android Virtual Devices (AVD)

11 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Creating a Tablet App 11 Android Boot Camp for Developers Using Java, 3rd Ed.

12 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 12 Android Boot Camp for Developers Using Java, 3rd Ed. Creating a Tablet App (continued)

13 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Creating a Tablet App (continued) 13 Android Boot Camp for Developers Using Java, 3rd Ed.

14 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 14 Android Boot Camp for Developers Using Java, 3rd Ed. Creating a Tablet App (continued)

15 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Creating the String Table (continued) 15 Android Boot Camp for Developers Using Java, 3rd Ed.

16 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout 16 Android Boot Camp for Developers Using Java, 3rd Ed. TableLayout is composed of TableRow controls—one for each row in your table in activity_main.xml The padding property can be used to offset the content of the control by a specific number of pixels. Another Android property named typeface sets the style of the text to font families that include monospace, sans_serif, and serif

17 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 17 Android Boot Camp for Developers Using Java, 3rd Ed.

18 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 18 Android Boot Camp for Developers Using Java, 3rd Ed.

19 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 19 Android Boot Camp for Developers Using Java, 3rd Ed.

20 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 20 Android Boot Camp for Developers Using Java, 3rd Ed.

21 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 21 Android Boot Camp for Developers Using Java, 3rd Ed.

22 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 22 Android Boot Camp for Developers Using Java, 3rd Ed.

23 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing a Tablet Table Layout (continued) 23 Android Boot Camp for Developers Using Java, 3rd Ed.

24 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Creating a control to enter the date is crucial because requiring users to type the date in a text box can lead to multiple errors, including incorrect format or typos 24 Android Boot Camp for Developers Using Java, 3rd Ed. Date, Time, and Clocks

25 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Instantiating the Objects The txtReservation TextView control is referenced in multiple methods, so this instantiation must be declared as a class variable The TextView control, Button control, and the Button OnClickListener must all be instantiated 25 Android Boot Camp for Developers Using Java, 3rd Ed.

26 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Instantiating the Objects (continued) 26 Android Boot Camp for Developers Using Java, 3rd Ed.

27 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Instantiating the Objects (continued) 27 Android Boot Camp for Developers Using Java, 3rd Ed.

28 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Android System date is accessed by using the Calendar class which reads the updated time zone information from the wireless provider The getInstance method returns the YEAR, MONTH, DAY_OF_MONTH, and the DAY_OF_YEAR 28 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class

29 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Date Format Formats the date into a String value 29 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class (continued)

30 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. DatePickerDialog Input –Allows you to select a date from a DatePicker View –TimePickerDialog allows you to select a time from the TimePicker View –The ProgressDialog displays a progress bar below a message text box to inform you of how long a time- consuming operation is taking –get accesses the system date or time, and set changes the current date or time 30 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class (continued)

31 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 31 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class (continued)

32 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 32 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class (continued)

33 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 33 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class (continued) Selecting the Date From the DatePickerDialog Adding the onDateSet() Method the onDateSet( ) method automatically obtains the date selected by the user

34 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 34 Android Boot Camp for Developers Using Java, 3rd Ed. Using the Calendar Class (continued)

35 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 35 Android Boot Camp for Developers Using Java, 3rd Ed. Displaying the Date Using the getTime( ) Method The getTime( ) method returns the time value in the Date object Using the Calendar Class (continued)

36 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary When designing apps for an Android tablet, keep your users’ objectives and the size of the device in mind. To use an Android emulator designed for tablets, you first add AVD configurations appropriate for tablets. You can combine the Linear layout and the Table layout to create a simple, clean layout that takes advantage of a tablet’s width. The TableLayout contains TableRow controls—one for each row in your table in main.xml. In each TableRow, you can insert a view control such as a Button or TextView. 36 Android Boot Camp for Developers Using Java, 3rd Ed.

37 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (continued) You can display a calendar tool called a DatePicker control in a dialog box so users can select a date from the control. –The Time & Date category in the Palette contains many calendar controls, including TimePicker, DatePicker, CalendarView, Chronometer, AnalogClock, and DigitalClock. To display the current system date when the DatePicker control opens, use the currentYear, currentMonth, and currentDay class variables which hold the system year, month, and day. 37 Android Boot Camp for Developers Using Java, 3rd Ed.

38 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (continued) To create a DatePickerDialog instance, you must OnDateSetListener( ) method to await user interaction. If you include a control, such as a Button, that users tap to display a calendar, use the setOnClickListener method to implement the Button.OnClickListener. When a dialog box containing a DatePicker appears, users can select a date and tap a Button control. 38 Android Boot Camp for Developers Using Java, 3rd Ed.

39 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (continued) When the integer id for the DATE_DIALOG_ID constant is passed to the DatePicker dialog box in the onClick method, a new DatePicker Dialog is passed along with the values for year, month, and day. After an app calls a showDialog(DATE_DIALOG_ID) method in reaction to the user tapping a Button control, the showDialog method calls the OnCreateDialog callback method. 39 Android Boot Camp for Developers Using Java, 3rd Ed.

40 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (continued) When a dialog box containing a DatePicker appears, users can select a date and tap a Button control. –Tapping the Button invokes an onDateSetListener in DatePickerDialog, which passes integers representing the year, month, and day from the DatePicker into onDateSet. –The selected date can then be displayed in a TextView control using setText. 40 Android Boot Camp for Developers Using Java, 3rd Ed.


Download ppt "© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp."

Similar presentations


Ads by Google