Mobile User Interfaces

Similar documents
Praktikum Entwicklung Mediensysteme. Implementing a User Interface

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

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

CS378 -Mobile Computing. User Interface Basics

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

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

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

Android Basics. Android UI Architecture. Android UI 1

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Activities and Fragments

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

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

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

Android Programming Lecture 2 9/7/2011

ANDROID USER INTERFACE

Stanislav Rost CSAIL, MIT

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

Android User Interface

Android User Interface Android Smartphone Programming. Outline University of Freiburg

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

CS371m - Mobile Computing. User Interface Basics

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

Lab 1 - Setting up the User s Profile UI

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

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

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Mobile Application Development Android

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

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

Building User Interface for Android Mobile Applications II

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

Have a development environment in 256 or 255 Be familiar with the application lifecycle

Lab 1: Getting Started With Android Programming

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

Computer Science E-76 Building Mobile Applications

UNDERSTANDING ACTIVITIES

Android UI Development

Android UI DateBasics

Mobile Programming Lecture 1. Getting Started

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

Application Fundamentals

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

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

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

EMBEDDED SYSTEMS PROGRAMMING Application Basics

LECTURE 08 UI AND EVENT HANDLING

Real-Time Embedded Systems

Mobile Computing Practice # 2c Android Applications - Interface

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

Android Application Development

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

ListView Containers. Resources. Creating a ListView

CS 4330/5390: Mobile Application Development Exam 1

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

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

Embedded Systems Programming - PA8001

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

Android Programming (5 Days)

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Programming Android UI. J. Serrat Software Design December 2017

Overview of Activities

Lecture 6: Android XML, Inversion of Control, Timers (Handlers), Activity

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

Android UI: Overview

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Minds-on: Android. Session 2

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

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

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

INTRODUCTION TO ANDROID

CMSC436: Fall 2013 Week 3 Lab

Creating a User Interface

ES E 3 3 L a L b 5 Android development

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

MC Android Programming

LECTURE NOTES OF APPLICATION ACTIVITIES

GUI Design for Android Applications

GUI Widget. Lecture6

Lab 3. Accessing GSM Functions on an Android Smartphone

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

States of Activities. Active Pause Stop Inactive

Beginning Android 4 Application Development

Embedded Systems Programming - PA8001

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

CS378 - Mobile Computing. Anatomy of an Android App and the App Lifecycle

This lecture. The BrowserIntent Example (cont d)

Mobile and Ubiquitous Computing: Android Programming (part 3)

Chapter 5 Flashing Neon FrameLayout

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

14.1 Overview of Android

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

Lecture 7: Data Persistence : shared preferences. Lecturer : Ali Kadhim Al-Bermani Mobile Fundamentals and Programming

The Internet. CS 2046 Mobile Application Development Fall Jeff Davidson CS 2046

Android Development Crash Course

Required Core Java for Android application development

The Suggest Example layout (cont ed)

Activities. Repo:

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

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

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Transcription:

Mobile User Interfaces CS 2046 Mobile Application Development Fall 2010

Announcements Next class = Lab session: Upson B7 Office Hours (starting 10/25): Me: MW 1:15-2:15 PM, Upson 360 Jae (TA): F 11:00 AM-12:00 PM, Upson 328B, Bay D

Recap Task = Stack of related Activities Activity Lifecycle: Active = In the foreground, called onresume() Paused = Obscured, called onpause() Stopped = Not visible, called onstop() Resources separate program logic from other stuff Strings, images, UI layouts AndroidManifest.xml tie together components

Processes/Threads on Android Default: One application = one process All components are instantiated on main thread Consequence: Should not perform long/blocking operations without forking. Definition of application: all components grouped under the <application> tag in AndroidManifest

Service Lifecycle Service has oncreate, onstart, and ondestroy methods (but no pause/resume). startservice (like startactivity) will start the service if it isn t already running. Then, call onstart If service is already running, just call onstart As consequence of single process, should spawn new Thread to handle work.

Service.stopSelf onstart(intent i, int startid) Should stop Service when all commands have been processed. Because of threading no guarantee of order. stopself(startid): Will stop Service if startid corresponds to last command. What data structure should we use to store startids?

Service All explained at http://developer.android.com/reference/android/ app/service.html Also see my post on the Newsgroup We ll talk about this more in a few lectures when we get to background tasks.

Developer Blog Improving Apps Listen to your users Use betas before making final releases Improve stability and eliminate bugs Monkey: Send random UI events View reported crashes in Android Market Improve UI Responsiveness Today s lecture! Integrate with the system and third-party apps See post for many more: http://android-developers.blogspot.com/2010/10/improving-app-quality.html

Designing Mobile Interfaces Reading: 12 myths of mobile UI design (Most of these are not actually related to UI) Takeaways: Keep it simple! Get in the shoes of your users Figure out what 90% of your users need to do 90% of the time, and make it easy. Consistency is key. The less you reinvent the wheel and use standard UI features, the more your user will already know how to use.

View Hierarchy View: Basic unit of user interface Widgets: android.widget.* Leaves of the hierarchy tree ViewGroup: Defines a layout Also in android.widget.* Define where to place children Views (or ViewGroups)

Examples of Widgets Button EditText CheckBox and RadioButton Spinner Others: TextView, ImageView Can extend a widget, or create a brand new one.

Examples of Layouts Remember: ViewGroup is just a subclass of View Simplest: FrameLayout Blank space to be filled with a single object Pins objects to top-left corner If it contains more than one object, just draws them overlapping This is the root layout for any Activity

LinearLayout Aligns all children one after the other in a single direction orientation = vertical or horizontal Can nest for more complex layout. Common use: (small) forms Vertical LinearLayout Horizontal LinearLayout TextView = Label EditText = Value Horizontal LinearLayout

TabLayout Multiple distinct features in one View Good use of constrained screen space Two methods of filling tabs: Swapping Views best for features which are similar and fit into one functional group. Swapping Activities best for managing separate tasks, instead of one massive Activity and layout.

Other Layouts RelativeLayout Specify elements relative to parent or siblings Combination of power and simplicity in description EditText: Below TextView OK Button: Below EditText, aligned to right of parent (Screen) TableLayout Cancel Button: Left of OK Button, small margin to the right

Nested LinearLayouts Nesting LinearLayouts is an easy way to create many common UIs. Caution: doing this too much (more than ~5 levels of nesting) can make UI sluggish! Tool for detecting common problems: http://android-developers.blogspot.com/2009/11/optimize-your-layouts.html

LinearLayout Relative Layout Solution: Refactor into a RelativeLayout Example: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html Might not seem like much, but if this is drawn on screen many times

ListView ViewGroup containing a list of Views Can define a View to display when List is empty with setemptyview Each row is by default just a TextView can customize. Usually populated dynamically Assignment 1: String[] array of tasks Assignment 2: Data pulled from a ContentProvider.

ListView Adapters Adapter Binds dynamic content to the Views in a ListView. e.g. ArrayAdapter for arrays Simple bind a text value to the one text field in the ListView. More complex custom ListView rows, custom objects being bound to the Views. We ll see this in Assignment 2

Layout Weight Weight allows creating LinearLayouts with proportional sizes. Default = 0 minimum space to display all content

Example How would you define this layout?

Defining Layout Most common method XML layout files Located in res/layout/<file>.xml can access later as R.layout.<file> from code. All files contain: XML version: <?xml version="1.0" encoding="utf-8"?> xmlns:android tag in root element <LinearLayout xmlns:android= http://schemas.android.com/apk/res/android"> From oncreate, call setcontentview(r.layout.<file>) to set the root layout element for an activity.

XML Layout All attributes preceded with android: Attributes which apply to every View: id optional a unique identifier for the object so it can be accessed later from code. Specify as android:id= @+id/<name> In Java: (Button) b = (Button) findviewbyid(r.id.<name>); layout_width/layout_height dimensions of object Specific size (pixels, or dips density-independent pixels) fill_parent: Takes up entire size of the parent ViewGroup wrap_content: Takes up only as much space as is needed to display the View.

Styles Essentially, CSS for Android UI Located in res/values/<anything>.xml styles.xml is a good choice <?xml version= 1.0 encoding= utf-8?> <resources> <style name= BigText > <item name= android:textsize >30dip</item> </style> </resources> Apply to a view in XML with: style= @style/bigtext

Themes Theme: Style applied to entire Activity or application Apply in AndroidManifest.xml Common examples: Make Activity look like dialog box: <activity android:theme= @android:style/theme.dialog > Get rid of title bar: @android:style/theme.notitlebar More on Styles/Themes: http://developer.android.com/guide/topics/ui/themes.html

Programmatic Layout Can also define layout in Java: public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); LinearLayout ll = new LinearLayout(this); Button button1 = new Button(this); button1.settext("hello"); Button button2 = new Button(this); button2.settext("world"); ll.addview(button1); ll.addview(button2); setcontentview(ll); } In practice, much easier to define XML layout But, need Java to receive events from Views and update them dynamically.

More on UI Resources: Hello, Views tutorial: http://developer.android.com/resources/tutorials/views/index.html Examples (with code) for these and other layouts Examples for common widgets (Date Picker, Spinners, Image Galleries, etc.) Javadoc for android.widget package: http://developer.android.com/reference/android/widget/package-summary.html For each View/ViewGroup, describes: XML attributes that can be specified Methods that can be called on the Java object. Official developer blog posts on UI: http://android-developers.blogspot.com/search/label/user%20interface API Demos

UI in Java Have defined layout in XML now what? We need to know how to: Get data from and put data to widgets How do we access the text in an EditText? Receive events from widgets How can we do something when a button is clicked?

Getting References Have view with android:id= @+id/widget ; <Class> widget = (<Class>) findviewbyid(r.id.widget); <Class> is the class of the View, i.e. Button or EditText This is the object we need to: Get/set fields Set up event handlers

Gotchas If you need to access a view in more than one method: Have a class variable prefixed with m (for member): private ListView mlist; Bind variable in oncreate() method What s wrong with this: public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button b = (Button) findviewbyid(r.id.button); setcontentview(r.layout.main); }

Gotchas If you need to access a view in more than one method: Have a class variable prefixed with m (for member): private ListView mlist; Bind variable in oncreate() method What s wrong with this: public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button b = (Button) findviewbyid(r.id.button); setcontentview(r.layout.main); }

Gotchas If you need to access a view in more than one method: Have a class variable prefixed with m (for member): private ListView mlist; Bind variable in oncreate() method You must first call setcontentview() before findviewbyid will work!

Getting/Setting Fields Once we have a reference to a widget, accessing fields is fairly simple: EditText textfield = String text = textfield.gettext().tostring(); textfield.settext( Hello ); textfield.settextcolor(color.red);

Interlude Anonymous Inner Classes Consider the (generic) Java method: Arrays.sort(T[] a, Comparator<T> c) Comparator interface: int compare(t o1, T o2) Return 0 if equal, -1 if o1 < o2, 1 if o1 > o2 How should we construct an instance of Comparator?

Anonymous Inner Classes class Pair { int x, y; boolean equals(object other) {... }... } class PairComparator implements Comparator<Pair> { int compare(pair p1, Pair p2) { if (p1.equals(p2)) return 0; if (p1.x < p2.x p1.x == p2.x && p1.y < p2.y) return -1; else return 1; } } Arrays.sort(Pair[] pairs, new PairComparator());

Anonymous Inner Classes class Pair { int x, y; boolean equals(object other) {... }... } Arrays.sort(Pair[] pairs, new Comparator<Pair>() { int compare(pair p1, Pair p2) { if (p1.equals(p2)) return 0; if (p1.x < p2.x p1.x == p2.x && p1.y < p2.y) return -1; else return 1; } });