Building User Interface for Android Mobile Applications II

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

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

UI Fragment.

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

Beginning Android 4 Application Development

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

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

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

ANDROID USER INTERFACE

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

Android Programming (5 Days)

CHAPTER 4. Fragments ActionBar Menus

Mobile Application Development Android

CS378 -Mobile Computing. User Interface Basics

MC Android Programming

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

CS371m - Mobile Computing. User Interface Basics

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

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

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

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

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

LECTURE 08 UI AND EVENT HANDLING

Android Basics. Android UI Architecture. Android UI 1

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

Stanislav Rost CSAIL, MIT

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

GUI Design for Android Applications

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

ListView Containers. Resources. Creating a ListView

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

Activities and Fragments

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Required Core Java for Android application development

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

GUI Widget. Lecture6

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

User Interface: Layout. Asst. Prof. Dr. Kanda Runapongsa Saikaew Computer Engineering Khon Kaen University

Android Programming Lecture 2 9/7/2011

Fragments. Lecture 11

Fragments and the Maps API

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

Mobile User Interfaces

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

Programming Android UI. J. Serrat Software Design December 2017

ConstraintLayouts in Android

INTRODUCTION COS MOBILE DEVELOPMENT WHAT IS ANDROID CORE OS. 6-Android Basics.key - February 21, Linux-based.

Mobile Computing Fragments

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

MOBILE COMPUTING 1/20/18. How many of you. CSE 40814/60814 Spring have implemented a command-line user interface?

Overview. What are layouts Creating and using layouts Common layouts and examples Layout parameters Types of views Event listeners

Android Application Development

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

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

EMBEDDED SYSTEMS PROGRAMMING UI and Android

Mobile Computing Practice # 2a Android Applications - Interface

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

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

CS 4330/5390: Mobile Application Development Exam 1

Programmatically Working with Android Fragments

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

Event Driven UIs and Model-View-Controller

Adapter.

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

Android Programming - Jelly Bean

Announcements. Android: n-puzzle Walkthrough. Tommy MacWilliam. Dynamic GUIs. ListViews. Bitmaps. Gameplay. Saving State. Menus

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Mobile Development Lecture 10: Fragments

Java Training Center - Android Application Development

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

Mobile Computing Practice # 2c Android Applications - Interface

Android UI DateBasics

AND-401 Android Certification. The exam is excluded, but we cover and support you in full if you want to sit for the international exam.

Android for Ubiquitous Computing Researchers. Andrew Rice University of Cambridge 17-Sep-2011

Xamarin for C# Developers

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

Minds-on: Android. Session 2

14.1 Overview of Android

M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 2

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Creating a User Interface

O X X X O O X O X. Tic-Tac-Toe. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 2: The Ultimate Tic-Tac-Toe Game

Programming with Android: Introduction. Layouts. Luca Bedogni. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

(c) Dr Sonia Sail LAJMI College of Computer Sciences & IT (girl Section) 1

Programming with Android: Layouts, Widgets and Events. Dipartimento di Scienze dell Informazione Università di Bologna

Introductory Mobile App Development

Lab 1 - Setting up the User s Profile UI

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

Chapter 8 Positioning with Layouts

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

CS 528 Mobile and Ubiquitous Computing Lecture 3: Android UI, WebView, Android Activity Lifecycle Emmanuel Agu

Android User Interface

Mobile and Ubiquitous Computing: Android Programming (part 3)

Mobile Programming Lecture 3. Resources, Selection, Activities, Intents

Mobila applikationer och trådlösa nät, HI1033, HT2012

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Android Programming in Bluetooth Cochlea Group

A view is a widget that has an appearance on screen. A view derives from the base class android.view.view.

COLLEGE OF ENGINEERING, NASHIK-4

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

Transcription:

Building User Interface for Android Mobile Applications II Mobile App Development

1 MVC 2

MVC 1 MVC 2

MVC Android redraw View invalidate Controller tap, key pressed update Model

MVC MVC in Android View The View is the application s feedback to the user and is a portion of application that is responsible for rendering the display. Graphically, it represents a rectangular area on the screen that is completely within the rectangular area represented by its parent in the tree. The root of this tree is the application window.

MVC MVC in Android Controller The Controller is the portion of an application that responds to external actions: a keystroke, a screen tap, an incoming call, etc. System maintains a queue of events and removes events in order and dispatches them. View event Queue event event event Controller1 Controller2 Controller3

MVC MVC in Android Model Controller as a reaction to the event notifies the Model. The Model is updated and sends the information to the View to refresh (invalidate) View event event update Controller Queue Model invalidate

MVC

1 MVC 2

Chapter 4 Building UI Using and layouts Understanding Optimizing layouts Creating resolution-independent user interfaces Extending, grouping, creating, and using Using to bind data to

TextView and EditText TextView TextView is for display only. It can be used as a label or as a way to present text without option to edit it. EditText EditText is a predefined subclass of TextView that includes rich editing capabilities.

TextView properties Outline You can change its height, width, font, text color, background color, etc. Interesting non-standard properties autolink if set to true, finds URLs in the displayed text and automatically converts them to clickable links. autotext if set to true, finds and corrects simple spelling errors in the text. editable if set to true, indicates that the program has defined an input method to receive input text. inputmethod Identifies the input method inputtype specifies a type of input e.g. phone no, email, password. a a http://developer.android.com/reference/android/widget/textview.html

Button and ImageButton Button The Button View is just a button, printed with some text to identify it, that the user can click to invoke some action. ImageButton ImageButton View is a button with an image on it rather than one with text

ImageButton Example Outline In main.xml 1 <ImageButton 2 a n d r o i d : i d= @+i d / btndone 3 a n d r o i d : l a y o u t w i d t h= w r a p c o n t e n t 4 a n d r o i d : l a y o u t h e i g h t= w r a p c o n t e n t 5 /> in activity s oncreate 1... 2 // Get p o i n t e r s to t h e d e f i n e d i n main. xml 3 btn1 = ( ImageButton ) f i n d V i e w B y I d (R. i d. btndone ) ; 4... 5 // Set t h e image f o r t h e Done b u t t o n 6 btn1. s e t I m a g e R e s o u r c e (R. d r a w a b l e. l o g ) ;

and Adapter The Adapter has two responsibilities: find the data object that corresponds to a particular index supply a view through which the data at a particular index can be displayed. Adapter The AdapterView is a generic, list-oriented view of data. Any collection of data objects that can be ordered in some relatively stable way can be displayed through an AdapterView.

CheckBoxes, RadioButtons, and Spinners Check-Boxes are typically used when you want to offer multiple selections RadioButtons are used when only one choice is allowed at a time Spinners are similar to combo boxes, displays the currently selected option, along with a pull-down list from which the user can click on another option to select it. All above are optimized in Android to serve better in touchscreen environment

CheckBox The CheckBox View takes care of flipping its state back and forth and displaying the appropriate checkmark when the state is true. All you have to do is create an OnClickListener to catch click events, and you can add whatever code you want to react.

RadioGroup RadioGroup View is really a ViewGroup that contains any number of RadioButton. The user can select only one of the buttons at a time, and you capture the selections by setting OnClickListeners for each RadioButton. Note that clicking on one of the RadioButtons does not fire a click event for the RadioGroup.

Spinner Spinners require the most work of these three, but can also provide the best use of scarce screen real estate. To make it work you have to: Create a list of the selections (can be dynamic) Create an ArrayAdapter from the list that the Spinner can use for its drop-down list. Create an onitemselectedlistener for the Spinner to capture select events. Note If you declared values in XML then Adapter is implicit!

WebView Outline WebView A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more. To enable zoom Set WebSettings.setBuiltInZoomControls

1 MVC 2

ViewGroup Outline are that contain child.

ListView and ListActivity ListView ListView is similar to Gallery, the difference is in scrolling. Gallery provides horizontal while ListView vertical scrolling capabilities. ListActivity Is used to create a ListView that takes up the entire screen. Simple implementation can use a simple String array containing data, an ArrayAdapter that contains a reference to this list of strings and ListActivity using Adapter. See the example in the Hallo Android for more details.

ScrollView Outline A ScrollView is a container for another View that lets the user scroll that View vertically ScrollView vs. ListView ListView is designed to display a set of similar things (e.g. makes of cars). The ScrollView, on the other hand, allows an arbitrary View to scroll vertically.

TabHost Outline Three different approaches for setting the tab s content Set the content of a tab to an Intent Use a TabContentFactory to create the tab s content on-the-fly Retrieve the content from an XML layout file, much like that of a regular Activity

1 MVC 2

Outline Why? Android supplies a set of that can pump data from common data sources (including arrays and Cursors) into the native controls that extend Adapter View. Responsibilities are responsible both for supplying the data and for creating the that represent each item, can radically modify the appearance and functionality of the controls they are bound to.

Two useful adapters Outline ArrayAdapter It uses generics to bind an Adapter View to an array of objects of the specified class. By default, it uses the tostring value of each object in the array to create and populate Text. SimpleCursorAdapter It enables you to bind the within a layout to specific columns contained within a Cursor (returned from a Content Provider). The adapter will create a new View for each Cursor entry and inflate the layout into it, populating each View within the layout using the Cursor s corresponding column value.

Creating and applying an Adapter ArrayList<String> mystringarray = new ArrayList<String>(); int layoutid = android.r.layout.simple_list_item_1; ArrayAdapter<String> myadapterinstance; myadapterinstance = new ArrayAdapter<String>(this, layoutid, mystringarray); mylistview.setadapter(myadapterinstance);

1 MVC 2

Frame Layout Outline Frame Layout The Frame Layout is sort of a null layout specification. It reserves space on the screen for a single View to be drawn, and the View is always located at the upper left of the space. There is no way to specify a different location for the View, and there can be only one View in the Layout. Note! If more than one View is defined in the layout file, they are just drawn on top of each other, all pinned to the upper-left corner.

LinearLayout and TableLayout LinearLayout The most popular layout in Android. are laid out as either a series of rows (vertical LinearLayout) or a series of columns (horizontal LinearLayout). TableLayout It lays out the included in the form of a table (similar to an HTML table).

AbsoluteLayout and RelativeLayout AbsoluteLayout An AbsoluteLayout puts views on the screen wherever you tell it to. No resizing, nor alignment is done. It just puts things where it s told so be careful! RelativeLayout It allows you to express the relative positioning of the in the screen, and the layout manager will do its best to fit them all on the screen in the proper relations. Properties such as android:layout below, android:layout torightof etc are used to express relative position

1 MVC 2

...... were introduced to Android as part of the Android 3.0 Honeycomb (API level 11) release. They are now also available as part of the Android support library, making it possible to take advantage of on platforms from Android 1.6 (API level 4) onward.

Why? enable you to divide your Activities into fully encapsulated reusable components, each with its own lifecycle and UI. What? Each Fragment is an independent module that is tightly bound to the Activity into which it is placed. can be reused within multiple activities, as well as laid out in a variety of combinations to suit multipane tablet UIs and added to, removed from, and exchanged within a running Activity to help build dynamic UIs.

Building framgents Outline 1 Extend the Fragment class to create a new Fragment, (optionally) defining the UI and implementing the functionality it encapsulates. 2 Assign a UI to your Fragment (It is possible to create a Fragment that doesn t include a UI but instead provides background behaviour for an Activity) 3 Override the oncreateview handler to in ate and return the required View hierarchy

1 You must call back to the superclass when overriding most of these event handlers. 1 Source: Professional Android 4 Application Development

Creating and Destroying fragments (1) Create The onattach event is triggered before the Fragment s UI has been created, before the Fragment itself or its parent Activity have nished their initialization. Typically, the onattach event is used to gain a reference to the parent Activity in preparation for further initialization tasks. As with Activities, you should use the oncreate method to initialize your Fragment. It s good practice to create any class scoped objects here to ensure they re created only once in the Fragment s lifetime. Note Unlike Activities, the UI is not initialized within oncreate.

Creating and Destroying fragments (2) Destroy The created lifetime of your Fragment occurs between the first call to oncreate and the nal call to ondestroy. As it s not uncommon for an Activity s process to be terminated without the corresponding ondestroy method being called, so a Fragment can st rely on its ondestroy handler being triggered.

Fragment Manager Outline Each Activity includes a Fragment Manager to manage the it contains. You can access the Fragment Manager using the getfragmentmanager method. It provides the methods used to access the currently added to the Activity, and to perform Fragment Transaction to add, remove, and replace. FragmentManager fragmentmanager = getfragmentmanager();

FragmentTransaction Outline Fragment Transactions Fragment Transactions can be used to add, remove, and replace within an Activity at run time. Using Fragment Transactions, you can make your layouts dynamic that is, they will adapt and change based on user interactions and application state. FragmentTransaction fragmenttransaction = fragmentmanager.begintransaction(); // Add, remove, and/or replace. // Specify animations. // Add to back stack if required. fragmenttransaction.commit();

Android Fragment Classes DialogFragment A Fragment that you can use to display a floating Dialog over the parent Activity. ListFragment A wrapper class for that feature a ListView bound to a data source as the primary UI metaphor. It provides methods to set the Adapter to use and exposes the event handlers for list item selection. WebViewFragment A wrapper class that encapsulates a WebView within a Fragment. The child WebView will be paused and resumed when the Fragment is paused and resumed.