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 9: Customize! Navigating with a Master/Detail Flow Activity 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: Understand responsive design for Android apps Create an Android tablet project using an application template Understand the Master/Detail Flow template Modify the Master/Detail Flow template Add a WebView control 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 Web browser within a tablet app Add an Internet permission to the Android Manifest Customize the content of the sample template file Display a custom layout in the details pane 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. Understanding Responsive Design Responsive design –An approach to designing apps and Web sites that provide an optimal viewing experience across as many devices as possible 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. Using Application Templates Application templates –Used to create basic Android applications that can immediately be run and test on an Android device of any size –Android templates are available when you create a new Android project 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. Master/Detail Flow Template –Creates an adaptive, responsive layout for a set of list items and associated detail content 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. Master/Detail Flow Template (continued) 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. Master/Detail Flow Template (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. Master/Detail Flow Template (continued) 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. Understanding the Structure of the Master/Detail Flow Template Java Files –ItemDetailActivity.java The purpose of this class is to display the activity_item_detail.xml layout file if a smartphone is detected –ItemDetailFragment.java The purpose of this class is to display the fragment_item_detail.xml layout file –ItemListActivity.java The purpose of this initial Activity is to display the master list in a two-pane mode if a tablet device is detected or to launch a second Activity to display the detailed items if a smaller device is detected –ItemListFragment.java The purpose of this class is to display the activity_item_list.xml layout file –DummyContent.java The purpose of this Java file is to provide sample code you customize to suit your specific app content. 10 Android Boot Camp for Developers Using Java, 3rd Ed.

11 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Understanding the Structure of the Master/Detail Flow Template (continued) 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. Layout Files –activity_item_detail.xml When a smartphone is detected, the app uses this layout to display the FrameLayout instance –activity_item_list.xml(2) –activity_:item_list.xml When a smartphone is detected, the app uses this layout to display the master list fragment –activity_item_list.xml(sw600dp): When a tablet is detected, the app is displayed in a two-pane layout containing both the master item list fragment and the item detail container –fragment_item_detail.xml When a smartphone or a tablet is detected, this layout file displays the detail pane using the onCreateView( ) method 12 Android Boot Camp for Developers Using Java, 3rd Ed. Understanding the Structure of the Master/Detail Flow Template (continued)

13 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Adding Images to the Drawable Folder 13 Android Boot Camp for Developers Using Java, 3rd Ed. Before designing the XML layouts, first place three images in the drawable folder and then reference them in the photos.xml layout

14 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing an XML TableLayout The Strings table is responsible for the text displayed in the app –The first string is displayed in the title bar of the tablet, and the second string is displayed in the title bar of a smaller device such as a smartphone 14 Android Boot Camp for Developers Using Java, 3rd Ed.

15 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing an XML TableLayout (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 an XML TableLayout (continued) 16 Android Boot Camp for Developers Using Java, 3rd Ed.

17 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Designing an XML TableLayout (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 an XML TableLayout (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. Creating a TextView XML Layout for the Second List Item 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. Creating a TextView XML Layout for the Second List Item (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. 21 Android Boot Camp for Developers Using Java, 3rd Ed. Webview –A View widget object that displays Web pages Permission –A restriction limiting access to a part of the code or to data on the device Creating a WebView XML Layout for the Third List Item Code Syntax

22 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Creating a WebView XML Layout for the Third List Item (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. Customizing the Item List 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. 24 Android Boot Camp for Developers Using Java, 3rd Ed. Customizing the Item List (continued)

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

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

27 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Displaying the Custom Layout in the Detail Pane 27 Android Boot Camp for Developers Using Java, 3rd Ed. A fragment is a piece of an application’s user interface or behavior that can be placed in an Activity –Fragments are essentially a sub-Activity hosted inside another Activity To determine if two String objects match exactly: –Use the.equals method, and not the == operator –The == operator compares if two objects are exactly the same object. –Two strings may be different objects, but have the same exact characters –The.equals() method is used to compare strings for equality

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

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

30 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Running and Testing the Application Tap or click the Run ‘app’ button on the Standard toolbar, select the Nexus 10 emulator to test the application in the emulator, and then tap or click the OK button Unlock the emulator (if necessary) Test each tab to ensure it works as intended –You must have Internet connectivity to open the Web page and enough memory available to handle the app connection to the Web 30 Android Boot Camp for Developers Using Java, 3rd Ed.

31 © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary Responsive design is an approach to designing apps and Web sites that provide an optimal viewing experience across as many devices as possible Android templates are available when you create a new Android project and are used to create basic Android applications that you can run and test on an Android device of any size A tablet app created with the Master/Detail Flow template displays a Master list of items in a narrow vertical pane along the left edge of the screen To display the detail content for the first list item in the Bike and Barge app, you provide images and text descriptions in an XML TableLayout. Each row in the TableLayout displays an ImageView and TextView control 31 Android Boot Camp for Developers Using Java, 3rd Ed.

32 © 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 display the detail content for the second list item, you code two TextView controls in a Linear layout that include the tour details To display the detail content for the third list item, you customize the default fragment_item_detail.xml layout to use a WebView object instead of a TextView object After including a WebView object in the XML layout of an app, you must add the INTERNET permissions to the Android Manifest file so the app can access the Internet and load Web pages 32 Android Boot Camp for Developers Using Java, 3rd Ed.

33 © 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 associate the content displayed in the detail pane with each list item in the left pane, you customize the DummyContent.java class file by adding code to the addItem statement so it references three String objects: the id, the item list string, and the Web site URL To handle the responses to user selections, you add conditional statements to the ItemDetailFragment.java file 33 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