Reference CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing Fragments, ActionBar and Menus Part 1 of 5 Android Programming Concepts, by Trish Cornez and Richard Cornez, pubslihed by Jones & Barlett Learning, pp. 185-278. Paul I-Hai Lin, Professor Spring 2017 A Specialty Course Purdue University M.S. Technology Graduate Program Dept. of Computer, Electrical and Information Technology Purdue University Fort Wayne Campus 1 Topics of Discussion Fragmentation and Android Fragments The Fragment Lifecycle Action Bar Lab Example 4-1: Fragments and the ActionBar: Menu Experiment, pp. 285-298 ActionBar Configurations Overflow and Action Bar Adding an Action View Lab Example 4-2: Unit Calculator App, pp. 305-318 Responsive Design with Fragments Lab Example 4-3: Shades App: A Fragment Experiment, pp. 321-338 2 1
Topics of Discussion Animation in Fragment Transaction Lab Example 4-4: Recipes-Fragments with Transition Animation, pp. 339-382 ListViews and Adaptors Lab Example 4-5: Redlands Music Events App Adapters and ListViews. 353-371 3 Fragments, https://developer.android.com/guide/components/fragments.html A Fragment represents a behavior or a portion of UI in an Activity A Fragment == A Sub Activity A fragment has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. 4 2
Fragments, https://developer.android.com/guide/components/fragments.html Each Fragment has its own callback methods in the standard Activity lifecycle oncreatview() oninflate() onactivitycreated() onattach() ondestroyview() ondeatch() 5 ActionBar, https://developer.android.com/reference/android/sup port/v7/app/actionbar.html A primary toolbar within the activity that may display the activity title, application-level navigation affordances, other interactive items. The action bar appears at the top of an activity's window when the activity uses the AppCompat's AppCompat theme (or one of its descendant themes). You may otherwise add the action bar by calling requestfeature(feature_support_action_ba R) or by declaring it in a custom theme with the windowactionbar property. 6 3
ActionBar, https://developer.android.com/training/appbar/index.html Also called App bar which provides information and display control elements to the user. Provides a visual structure and interactive elements Key functions of the app bar A dedicated space for giving your app an identity and indicating the user s location in the app. Access to important actions in a predictable way such as search Support for navigation and view switching ActionBar class, https://developer.android.com/reference/android/support/ v7/app/actionbar.html 7 ActionBar, https://developer.android.com/training/appbar/index.html ActionBar class, https://developer.android.com/reference/android/support/ v7/app/actionbar.html Material Design App Bar, https://developer.android.com/design/patterns/actionbar. html 1. App Icon 2. View Control 3. Action buttons 4. Action overflow 8 4
Navigation with Back and Up, https://developer.android.com/design/patterns/navigation.html 9 Deprecated Methods import android.app.activity; import android.app.actionbar actionbar.setnavigationmode(actionbar.navigation_mode_ TABS); actionbar.tab breakfasttab = actionbar.newtab().settext( getstring(r.string.ui_tabname_breakfast)); actionbar.setselectednavigationitem(savedinstancestate.getint( TAB_KEY_INDEX, 0)) class MyTabsListener implements ActionBar.TabListener { public Fragment fragment; 10 5
ActionBar deprecated methods Deprecated Methods import android.support.v7.app.appcomatactivity setnavigationmode(), addtab(), selecttab() actionbar.setnavigationmode(actionbar.navigation_mode_ TABS); ActionBar.Tab breakfasttab = actionbar.newtab().settext( getstring(r.string.ui_tabname_breakfast)); breakfasttab.settablistener(new MyTabsListener (breakfastfragment, getapplicationcontext())); actionbar.addtab(breakfasttab); 11 ActionBar Depreciated Methods https://developer.android.com/reference/android/support/ v7/app/actionbar.html Use inline toolbar action bars 12 6
Lab 4-1 Fragments and ActionBar: Menu Experiment The ActionBar of an Application Application Icon Action Items Action overflow 13 Lab 4-1 Fragments and ActionBar: Menu Experiment An ActionBar containing Tabs 14 7
Lab 4-1 Fragments and ActionBar: Menu Experiment Project structure MyActity.java BreakfastFragment.java DinnerFragment.java LunchFragment.java SnackFragment.java 15 Lab 4-1 Fragments and ActionBar: Menu Experiment Activity_my.xml contains a LinearLayout for storing fragments res/layout activity_my.xml fragment_breakfast.xml, fragment_lunch.xml fragment_dinner.xml, fragment_snack.xml 16 8
Lab 4-1 Fragments and ActionBar: Menu Experiment The fragment_snack.xml layout shown in landscape orientation 17 Summary Q/A? 18 9