CHAPTER 4. Fragments ActionBar Menus

Similar documents
Topics of Discussion

Topics of Discussion

CS371m - Mobile Computing. More UI Action Bar, Navigation, and Fragments

CS371m - Mobile Computing. More UI Navigation, Fragments, and App / Action Bars

Building User Interface for Android Mobile Applications II

EMBEDDED SYSTEMS PROGRAMMING UI and Android

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

Multiple devices. Use wrap_content and match_parent Use RelativeLayout/ConstraintLayout Use configuration qualifiers

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

ListView Containers. Resources. Creating a ListView

CS 4330/5390: Mobile Application Development Exam 1

UI Fragment.

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Data-Driven Views and Android Components Emmanuel Agu

CS260 Intro to Java & Android 05.Android UI(Part I)

CS260 Intro to Java & Android 05.Android UI(Part I)

Android Essentials with Java

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Rotating Device, Saving Data, Intents and Fragments Emmanuel Agu

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Introduction to Android Programming. Emmanuel Agu

CS 528 Mobile and Ubiquitous Computing Lecture 4a: Fragments, Camera Emmanuel Agu

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

Activities and Fragments

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University. Overview (Review)

Pro Android 2. Sayed Y. Hashimi Satya Komatineni Dave Mac Lean. Apress

Fragments and the Maps API

Designing and Implementing Android UIs for Phones and Tablets

Android. The Toolbar

Polishing and Running a Presentation

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University

Mobile Development Lecture 10: Fragments

SmartArt Office 2007

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Android UI Design in XML + Examples. Emmanuel Agu

Programming with Android: Android for Tablets. Dipartimento di Scienze dell Informazione Università di Bologna

05. RecyclerView and Styles

Mobile Computing Practice # 2a Android Applications - Interface

ANDROID USER INTERFACE

CS 4518 Mobile and Ubiquitous Computing Lecture 2: Introduction to Android Programming. Emmanuel Agu

Mobile Application Development Android

You ve been told lies about Fragments.

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Views & View Events View Groups, AdapterViews & Layouts Menus & ActionBar Dialogs

MS_40541 Build Native Cross-Platform Mobile Apps with a Shared C# Business Logic for ios, Android, and UWP in C#.NET with Xamarin and Visual Studio

Mobile Computing Fragments

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

Xamarin for C# Developers

Android Programming - Jelly Bean

PowerPoint Tutorial 2: Adding and Modifying Text and Graphic Objects 2013

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Developing Android Applications

CS378 -Mobile Computing. User Interface Basics

1. What are the key components of Android Architecture? 2. What are the advantages of having an emulator within the Android environment?

Android Basics. Android UI Architecture. Android UI 1

Android Application Model I

CS378 -Mobile Computing. More UI -Part 2

Chapter 8 Positioning with Layouts

Introduction. Creating a New Publication. Publisher 2010 Creating a New Publication. To Create a New Publication from a Template: Page 1

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial

Introductory Mobile App Development

CS371m - Mobile Computing. User Interface Basics

CE881: Mobile & Social Application Programming

COLLEGE OF ENGINEERING, NASHIK-4

06. Advanced Widget. DKU-MUST Mobile ICT Education Center

GUI Widget. Lecture6

By: Ms. Fatima Shannag Ms. Essra Al-Mousa. Edited by: Khawlah Almutlaq

Creating a Custom ListView

More Effective Layouts

Fragments. Lecture 11

Rev. D 10/26/2012 Downers Grove Public Library Page 1 of 44

Beginning Android Tablet

MICROSOFT POWERPOINT 2016 Quick Reference Guide

Programming Android UI. J. Serrat Software Design December 2017

MC Android Programming

Adapter.

Android Programming (5 Days)

The Photo Gallery. Adding a Photo Gallery Page. Adding a Photo Gallery App

Androidfp_printOnly.book Page vii Tuesday, October 4, :15 AM. Contents. Before You Begin

Mobile Device Features - Android and ios

Android Programming in Bluetooth Cochlea Group

Beginning PowerPoint XP for Windows

Created by: Leslie Arakaki

ListView (link) An ordered collection of selectable choices. key attributes in XML:

User Interface Development. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr.

Microsoft Powerpoint 2007

ANDROID SERVICES, BROADCAST RECEIVER, APPLICATION RESOURCES AND PROCESS

HP Color LaserJet CM2320 MFP Series Print tasks

Android VirtuTrace Remote VTRemote Final Report

Fragments. Fragments may only be used as part of an ac5vity and cannot be instan5ated as standalone applica5on elements.

How to Export a Dashboard in Analyze

07. Menu and Dialog Box. DKU-MUST Mobile ICT Education Center

Presentation Software. Answers

Android Application Development 101. Jason Chen Google I/O 2008

[Not for Circulation] This document provides a variety of shortcuts for working in PowerPoint 2007.

Mobile and Ubiquitous Computing: Android Programming (part 3)

Reference Services Division Presents. Microsoft Word 2

Microsoft PowerPoint 2007 Beginning

Mobile Application Programing: Android. OpenGL Operation

Transcription:

CHAPTER 4 Fragments ActionBar Menus Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to configure the ActionBar Implement Fragments with Responsive Design Techniques Explore animation in Fragment Transactions Experiment with Fragments, ListViews, and ArrayAdapters 1

4.1 Fragmentation and Android Fragments There are many shapes and screen sizes and different performance characteristics Multiple versions of Android are being used This translates into a wider audience to build applications for When designing and coding layouts, there are several factors to consider, such as spacing, positioning, size, and the grouping of user interface controls Layouts must be compatible with many physical screens A Fragment is modeled as a subdivision of an Activity Fragment is integrated into an Activity, and needs an Activity to run The advantage of building applications that use Fragments is their ability to easily present a consistently welldesigned user interface Fragments are particularly helpful in adapting a user experience across a wide range of devices. 2

4.2 The Fragment Lifecycle Fragments are associated with an activity and can be created, added or removed while the activity is running Similar to an Activity, a Fragment has its own lifecycle, as well as its own user interface The Fragment s lifecycle is connected to the activity that owns it Each fragment has its own callback methods in the standard Activity lifecycle. Callbacks used in the lifecycle of a Fragment. oncreateview() oninflate() onactivitycreated() onattach() ondestroyview() ondetach() 3

4.3 Action Bar The action bar provides information and displays control elements to the user. In a basic configuration, the action bar displays the application icon and a title The title often identifies the running activity Users are given an indication of where they are and a consistent identity from which to recognize the application Action bar features: Application Icon Action Items Action overflow 4

4.4 ActionBar Configurations Control elements that appear directly on the action bar as an icon and/or text are known as action buttons When an Activity starts, its associated layout is inflated on the screen and the action bar is populated with action buttons The activity's oncreateoptionsmenu() method is responsible for inflating a menu hierarchy from a specified XML resource file 4.4 ActionBar Configurations Control elements that appear directly on the action bar as an icon and/or text are known as action buttons When an Activity starts, its associated layout is inflated on the screen and the action bar is populated with action buttons The activity's oncreateoptionsmenu() method is responsible for inflating a menu hierarchy from a specified XML resource file Figure 04.06: Action bar with five action buttons and the overflow button 5

4.4.1 Overflow on the Action Bar Narrow devices can often require the use of the overflow button When creating layouts on devices with a narrow screen, use ifroom to request that an item appear in the action bar Allow the system to move elements into the overflow when there is not enough room Figure 04.07: Buttons placed in the overflow menu display text titles Lab Experiment 4-1: Fragment and the ActionBar: Menu Experiment Figure 04.02: An Actionbar containing Tabs 6

Lab Experiment 4-1: Fragment and the ActionBar: Menu Experiment Figure 04.03: Project structure for the ActionBar Experiment application Lab Experiment 4-1: Fragment and the ActionBar: Menu Experiment Figure 04.04: activity_my.xml contains a LinearLayout view for storing fragments 7

Lab Experiment 4-1: Fragment and the ActionBar: Menu Experiment Figure 04.05: The fragment_snack.xml layout shown in landscape orientation 4.4.2 Adding an Action View An action view is simply a widget that appears in the action bar as a substitute for an action button An action view provides quick access to heavily used actions Consider a collapsible search view widget. A search action view can be added as an embedded search view widget in the action bar To declare an action view, the actionlayout or actionviewclass attribute can be added to an item to specify either a layout resource or a widget class 8

Lab Experiment 4-2: Unit Conversion Calculator App (using overflow menu) Figure 04.08: Unit Conversion Calculator Lab Experiment 4-2: Unit Conversion Calculator App (using overflow menu) Figure 04.09: The Overflow menu contains Action Items 9

Lab Experiment 4-2: Unit Conversion Calculator App Figure 04.10: Project structure for the Unit Conversion Calculator app Lab Experiment 4-2: Unit Conversion Calculator App Figure 04.11: The layout design for activity_my.xml 10

4.5 Responsive Design with Fragments Responsive design works across different screens sizes Responsive design techniques should also be applied to Android applications for solving interactive design and layout problems Responsive design is used for heavy data driven content. Adaptive design is primarily used for the re-arrangement of fixed user interface elements in an application Figure 04.12: Fragments can be combined or separated on a device 4.5 Responsive Design with Fragments Responsive design makes use of Fragments A user interface can be divided into multiple panes using Fragments and reused in more than one screen of an application, as shown in the following figure Fragments can be combined or separated on a device When building an application that follows a similar master/detail design pattern, the application often needs a set of Java and XML layout resource files 11

4.5 Responsive Design with Fragments 4.5 Responsive Design with Fragments Responsive design revolves around a master/detail flow interface design pattern The user is provided with a list of items Upon selecting one of the items, additional information relating to that item is then presented to the user 12

This design concept is called responsive in the sense that list and detail panels of the app can change based on the width of the device On a large tablet-sized Android device, the screen is large enough to display both panels The master list can appear as a narrow vertical panel along the left hand edge of the screen while the remainder of the screen can display the detail panel This arrangement is referred to as two-pane mode. Figure 04.14: One- and two-pane configurations Lab Experiment 4-3: Shades App: A Fragment Experiment (using responsive design two-pane/single-pane configuration) Figure 04.14: One- and two-pane configurations 13

Lab Experiment 4-3: Shades App: A Fragment Experiment Figure 04.15: The final project structure for the Shades application Lab Experiment 4-3: Shades App: A Fragment Experiment (Individual Fragment Layouts) Figure 04.16: list_fragment.xml 14

Lab Experiment 4-3: Shades App: A Fragment Experiment (Individual Fragment Layouts) Figure 04.17: The layout, information_fragment.xml, used to hold color information Lab Experiment 4-3: Shades App: A Fragment Experiment (The Main User Interface to Hold the Fragments) Figure 04.18: activity_my.xml uses a LinearLayout root element 15

Lab Experiment 4-3: Shades App: A Fragment Experiment (The Main User Interface to Hold the Fragments) Figure 04.19: The main layout designed for portrait orientation. Fragment1 is shown holding the color list 4.6 Animation in Fragment Transactions Transition animations can be applied directly to fragments that are entering and exiting a transaction The FragmentManager provides the structure that handles transactions between fragments A transaction refers to the sequence of steps that add, replace, or remove fragments. Operations performed by the FragmentManager will occur inside a transaction 16

Lab Experiment 4-4: Recipes-Fragments with Transition (Basic animation effects and the Android Interpolator) Figure 04.20: The Recipes app: A button in the lower left corner for flipping the photograph Lab Experiment 4-4: Recipes-Fragments with Transition Figure 04.21: Project structure for the Recipes application 17

Lab Experiment 4-4: Recipes-Fragments with Transition (Designing Individual Fragments) Figure 04.22: The visual layout design for fragment_recipe_photo Lab Experiment 4-4: Recipes-Fragments with Transition (Designing Individual Fragments) Figure 04.23: The layout, fragment_recipe.xml, used to hold color information 18

Lab Experiment 4-4: Recipes-Fragments with Transition (User Interface and Fragment Design) Figure 04.24: The visual design for activity_my.xml Lab Experiment 4-4: Recipes-Fragments with Transition (The Transition Animation) Figure 04.25: Animation effect rotationx rotates around the x-axis 19

4.7 ListViews and Adapters (dynamic data) A ListView is similar to a ScrollView A ScrollView is an extension of the FrameLayout, and is suitable for holding a single control element It provides the user with the scroll mechanism to reveal more content than can be displayed on the screen at once A LinearLayout, containing multiple View items, can be placed within a ScrollView 4.7 ListViews and Adapters (dynamic data) A ListView is a specialized control that is optimized for displaying long lists of items When the data content for the layout is dynamic or not pre-determined, it is possible to use a layout that subclasses an AdapterView to populate the layout with views at runtime 20

Lab Experiment 4-5: Redlands Music Events App Adapters and ListViews Figure 04.26: A Fragment containing a ListView Lab Experiment 4-5: Redlands Music Events App Adapters and ListViews Figure 04.27: Project structure for the Redlands Music Events application 21

Lab Experiment 4-5: Redlands Music Events App Adapters and ListViews (The Fragment Layout File) Figure 04.28: The layout design for the Music Festival application 4.8 Handling Click Events in a ListView A ListView might be populated with items that need to respond to a click event You can respond to click events on an item in an AdapterView by implementing the AdapterView.OnItemClickListener interface The onitemclick () callback method will always be invoked when an item in the AdapterView has been clicked. 22

Lab Experiment 4-6: Shades (Part 2): Clickable Shades of Color in the ListView Figure 04.29: Shades II application features a scrollable list of clickable items Lab Experiment 4-6: Shades (Part 2): Clickable Shades of Color in the ListView Figure 04.30: Project structure for Shades II application 23

Lab Experiment 4-6: Shades (Part 2): Clickable Shades of Color in the ListView Figure 04.31: The visual structure for the master list, list_fragment.xml 24