CS499 – Mobile Application Development Fall 2012 Programming the Android Platform Application Fundamentals & Quick intro to XML & Anatomy of a Simple Android.

Slides:



Advertisements
Similar presentations
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Advertisements

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.
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.
Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android 101 Application Fundamentals January 29, 2010.
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
Client / Server Programming in Android Eclipse IDE Android Development Tools (ADT) Android SDK
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Introducing the Sudoku Example
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
DUE Hello World on the Android Platform.
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.
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.
Configuring Android Development Environment Nilesh Singh.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
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 App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
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.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Programming.
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 Introduction Hello World.
MAD.
CS499 – Mobile Application Development
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
ITEC535 – Mobile Programming
HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung
תכנות ב android אליהו חלסצ'י.
Mobile Device Development
Anatomy of an Android Application
Android SDK & App Development
CS323 Android Model-View-Controller Architecture
CIS 470 Mobile App Development
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
Android Notifications
Emerging Platform#3 Android & Programming an App
Chapter 5 Your Second Activity.
Android Sensor Programming
Presentation transcript:

CS499 – Mobile Application Development Fall 2012 Programming the Android Platform Application Fundamentals & Quick intro to XML & Anatomy of a Simple Android App

PART I – APPLICATION FUNDAMENTALS

Building an Application see

More Detailed Look Mix of user- generated and auto- generated Java compiled into a.dex file Generates a.apk file – this is what is installed on the device

Running an Application By default, each application executes as its own Linux process and is assigned a unique Linux user ID By default, each process runs its own virtual machine (dvm) Android manages process creation & shutdown – Starts process when any of the application’s components need to be executed – Shuts down when process no longer needed and system resources are required by another application

Application Components An app can have multiple entry points (i.e. not just a main() ) App comprises components that the system can instantiate and run as needed. Key component classes include: – Activities – Services – Broadcast receivers – Content providers

Activity Primary class for interacting with user – Usually implements a focused task – Usually involves one screenful of data Example: – Calculator – HelloAndroid

Service Runs in the background to perform long- running or remote operations Does not have a visual user interface Example: – Music player

Broadcast Receiver Component that listens for broadcast announcements (events) – Events implemented as Intent instances Does not have a visual user interface Example: – messaging (on SMS receipt)

Content Providers Store and retrieve data across applications Uses database-style interface Example: – Contacts

PART 2 – QUICK INTRO TO XML

Use of XML in Android SDK Used in a number of places as a specification language: – AndroidManifest.xml – describes the components and connections in an application – Layouts – use XML notation to describe VIEW- based user interfaces Sometimes can use a graphical tool rather than XML directly but it is useful to be able to understand the specifications

Ex: AndroidManifest.xml for HelloAndroid <manifest xmlns:android=" package=“cs499.examples.helloandroid" android:versionCode="1" android:versionName="1.0" > <application > <activity android:name=".HelloAndriod" >

XML syntax Meta-language – XML syntax describes an infinite number of languages What are the components of an XML document? – Elements demarcated by tags. … or – Attributes associated with elements. – Other types as well but not typically in the context of Android

Example XSLT Programmer’s Reference Michael Kay Lord of the Rings J.R.R. Tolkein Java and XML Jane Doe XML Gregory Brill tag open tag close

Example XSLT Programmer’s Reference Michael Kay Lord of the Rings J.R.R. Tolkein Java and XML Jane Doe XML Gregory Brill attributes

XML: Document Object Model (DOM) Basic idea: represent components of an XML document as nodes. – Specific node subtypes for different component types. – Organize nodes into a tree that reflects document structure. A document node serves as the root of the tree. – Provide interface for traversing the tree and dynamically changing properties of the nodes.

XML documents as Trees books book titleauthor “XML” “Gregory Brill” Here’s a simple XML document and associated tree: XML Gregory Brill Java and XML Jane Doe titleauthor “Java and XML” “Jane Doe”

Example XSLT Programmer’s Reference Michael Kay Lord of the Rings J.R.R. Tolkein Java and XML Jane Doe XML Gregory Brill

Ex: main.xml for an Android app <LinearLayout xmlns:android=" android:orientation="vertical“ … android:layout_height="fill_parent">

PART 3 – ANATOMY OF A SIMPLE ANDROID APP

Anatomy of an App Going to look at the Units Converter App. The parts of this app are available on blackboard. – This app just takes a single number plus a conversion to be performed and outputs the result of this conversion. Want to see the parts and (more importantly) the inter-relationships between these parts. Consists of Java code and XML documents

Elements of the App The Java code: UCActivity.java The configuration file: AndroidManifest.xml The resource files: – Layout: main.xml, gradientbg.xml – Values: strings.xml, arrays.xml

Configuration file Always called AndroidManifest.xml Defines app level info: versioning, permissions, … Defines the basic elements (activities, services, etc) of the application – with characteristics of these elements that make them usable by other apps.

AndroidManifest.xml <manifest package="cs499.examples.ucactivity“ android:versionCode="1" android:versionName="1.0"> <application android:icon= <activity android:name=".UCActivity" <action android:name= "android.intent.action.MAIN"/> <category android:name= "android.intent.category.LAUNCHER"/>

Resources Can define application level constants and values – For example, text strings for prompts, etc. Could use a different file for different languages for portability. Can define layout elements for the different activities.

strings.xml Hello World, UCActivity! Units Converter Clear Close Convert Select a Conversion Units Will be automatically converted to a class R.java (see the gen directory) In Java code, will see references to these strings as R.string.* In XML code, will see references to these strings as

arrays.xml Acres to square miles Atmospheres to Pascals Bars to Pascals Celsius to Fahrenheit Fahrenheit to Celsius … Will be automatically converted to a class R.java

<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:padding="5dip"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dip" android:textColor="#000000" android:textSize="15sp" android:textStyle="bold"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="type a number" android:inputType="numberDecimal|numberSigned" android:maxLines="1"/> <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" main.xml

<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:padding="5dip"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dip" android:textColor="#000000" android:textSize="15sp" android:textStyle="bold"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="type a number" android:inputType="numberDecimal|numberSigned" android:maxLines="1"/> <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:prompt= <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text= /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text= /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text= /> main.xml From strings.xml ids associated with layout elements. In Java code, will see R.id.*

gradientbg.xml <gradient android:startColor="#fccb06" android:endColor="#fd6006" android:angle="270"/>

/* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package cs499.examples.ucactivity; public final class R { public static final class array { public static final int conversions=0x7f040000; } public static final class attr { } public static final class drawable { public static final int gradientbg=0x7f020000; public static final int ic_launcher=0x7f020001; } public static final class id { public static final int clear=0x7f060002; public static final int close=0x7f060004; public static final int conversions=0x7f060001; public static final int convert=0x7f060003; public static final int units=0x7f060000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f050001; public static final int clear=0x7f050002; public static final int close=0x7f050003; public static final int convert=0x7f050004; public static final int hello=0x7f050000; public static final int prompt=0x7f050005; public static final int units=0x7f050006; } R.java – automatically generated

UCActivity.java public class UCActivity extends Activity { private int position = 0; // will use this to keep track of which conversion is chosen in the spinner // These are the multiplication factors used in the converter. private double[] multipliers = { , // Acres to square miles , // Atmospheres to Pascals , // Bars to Pascals 0, // placeholder for celsius to farhenheit 0,// placeholder for farhenheit to celsius , // Dynes to Newtons ,// feet/sec to meters/second , // ounces (UK) to Liters … lots more deleted … };

/** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // this is where the user inputs the number to be converted final EditText etUnits = (EditText) findViewById(R.id.units); From main.xml: <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="type a number" android:inputType="numberDecimal|numberSigned" android:maxLines="1"/> inflate main.xml must be defined for every activity

// The spinner - create the spinner and use the conversions array // to populate the choices final Spinner spnConversions = (Spinner)findViewById(R.id.conversions); ArrayAdapter aa; aa = ArrayAdapter.createFromResource(this, R.array.conversions, android.R.layout.simple_spinner_item); aa.setDropDownViewResource( android.R.layout.simple_spinner_item); spnConversions.setAdapter(aa); AdapterView.OnItemSelectedListener oisl; oisl = new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView parent, View view, int position, long id) { UCActivity.this.position = position; } public void onNothingSelected(AdapterView parent) { System.out.println("nothing"); } }; spnConversions.setOnItemSelectedListener(oisl);

// We have three buttons: clear, convert and close // The clear button - starts out disabled. When enabled, clicking the button // sets the editable field to empty. final Button btnClear = (Button) findViewById(R.id.clear); AdapterView.OnClickListener ocl; ocl = new AdapterView.OnClickListener() { public void onClick(View v) { etUnits.setText(""); } }; btnClear.setOnClickListener(ocl); btnClear.setEnabled(false); // The close button - always enabled. Terminates the // application by calling finish() final Button btnClose = (Button) findViewById(R.id.close); ocl = new AdapterView.OnClickListener() { public void onClick(View v) { finish(); } }; btnClose.setOnClickListener(ocl);

// The convert button - initially disabled. Once enabled, it // does the conversion specified by position - notice that // the temperature conversions position 3 & 4, are handled // separately. Puts the answer in the editable field final Button btnConvert = (Button) findViewById(R.id.convert); ocl = new AdapterView.OnClickListener() { public void onClick(View v) { String text = etUnits.getText().toString(); double input = Double.parseDouble(text); double result = 0; if (position == 3) result = input*9.0/ ; // Celsius to Fahrenheit else if (position == 4) result = (input - 32)* 5.0/ 9.0; // Fahrenheit to Celsius else result = input * multipliers[position]; etUnits.setText(""+result); } }; btnConvert.setOnClickListener(ocl);

// Toggles the button enabling - by knowing when // there is information to convert TextWatcher tw; tw = new TextWatcher(){ public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) { if (etUnits.getText().length() == 0) { btnClear.setEnabled(false); btnConvert.setEnabled(false); } else { btnClear.setEnabled(true); btnConvert.setEnabled(true); } }; etUnits.addTextChangedListener(tw); } // end of onCreate() } // end of the activity

Next class Introduction to Activities firstapp/index.html ndamentals/activities.html