Android UI Development

Similar documents
ANDROID USER INTERFACE

Graphical User Interfaces

Comparative Study on Layout and Drawable Resource Behavior in Android for Supporting Multi Screen

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

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

Android Basics. Android UI Architecture. Android UI 1

Create Parent Activity and pass its information to Child Activity using Intents.

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Our First Android Application

Android UI: Overview

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

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

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

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

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

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

Laying Out Controls in Containers

Introduction to Android Development

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

Mobile Software Development for Android - I397

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

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

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

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

Sizing and Positioning

INTRODUCTION TO ANDROID

Produced by. Mobile Application Development. Eamonn de Leastar

South Africa

Android Programming Lecture 2 9/7/2011

Fragments. Lecture 11

Fragment Example Create the following files and test the application on emulator or device.

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

COMP61242: Task /04/18

GUI Widget. Lecture6

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Android Application Development. By : Shibaji Debnath

Android HelloWorld - Example. Tushar B. Kute,

Intents. Your first app assignment

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

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

Mobile Application Development Android

Chapter 2 Welcome App

User Interface Development in Android Applications

Introductory Android Development

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

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

Android Layout Types

Basic GUI elements - exercises

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

Created By: Keith Acosta Instructor: Wei Zhong Courses: Senior Seminar Cryptography

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

ANDROID PROGRAMS DAY 3

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

A Crash Course to Android Mobile Platform

An Overview of the Android Programming

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

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

Android - JSON Parser Tutorial

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

Stanislav Rost CSAIL, MIT

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

PROGRAMMING APPLICATIONS DECLARATIVE GUIS

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Mobile Programming Lecture 1. Getting Started

Mobile User Interfaces


<uses-permission android:name="android.permission.internet"/>

ANDROID APP DEVELOPMENT

Upon completion of the second part of the lab the students will have:

Notification mechanism

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

Creating a User Interface

Arrays of Buttons. Inside Android

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

When programming in groups of people, it s essential to version the code. One of the most popular versioning tools is git. Some benefits of git are:

Android Beginners Workshop

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

Embedded Systems Programming - PA8001

LifeStreet Media Android Publisher SDK Integration Guide

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

Android Workshop: Model View Controller ( MVC):

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

Text Properties Data Validation Styles/Themes Material Design

TPCT s College of Engineering, Osmanabad. Laboratory Manual SDL-II. Mobile Application Development (Android) For. Third Year Students (CSE)

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Getting Started With Android Feature Flags

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

Android Application Development

Chapter 8 Positioning with Layouts

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Android Navigation Drawer for Sliding Menu / Sidebar

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

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

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Adaptation of materials: dr Tomasz Xięski. Based on presentations made available by Victor Matos, Cleveland State University.

Let s take a display of HTC Desire smartphone as an example. Screen size = 3.7 inches, resolution = 800x480 pixels.

Transcription:

Android UI Development Android UI Studio Widget Layout Android UI 1

Building Applications A typical application will include: Activities - MainActivity as your entry point - Possibly other activities (corresponding to multiple screens) Views - Screen layouts - ViewGroups containing Views (i.e. components) Intents - required if you have multiple Activity screens Android UI 2

Android Development Environment 1. Install Android Studio, and run it https://developer.android.com/studio/install.html 2. Don t import previous settings 3. Choose install standard type Android UI 3

Create new project project component - Company Domain - only important if you release your app, can just use something like: cs349.uwaterloo.ca Need to choose which API to target - We ll use API 15 for phone and Tablet (need not to support the other devices) Android UI 4

Create new project - Activity templates - For the assignment, choose Empty Activity Android UI 5

Create Android Virtual Device (ADV) For testing - Device: Pixel - System: Android 8 x86 (Oreo API 26) download Android UI 6

Android Virtual Device (AVD) - The AVD is slow to launch, so keep it running in the background while you re programming / debugging. Android UI 7

Run sample code File -> Open -> select android/simple Run Select Deployment Target -> Pixel API 26 (the one just created) Android UI 8

Code Demo: Simple (Android Project Files) Manifest (app/manifests/) - Application setting Java (app/java/) - (*.java) source code Resources (app/res/) - layout: (*.xml) UI layout and View definitions - values: (*.xml) constants like strings, colours, - also bitmaps and SVG images (mipmap*, drawable*,.) Android UI 9

Manifest Metadata about the app App components, Intent filters <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> Android UI 10

Manifest Permissions - <manifest> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.send_sms" /> </manifest> Android must request permission to access sensitive user data Android UI 11

App Resources Each type of resource in a specific subdirectory of your project's res/ directory Access them using resource IDs that are generated in the project's R class app/ manifest/ java/ res/ drawable/ layout/ mipmap/ values/ graphic.png activity_main.xml icon.png strings.xml Android UI 12

Layouts Defines the structure for a user interface in your app Can be nested Android UI 13

Editing XML: WYSIWYG Version Android UI 14

Editing XML: XML Version Android UI 15

Layout Example <RelativeLayout xmlns: android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/edittextname android:layout_alignparenttop="true android:layout_margintop="30dp" android:ems="12" android:text="@string/name /> <Button android:id="@+id/btnconfirm" android:layout_below="@+id/edittextname" android:layout_margintop="40dp" android:text="@string/confirm" /> </RelativeLayout> Android UI 16

Layout When you compile your app, each XML layout file is compiled into a View resource calling setcontentview(), passing it the reference to your layout resource in the form of: R.layout.layout_file_name. app/java/mainactivity.java protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } Android UI 17

View (Widget) Properties: Background color, text, font, alignment, size, padding, margin, etc Event Listeners and Handlers: respond to various events such as: click, long-click, focus change, etc. Set focus: Set focus on a specific view requestfocus() or use XML tag <requestfocus /> Visibility: You can hide or show views using setvisibility( ). Android UI 18

Views: TextViews <TextView android:id="@+id/txthello" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello World!" /> TextView hellotextview = findviewbyid(r.id.txthello); hellotextview.settext("cs349 W18"); Android UI 19

Views: EditText <EditText android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content android:inputtype="textpersonname" android:text= @string/name > <requestfocus/> <EditText/> EditText nameview = findviewbyid(r.id.name); Text name = nameview.gettext().tostring(); Android UI 20

Views: Buttons <Button android:id="@+id/btnalarm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/alarm" /> https://developer.android.com/guide/topics/ui/controls/button.html Android UI 21

Responding to Button Events Option 1 <Button android:id="@+id/btnalarm" android:onclick="sendmessage"/> /** Called when the user touches the button */ public void sendmessage(view view) { // Do something in response to button click } Option 2 Button button = (Button) findviewbyid(r.id.btnalarm); button.setonclicklistener(new View.OnClickListener() { public void onclick(view v) { // Do something in response to button click } }); Android UI 22

Radio Buttons <RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/radio_yes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:weight= 1" android:onclick="onradiobuttonclicked" android:text="@string/yes" /> <RadioButton android:id="@+id/radio_no" android:layout_width="wrap_content" android:layout_height="wrap_content" android:weight= 1" android:onclick="onradiobuttonclicked" android:text="@string/no" /> </RadioGroup> Android UI 23

Radio Buttons public void onradiobuttonclicked(view view) { // Is the button now checked? boolean checked = ((RadioButton) view).ischecked(); } // Check which radio button was clicked switch (view.getid()) { case R.id.radio_yes: if (checked) // code for yes break; case R.id.radio_maybe: if (checked) // code for may be break; case R.id.radio_no: if (checked) // code for no break; } Android UI 24

Checkboxes <CheckBox android:id="@+id/checkbox_morning" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="oncheckboxclicked" android:text="@string/morning" /> <CheckBox android:id="@+id/checkbox_afternoon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="oncheckboxclicked" android:text="@string/afternoon" /> https://developer.android.com/guide/topics/ui/controls/checkbox.html Android UI 25

Checkboxes public void oncheckboxclicked(view view) { // Is the view now checked? boolean checked = ((CheckBox) view).ischecked(); // Check which checkbox was clicked switch (view.getid()) { case R.id.checkbox_morning: if (checked) // Add morning session else // Remove morning session break; case R.id.checkbox_afternoon: if (checked) // Add afternoon session else // Remove afternoon session break; } } https://developer.android.com/guide/topics/ui/controls/checkbox.html Android UI 26

ImageView Save image resources to drawable folder - app/src/main/res/drawable/ <ImageView android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="wrap_content android:text="@drawable/lollipop" /> Android UI 27

Linear Layout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. All children of a LinearLayout are stacked one after the other - a vertical list will only have one child per row, no matter how wide they are - a horizontal list will only be one row high https://developer.android.com/guide/topics/ui/layout/linear.html Android UI 28

Key Attributes Orientation Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column. Fill model MATCH_PARENT: the view wants to be as big as its parent WRAP_CONTENT: the view wants to be just large enough to fit its own internal content Weight android:layout_weight attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. Android UI 29

Attributes gravity Specifies how an object should position its content, on both the X and Y axes (top, bottom, center, ) Padding/margin Setting padding/margin Android UI 30

LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="16dp" android:paddingright="16dp" android:orientation="vertical" > <EditText /> <EditText /> <Button /> </LinearLayout> Android UI 31

LinearLayout <LinearLayout > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/to" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/subject" /> <EditText android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="top" android:hint="@string/message" /> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/send" /> </LinearLayout> Android UI 32

Relative Layout RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as - relative to sibling elements (such as to the left-of or below another view) - in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center). https://developer.android.com/guide/topics/ui/layout/linear.html Android UI 33

View Positioning RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). By default, all child views are drawn at the top-left of the layout Example of some layout properties : - android:layout_alignparenttop - android:layout_centervertical - android:layout_below - android:layout_torightof - More: RelativeLayout.LayoutParams https://developer.android.com/guide/topics/ui/layout/linear.html Android UI 34

View Positioning in Relative Layout android:layout_above android:layout_below Widget 2 Widget 1 Widget 1 Widget 2 android:layout_toleftof android:layout_torightof Widget 2 Widget 1 Widget 1 Widget 2 android:layout_alignbottom android:layout_aligntop Widget 1 Widget 2 Widget 1 Widget 2 android:layout_alignleft android:layout_alignright Widget 1 Widget 2 Widget 1 Widget 2 Android UI 35

Relative layout alignment parameters android:layout_alignparenttop android:layout_alignparentbottom android:layout_alignparentleft android:layout_alignparentright android:layout_centerinparent android:layout_centervertical android:layout_centerhorizontal Android UI 36

Relative Layout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="16dp" android:paddingright="16dp" > <EditText /> <Spinner /> <Spinner /> <Button /> </RelativeLayout> Android UI 37

<RelativeLayout <EditText android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content /> <Spinner android:id="@id/times" android:layout_width="96dp" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_alignparentright="true" /> <Spinner android:layout_width="0dp" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_toleftof="@+id/times android:layout_alignparentleft="true /> <Button android:layout_width="96dp" android:layout_height="wrap_content" android:layout_below="@id/times" android:layout_alignparentright="true" android:text="@string/done" /> </RelativeLayout> Android UI 38

Nested Layout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/name_title" Views android:text= @string/name"> </EditText> <LinearLayout android:layout_below="@+id/session"> <CheckBox android:id="@+id/checkbox_morning" android:text="@string/morining /> <CheckBox /> </LinearLayout> </RelativeLayout> Views Android UI 39

Constraint Layout Similar to RelativeLayout - All views are laid out according to relationships with others Easier to use with Android Studio s Layout Editor - Default layout for a new layout https://developer.android.com/training/constraint-layout/ index.html Android UI 40

Layout test Check the layout with multiple screen sizes Android UI 41

Code Demo: WidgetDemo Notes - TextView - EditText - RadioButton - CheckBox - Spinners - Relative Layout - Linear Layout - Nested Layout Android UI 42

Tips & Tricks Use the debugging tools in Android Studio - You can set breakpoints etc. as usual - logcat shows device output and you can write to it using the android.util.log class (sim. to printf). Use Build->Clean Project for remove unnecessary files. - This sometime helps to fix errors Android UI 43