Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.

Slides:



Advertisements
Similar presentations
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
Advertisements

Android User Interface
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Development (Basics)
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Android: Layouts David Meredith
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
1 Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources, Listener 10/9/2012 Y. Richard Yang.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Introducing the Sudoku Example
CS5103 Software Engineering Lecture 08 Android Development II.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
CE Applied Communications Technology Android lecture 2 - Structures Android File structure Resources Drawables Layout Values R Class Manifest Running.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
Themes and Menus: The Sudoku Example Content taken from book: “Hello, Android” by Ed Burnette Third Edition.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
MOBILE COMPUTING D10K-7D02 MC05: Android UI Design Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
Building User Interfaces Basic Applications
More App Customizations. Overview  Application/ Activity Customizations: Themes  Menu Customizations  Custom Dialogs  Custom Toasts  Custom Buttons.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
Http :// developer. android. com / guide / topics / fundamentals. html.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Chapter 2: Simplify! The Android User Interface
Lab7 – Appendix.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Application Development 1 6 May 2018
Android N Amanquah.
GUI Programming Fundamentals
Android – Event Handling
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
Android Introduction Hello World.
Mobile Application Development BSCS-7 Lecture # 8
Android Widgets 1 7 August 2018
ITEC535 – Mobile Programming
Politeknik Elektronika Negeri Surabaya
תכנות ב android אליהו חלסצ'י.
CIS 470 Mobile App Development
Building User Interfaces Basic Applications
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
CIS 470 Mobile App Development
Mobile Programmming Dr. Mohsin Ali Memon.
Android Sensor Programming
Presentation transcript:

Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld

Overview  Deconstructing HelloWorld  User Interface  View Hierarchy  Layout (XML)  Load XML Resource  Layout (Output)  Widgets

Typical Android Applications  Typical Android applications are composed of 4 main parts  Code definition  UI definition  Values definition  Manifest definition

HelloWorld package edu.ateneo.ajwcc.android; import android.app.Activity; import android.os.Bundle; public class KumustaMundoActivity extends Activity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); }

Not much there is there…  Majority of Android’s UI definition is done using XML files  Allows clean separation between the UI design and the code  Code’s main job is to store control logic  Widget event-handling  Activity Life Cycle methods (like onCreate)

HelloWorld XML Layout <LinearLayout xmlns:android=" m/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" /> Found in the res > layout folder

Android: User Interface  Built using View and ViewGroup objects  View = base for subclasses called widgets  Widgets = text fields, buttons, etc  ViewGroup = base for subclasses called layouts  Layouts = linear, tabular and relative (layout architectures)

Android: View Hierarchy  To attach View Hierarchy to the screen (for rendering), must call setContentView() in your Activity.  Android parses hierarchy tree from the top  In case of overlaps, Draw Order = “last one to be drawn will lie on top of others previously drawn to that space”

Android: Declaring UI Layout  2 ways:  “Declare UI elements in XML”  “Instantiate layout elements at runtime” (programmatically)  You can use either or both!  Advantage in using both:  XML can handle presentation (ala View in MVC)  Code can handle behavior of UI elements (ala Controller in MVC)

Widgets  Android has many widgets (simple and complex) built-in to it  Buttons  Textfields  ListView  ImageViews  Each widget has a programmatic and XML representation

Layouts  Android has many layouts (simple and complex) built-in to it  Linear  Relative  Tabular  Like widgets, each layout has a programmatic and XML representation

More Later  Specific Widget and Layouts will be discussed later in a separate slideset  Additional information can also be found in the Android documentation found with the SDK

values  Hard-coded strings are never a good thing in an application  Hard to change especially if used in several places  Forces a recompile of the application  NOT GOOD  Used for text localization  Changing text for different languages

Strings.xml Hello World, HelloWorldActivity! HelloWorld Found in the res > values folder

drawables  Like strings, hard-coded image paths are not recommended  For the same reasons as hard-coded strings  Images can be placed in the res/drawable-xxx  They can be referenced using their name (minus the extension)  Caveat: name must be all lowercased to be safe

Manifest file  The Manifest file contains information about  Activities – screens that are part of your app  Also defines the entry point activity  Permissions – all the special permissions required by the app  E.g. accessing the network, sms, etc  Can access the stuff in the /res by using marker

Sample <manifest xmlns:android=" package="admu.edu.cs119" android:versionCode="1" android:versionName="1.0"> <activity android:name=".HelloWorldActivity" This intent-filter marks the entry point of your application

Activities  Activities define the available screens that will be used in the your application  Activities have complex life-cycles that are controlled by events that occur on the phone such as being put in the background, calls, changing orientation, etc.  onCreate() is the life-cycle method for initializing the activity  More on Activities later

Customizing HelloWorld  Quickest way to customize HelloWorld is to change the widgets inside it  Editing XML layout is one way to achieve this  Another is to programmatically instantiate a view (like a TextField) and use it as the contentView

Programmatic customization public class HelloWorldActivity extends Activity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); TextView tv = new TextView(this); tv.setText("*\n*\n**\n***"); setContentView(tv); }

Android: Layout (XML) <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a TextView" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a Button" /> Save this as main_layout.xml in your project’s res > layout folder

Android: Layout (Output)

Android: Layout What’s the difference between: wrap_content and fill_parent ?

Android: Widgets  = View object that a user interacts with.  Ex: Buttons, TextView, EditText, RadioButton, CheckBox  You can create your own custom widgets!  How? Extend existing View class or subclass

Android: UI Events  To determine whether a user has interacted with your UI (so you can perform appropriate actions)  Either of these 2 things: 1) “Define an event listener and register it with the View” - onClickListener(), setOnClickListener(…) 2) “Override an existing callback method for View” - onTouchEvent(), onKeyDown()…

Retrieving Views from the XML  When you define views inside an XML there are times you need to pull one of them out  To do this you will need to supply an id to the view  Using in the view  E.g.  This view may then be retieved using findViewById(int id)

IDs  Ids are special in Android, they are auto- generated so you can use Eclipse auto-complete to use them  These are stored in the auto-generated R file  Your project package has a specific R file associated to it  E.g. admu.edu.cs119.R  Make sure you have imported the correct one

Android: UI Events (Java) public void initUIEventHandling() { myTextView = (TextView)findViewById(R.id.my_textview); myButton = (Button)findViewById(R.id.my_button); myButton.setOnClickListener(new OnClickListener() public void onClick(View v) { myTextView.setText("Button clicked!"); } }); } Be sure that you have my_textview and my_button ids in the XML layout that you attached to your Activity using setContentView(…)!

Android: UI Events (Output)

Android: Menus  Option Menus (most common)  revealed by pressing MENU key in the device  onCreateOptionsMenu()  onOptionsItemsSelected()  Context Menus  revealed when users presses and holds down an item  onCreateContextMenu()  onContextItemsSelected() “Menus also handle their own events, so there’s no need to register event listeners on the items in your menu.” You can declare your menu items in XML!

Android: Menus (XML) <menu xmlns:android=" res/android" > <item android:title="Start" /> <item android:title="Quit" />

Android: Menus (Java) public class MenuActivity extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu); public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.my_menu, menu); return true; public boolean onOptionsItemSelected(MenuItem item) { //Handle item selection using item.getItemId() return; } For R.menu.my_menu, create in res folder a “menu” folder in the same level as “layout”, etc

Sample menu public boolean onOptionsItemSelected(MenuItem item) { //Handle item selection using item.getItemId() switch(item.getItemId()) { case id.start: break; case id.quit: break; } return true; } A Toast is a small pop-up message that appears then vanishes

Android: Menus (Output)

Android: Styles and Themes  Styles ≈ Cascading Style Sheets (CSS) in HTML  “collection of properties that specify look and format for a View…”  layout_width, layout_height, background, font size, font color, padding, …  Themes = style applied to an entire Activity or Application (rather than an individual View)

Android: Styles and Themes (XML) vertical center Save this XML file in /res/values/

Android: Styles and Themes (XML) <LinearLayout xmlns:android=" You can put your style in your Layout or View using style=“...". You can also put it in the Activity or Application itself using android:theme=“...".

Android: Styles and Themes (Output) Now, whenever the appearance of your Layouts, Views, etc change, you’ll only need to update Styles! Cool, eh?