EMBEDDED SYSTEMS PROGRAMMING UI and Android

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

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

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

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

CHAPTER 4. Fragments ActionBar Menus

UI Fragment.

Mobile Development Lecture 10: Fragments

Mobile Application Development - Android

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

EMBEDDED SYSTEMS PROGRAMMING Application Basics

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

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

Fragments and the Maps API

How to support multiple screens using android? Synopsis

CS378 -Mobile Computing. More UI -Part 2

CS 403X Mobile and Ubiquitous Computing Lecture 3: Introduction to Android Programming Emmanuel Agu

Fragments. Lecture 11

Fragments. Lecture 10

Mobile Application Development Android

Designing and Implementing Android UIs for Phones and Tablets

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

Lecture 2 Android SDK

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

Mobile Computing Fragments

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

getcount getitem getitemid getview com.taxi Class MainActivity drawerlayout drawerleft drawerright...

Building User Interface for Android Mobile Applications II

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

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

Android Application Model I

Produced by. Mobile Application Development. Eamonn de Leastar David Drohan

TextView. A label is called a TextView. TextViews are typically used to display a caption TextViews are not editable, therefore they take no input

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

CS 4330/5390: Mobile Application Development Exam 1

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

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

Login with Amazon. Getting Started Guide for Android apps

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

MC Android Programming

Android Basics. Android UI Architecture. Android UI 1

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

Chapter 2 Welcome App

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

Mobile Application Workbench. SAP Mobile Platform 3.0 SP02

MATERIAL DESIGN. Android Elective Course 4th Semester. June 2016 Teacher: Anders Kristian Børjesson. Ovidiu Floca

Action Bar. (c) 2010 Haim Michael. All Rights Reserv ed.

Android User Interface Overview. Most of the material in this sec7on comes from h8p://developer.android.com/guide/topics/ui/index.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

The drawable/tile empty.xml file

Topics of Discussion

UI (User Interface) overview Supporting Multiple Screens Touch events and listeners

CS 4518 Mobile and Ubiquitous Computing Lecture 3: Android UI Design in XML + Examples. Emmanuel Agu

Android. The Toolbar

Android & iphone. Amir Eibagi. Localization

ListView Containers. Resources. Creating a ListView

Activities and Fragments

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

Android CardView Tutorial

ANDROID SERVICES, BROADCAST RECEIVER, APPLICATION RESOURCES AND PROCESS

Orientation & Localization

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

CMSC 436 Lab 10. App Widgets and Supporting Different Devices

CS378 -Mobile Computing. What's Next?

ANDROID APPS (NOW WITH JELLY BEANS!) Jordan Jozwiak November 11, 2012

LECTURE 08 UI AND EVENT HANDLING

ANDROID USER INTERFACE

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Introduction To JAVA Programming Language

CE881: Mobile & Social Application Programming

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

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

ORACLE UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

(Refer Slide Time: 1:12)

UI, Continued. CS 2046 Mobile Application Development Fall Jeff Davidson CS 2046

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

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

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

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

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

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

EMBEDDED SYSTEMS PROGRAMMING Android Services

User Interfaces for Web Sites and Mobile Devices. System and Networks

Mobile Computing Practice # 2c Android Applications - Interface

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

Android Programming (5 Days)

EMBEDDED SYSTEMS PROGRAMMING Android NDK

COLLEGE OF ENGINEERING, NASHIK-4

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

INTRODUCTION TO ANDROID

Android UI DateBasics

Android Application Development

Understanding Application

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

05. RecyclerView and Styles

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

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

ES E 3 3 L a L b 5 Android development

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

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

Transcription:

EMBEDDED SYSTEMS PROGRAMMING 2016-17 UI and Android

STANDARD GESTURES (1/2) UI classes inheriting from View allow to set listeners that respond to basic gestures. Listeners are defined by suitable interfaces. boolean ontouch(view v, MotionEvent event) Part of the View.OnTouchListener interface. The user has performed an action qualified as a touch event, including a press, a release, or any movement gesture on the screen (within the bounds of the item). void onclick(view v) Part of the View.OnClickListener interface. The user has touched the item boolean onlongclick(view v) Part of the View.OnLongClickListener interface. The user has touched and holds the item

EXAMPLE

STANDARD GESTURES (2/2) Standard UI widgets respond to standard gestures (e.g., a ListView responds to a flick) Custom UI widgets can handle touch screen motion events by implementing the ontouchevent(motionevent event) method; no gesture recognizer is provided

SUPPORTING DIFFERENT SCREENS (1/3) Mobile platforms support a variety of devices with different screen sizes and resolutions Resolution does not cont that much: it is size that matters Bigger screens can accommodate more information than smaller screens Tablet screens can accommodate more information than other screens

SUPPORTING DIFFERENT SCREENS (2/3) Different screen sizes may require different artwork Different screen sizes typically require different UIs Use more / resize conventional UI elements Introduce new UI elements that are specifically designed for tablets

SCREENS: ANDROID Tens of locales (e.g., -en-rus), device dependent Four generalized screen sizes: small (-small), normal (-normal), large (-large), extra large (-xlarge) Two variations of each screen size: portrait (-port), landscape (-land) Four generalized screen densities: 120 DPI (-ldpi), 160 DPI (-mdpi), 240 DPI (-hdpi), 320 DPI (-xhdpi), 480 DPI (-xxhdpi), 640 DPI (-xxxhdpi) Place resources in the appropriate folder: Android will use them

SCREENS: EXAMPLES Directory for default layouts: res/layout Directory for layouts that target large screens and the landscape orientation: res/layout-large-land Directory for default artwork: res/drawable Directory for artwork that target US-English devices in landscape orientation: res/drawable-en-rus-land For a full list of directories and modifiers, look up the Providing resources page in the Android documentation Always provide default resources (i.e., a folder with no modifiers)

TABLETS: ANDROID Up to version 2.3 (API level 10): no support for tablets 3.x versions (11 API level 13): run only on tablets Version 4.0 and above (API level 14): unified support for tablets and other devices

MULTI-PANE LAYOUTS From developer.android.com: The most effective way to create a distinct user experience for tablets and handsets is to [...] design multi-pane layouts for tablets and single-pane layouts for handsets = +

SUPPORTING DIFFERENT SCREENS (3/3) Implement flexible layouts and provide multiple version of relevant resources Design activities using fragments Use the action bar

FRAGMENT CLASS Android 3.0+ (API level 11+) Represents a portion of user interface Hosted by an activity: to be precise, it lives in a ViewGroup inside the activity s view hierarchy, albeit it defines its own view layout and has its own lifecycle callbacks Each fragment can be manipulated independently from other fragments

FRAGMENT: LIFECYCLE A class derived from Fragment behaves similarly to an activity. It includes lifecycle callback methods (oncreate(), etc.) Two additional methods: oncreateview() and ondestroyview() Lifecycle callback methods must be invoked by the hosting activity Image from Android Developer

HOSTING A FRAGMENT Declarative approach: add the fragment to the layout file of the hosting activity Programmatic approach: add the fragment in the source code of the hosting activity; instantiate the UI in the oncreateview() method of the fragment

ONCREATEVIEW, ONDESTROYVIEW METHODS View oncreateview(layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) Instantiates the UI for a fragment and attaches it to container An implementation for oncreateview() must be provided by the programmer If the UI is defined in an XML file, the system-provided LayoutInflater can be used to instantiate ( inflate ) it void ondestroyview() Destroys a previously-created user interface

FRAGMENTMANAGER: TWO KEY METHODS An instance of the FragmentManager class allows interaction with fragments. For instance, it allows to add or remove a fragment (via a fragment transaction) Fragment findfragmentbyid(int id) Returns the fragment which is identified by the given id (as specified, e.g., in the XML layout file) FragmentTransaction begintransaction() Start editing the Fragments associated with the FragmentManager. The transaction is ended by invoking the commit() method of FragmentTransaction

HOSTING A FRAGMENT: EXAMPLE (1/2) Declarative approach 2 fragments declared inside the layout of an activity. When the activity is created, instances of the classes associated with the fragments are automatically allocated

HOSTING A FRAGMENT: EXAMPLE (2/2) Programmatic approach Initiate a fragment transaction, instantiate a fragment, then add it to a suitable ViewGroup

Example from Android Developers FRAGMENTS: EXAMPLE (1/4) Big screen (tablet) Small screen (phone) Activity MainActivity Activity MainActivity Activity DisplayActivity DisplayActivity is started only if the screen is small. It hosts fragment DetailsFragment MainActivity always manages fragment TitlesFragment and, depending on the screen size, hosts DetailsFragment as well or starts DisplayActivity

FRAGMENTS: EXAMPLE (2/4) Layout for MainActivity, big screen Resides in res/layout-large/ Both fragments are hosted by MainActivity

FRAGMENTS: EXAMPLE (3/4) Layout for MainActivity, small screen Resides in res/layout/ DisplayFragment is hosted by DisplayActivity

FRAGMENTS: EXAMPLE (4/4) Code snippet from the MainActivity class

ACTION BAR Picture: Android Design UI component that can contain, from left to right, 1. the application icon, 2.the view control (tabs or a spinner), 3.a certain number of action items, 4. the action overflow menu button May also contain a hint to the navigation drawer

Picture: Android Design APP BAR New name for the action bar in Android 5.0+ The nav icon, if present can be: an arrow for navigating the app s hierarchy a control to open a navigation drawer

Pictures: Android Design NAVIGATION DRAWER Displays the main navigation options for the app Appears from the left side of the screen by clicking on the application icon

OVERFLOW MENU Groups action items that are not important enough to be prominently displayed in the action bar Duplicates the functionality of the option menu + the (hardware) menu button In Android 4.0+, developers are strongly encouraged to migrate to the overflow menu Image from Android Design

SPLIT ACTION BAR Depending on the screen size, content may be split across multiple action bars: 1.main action bar, 2.top bar, 3.bottom bar Picture: Android Design

ADDING THE ACTION BAR Beginning with Android 3.0, an action bar is created by default for every application that declares a targetsdkversion of 11 or greater in its manifest

ACTION BAR: ADDING ITEMS The action bar can be populated in the oncreateoptionsmenu() activity method, which is called when the activity starts Action items and overflow menu items are managed together as a menu resource. The onoptionsitemselected() activity method is called whenever an item is selected by the user If the action bar is constrained for space, some action items can be moved to the overflow menu

SUPPORT LIBRARY PACKAGE (1/2) Provides static libraries that can be added to an Android app in order to use APIs that are either not available on older platform versions, or not part of the framework APIs Each library runs only on devices that provide at least a minimum API level Must be installed from the SDK Manager

Picture: Android Developers MULTIPLE WINDOWS (1/3) Android 7.0+ (API level 24+), any device Split-screen mode: two activities at the same time

Picture: Android Police MULTIPLE WINDOWS (2/3) Android 7.0+, if supported by device manufacturer Freeform mode: activities inside windows!

Picture: Android Authority MULTIPLE WINDOWS (3/3) Android 7.0+, any device Picture-in-picture mode: meant for video; pinned activity in a corner of the screen

SUPPORTING MULTIPLE WINDOWS (1/2) For apps targeting API level 24+, support is set per-component or per-app via manifest s attributes android:resizeableactivity If set to true (default), allows split-screen and freeform modes android:supportspictureinpicture If set to true, and resizeableactivity=true, allows picture-in-picture mode android:minheight, android:minwidth Minimum supported height & width for the activity in both split-screen and freeform modes

SUPPORTING MULTIPLE WINDOWS (2/2) New methods in classes Activity, Fragment, void onmultiwindowmodechanged (boolean isinmultiwindowmode) Called by the system when the component changes from fullscreen mode to multi-window mode and vice versa void onpictureinpicturemodechanged (boolean isinpictureinpicturemode) Called by the system when the component changes to/from picture-in-picture mode void enterpictureinpicturemode() Enters picture-in-picture mode

MULTI-WINDOW LIFECYCLE The activity lifecycle as a whole remains the same Only one activity is active, the others are paused (in PIP mode, a paused activity must play video!) Every resize is a configuration change (by default, activity killed and re-created!) While activities are sharing the screen, users can drag and drop data from one activity to another

SUPPORT LIBRARY PACKAGE (2/2) v4 Support Library Minimum API level: 4 (Android 1.6+) Provides support for fragments and navigation drawers v7 Appcompat Library Minimum API level: 7 (Android 2.1+) Provides support for action bars More libraries available

SUPPORT LIBRARY: FRAGMENTS android.support.v4.app.fragment, android.support.v4.app.fragmentactivity and android.support.v4.app.fragmentmanager classes, to name a few, re-implement fragment support Use such classes to write a single piece of code that runs on any API level 4 Host your fragments inside a FragmentActivity To get the FragmentManager, invoke getsupportfragmentmanager()

REFERENCES Android User Interface Supporting Different Screens Supporting Tablets and Handsets Building a Dynamic UI with Fragments Designing for Multiple Screens Designing for Seamlessness

LAST MODIFIED: MAY 12, 2017 COPYRIGHT HOLDER: CARLO FANTOZZI (FANTOZZI@DEI.UNIPD.IT) LICENSE: CREATIVE COMMONS ATTRIBUTION SHARE-ALIKE 4.0