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

Similar documents
ANDROID APPS DEVELOPMENT FOR MOBILE GAME

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

04. Learn the basic widget. DKU-MUST Mobile ICT Education Center

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

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

Lab 1 - Setting up the User s Profile UI

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

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

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

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

Android User Interface Android Smartphone Programming. Outline University of Freiburg

Creating a User Interface

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

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

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

Android User Interface

CS378 -Mobile Computing. User Interface Basics

ANDROID USER INTERFACE

LECTURE 08 UI AND EVENT HANDLING

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

Building User Interface for Android Mobile Applications II

CS371m - Mobile Computing. User Interface Basics

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

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

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

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

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

Android Programming (5 Days)

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

Mobile User Interfaces

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

Stanislav Rost CSAIL, MIT

MC Android Programming

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

Required Core Java for Android application development

GUI Widget. Lecture6

Android Basics. Android UI Architecture. Android UI 1

Embedded Systems Programming - PA8001

ConstraintLayouts in Android

Android UI Development

Mobile Application Development Android

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

Fragments. Lecture 11

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

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

Android UI: Overview

Fragments. Lecture 10

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

Android Programming Lecture 2 9/7/2011

Introduction to User Interface Elements in Android

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Java Training Center - Android Application Development

Introductory Android Development

Produced by. Mobile Application Development. Eamonn de Leastar

Programming in Android. Nick Bopp

South Africa

In this Class Mark shows you how to put applications into packages and how to run them through the command line.

Syllabus- Java + Android. Java Fundamentals

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

Mobile Programming Lecture 1. Getting Started

PROGRAMMING FUNDAMENTALS

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

Graphical User Interfaces

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

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

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

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

14.1 Overview of Android

Responsive mobile design in practice. Kirill Grouchnikov Android, Google Inc.

ListView Containers. Resources. Creating a ListView

CSC Java Programming, Fall Java Data Types and Control Constructs

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Beginning Android 4 Application Development

Spring Lecture 4 Lecturer: Omid Jafarinezhad

Android Development Crash Course

CS 528 Mobile and Ubiquitous Computing Lecture 2: Intro to Android Programming Emmanuel Agu

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

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

CS 528 Mobile and Ubiquitous Computing Lecture 2: Intro to Android Programming Emmanuel Agu

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

Mumbai Android Bootcamp -Course Content

Designing and Implementing Android UIs for Phones and Tablets

ORACLE UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

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

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Diploma in Android Programming (DAP)

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

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

Chapter 2 Welcome App

Programming Android UI. J. Serrat Software Design December 2017

Practical Problem: Create an Android app that having following layouts.

This lecture. The BrowserIntent Example (cont d)

Android Application Development

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

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

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

2. The object-oriented paradigm

INTRODUCTION TO ANDROID

The drawable/tile empty.xml file

Creating Workflows. Viewing the Task Library. Creating a Workflow. This chapter contains the following sections:

Transcription:

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I) Application Components Hold the content of a message (E.g. convey a request for an activity to present an image) Lecture 2: Android Programming Foundation Present a visual user interface for one focused endeavor the user can undertake (E.g. list of menu items) Run in the background for an indefinite period of time (E.g. calculate and provide the result to activities that need it) Peter Lo Receive and react to broadcast announcements (E.g. announcements that the time zone has changed) Store and retrieve data and make it accessible to all applications (E.g. audio, video, images, etc.) 2 Simple Android App Layout Linear Layout A layout defines the visual structure for a user interface: Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. Instantiate layout elements at runtime. Your application can create View and ViewGroup objects programmatically. In a linear layout, all the elements are displayed in a linear fashion, either Horizontally or Vertically The properties is set in android:orientation which is an attribute of the node LinearLayout. Create Layout by Drag and Drug Create Layout by Typing XML 3 4

Relative Layout Table Layout In a relative layout every element arranges itself relative to other elements or a parent element. E.g. The Cancel button is placed relatively, to the right of the Login button parallel. Here is the code snippet that achieves the mentioned alignment Table layouts in Android works in the same way HTML table layouts work. You can divide your layouts into rows and columns. 5 6 Layout Attributes The View Hierarchy FILL_PARENT / MATCH_PARENT, which means that the view wants to be as big as its parent (minus padding) WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding) The view hierarchy diagram gives probably the clearest overview of the relationship between the various views that make up the user interface shown. When a user interface is displayed to the user, the Android runtime walks the view hierarchy, starting at the root view and working down the tree as it renders each view. 7 8

Event Listener TextView (Label) An object cannot process event on its own, it needs a listener for this. E.g. When a button is clicked, listener reacts and runs the code from onclick method. A label is called in android a TextView. TextViews are not editable, typically used for output to display a caption. Common Event onclick() onlongclick() onfocuschange() onkey() ontouch() 9 oncreatecontextmenu() 10 Button EditText (Text Field) A Button widget allows the simulation of a clicking action on a GUI. Button is a subclass of TextView, it styled using the system's default button background. Request a reference to the button from the activity by calling findviewbyid. EditText allows the user to type text (single text or multiline) into your app. Touching a text field places the cursor and automatically displays the keyboard. Request a reference to the button from the activity by calling findviewbyid. Create a class implementing OnClickListener and set it as the on click listener for the button. 11 Retrieve the EditText value and convert to string 12

Common InputType for EditText Radio Button text number phone textmultiline textcapcharacters Radio buttons allow the user to select one option from a set. You should use radio buttons for optional sets that are mutually exclusive if you think that the user needs to see all available options side-by-side. To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup. By grouping them together, the system ensures that only one radio button can be selected at a time textpassword textautocorrect 13 14 Handling Events in Radio Button Checkbox RadioButton radio0 = (RadioButton) findviewbyid(r.id.radio0); RadioButton radio1 = (RadioButton) findviewbyid(r.id.radio1); RadioGroup radiogroup1 = (RadioGroup) findviewbyid(r.id.radiogroup1); radiogroup1.setoncheckedchangelistener( new RadioGroup.OnCheckedChangeListener() { public void oncheckedchanged ( RadioGroup group, int checkedid ) { if ( checkedid == radio0.getid() ) { else if ( checkedid == radio1.getid() ) { ); Checkboxes allow the user to select one or more options from a set. Typically, you should present each checkbox option in a vertical list. To create each checkbox option, create a CheckBox in your layout. Because a set of checkbox options allows the user to select multiple items, each checkbox is managed separately and you must register a click listener for each one. 15 16

Handling Events in Checkbox Toast (Message) CheckBox checkbox1 = (CheckBox) findviewbyid(r.id.checkbox1); if (checkbox1.ischecked()) { else { Toast messages is a simple pop-up message for alerting users. The following code would generate a toast message: Toast.makeText(Context, Text, Duration).show(); CheckBox checkbox2 = (CheckBox) findviewbyid(r.id.checkbox2); if (checkbox2.ischecked()) { The context to use, usually your Application or Activity object by method getapplicationcontext() Duration for the message display: LENGTH_SHORT (2 seconds) LENGTH_LONG (3.5 seconds) else { The text to show on screen 17 18 ImageView and ImageButton Appendix 1: Variables ImageView and ImageButton are two Android widgets that allow embedding of images in your applications. Both are image-based widgets analogue to TextView and Button, respectively. A variable is a reserved location in your computer s memory that will allow the application to store data. Each widget takes an android:src or android:background attribute (in an XML layout) to specify what picture to use. Pictures are usually a reference to a drawable resource. It is often referred to as a container that we can pass data in to hold and then reuse the data throughout the application. Before using a variable we need to both Declare and Instantiate the variable 19 20

Declaring a variable Instantiating a Variable When declaring a variable the Android system will reserve a portion of the system s memory so that it can be used to store data. Variables can vary in size and type, so when declaring a variable we also state which data type to use. The system can then reserve an appropriate amount of memory and expect a certain type of data to fill that memory. // Declare a integer variable to store total quantity int TotalQuantity; In addition to declaring a variable we must also instantiate the variable. This means that we assign data to the variable. As with most programming languages, we use the equal sign to assign a value to a variable. On the left of the equal sign will be the variable name and on the right of the equal sign will be the value that is assigned to the variable. // Set the total quantity to 100 TotalQuantity = 100; 21 22 Primitive Data Types Appendix 2: Programming Control Structure Type Description Memory Size boolean True or False Varies 1bit to 4 bytes char Unicode characters 2 byte (16 bit) byte Integers -128 to 127 1 byte (8 bit) short Integers -32,768 to 32,767 2 byte (16 bit) int Integers -2,147,483,648 to 2,147,483,647 4 byte (32 bit) Three types of control structure, derived from structured programming: Sequences of instructions Selection of alternative instructions Iteration (repetition) of instructions long Integers -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 8 byte (64 bit) float Decimals 3.4e-038 to 3.4e+038 4 byte (32 bit) double Decimals 1.7e-308 to 1.7e+308 8 byte (64 bit) 23 24

The Sequence Structure The Selection Structure Directs computer to process program instructions in a particular order Also called the Decision Structure, Makes a decision and then takes appropriate action based on that decision. Set of step-by-step instructions that accomplish a task 25 26 The if-then-else Statement Switch Statement The if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. if ( condition is true ) { else { execute statement(s) if condition is true execute statement(s) if condition is false A switch statement is a common conditional decision structure. It passes in a variable to evaluate and compares it to each case. If the case value matches the test variable then the code within the case executes. A break will end the case. You can code as many cases as needed. switch ( expression ) { case 1: execute statement(s); break; case 2: execute statement(s); break; default: execute statement(s); break; 27 28

The Iteration Structure The while Loop Directs computer to repeat one or more instructions until some condition is met Also referred to as a Loop, Repeating or Iteration The while loop is one of the most common constructs in programming. A while loop is a control structure that allows you to repeat a task a certain number of times. while ( condition ) { execute statement(s) 29 30 The do while Loop The for Loop There is one crucial difference between the Do-While and While loop. In the While loop, the action is performed only if the condition is true. A Do-While loop, on the other hand, will run at least once because the body (Do) is executed before the condition (While) is tested. do { while ( condition ) execute statement(s) 31 A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Here is the flow of control in for loop: 1. The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables. 2. Next, the Boolean expression is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement past the for loop. 3. After the body of the for loop executes, the flow of control jumps back up to the update statement. This statement allows you to update any loop control variables. 4. The Boolean expression is now evaluated again. If it is true, the loop executes and the process repeats itself. After the Boolean expression is false, the loop terminates. For (initialization; condition is true; update) { execute statement(s) 32