Android N Amanquah.

Slides:



Advertisements
Similar presentations
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Advertisements

Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
The Android Development Environment.  Getting started on the Android Platform  Installing required libraries  Programming Android using the Eclipse.
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.
@2010 Mihail L. Sichitiu1 Android Introduction Hello Views Part 2.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
App Development for Android Prabhaker Mateti. Development Tools (Android) Java – Java is the same. But, not all libs are included. – Unused: Swing, AWT,
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Layout and Control in UI The user interface (UI) is the graphical interface user can see and interact with your app comprising UI controls like textbox,
@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
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.
Wireless Mobility with Android 1 Presented by: Ung Yean MS. Computer Science American University, Washington DC, USA.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
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.
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 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
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Android and s Ken Nguyen Clayton state University 2012.
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.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
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
Adapting to Display Orientation
GUI Programming Fundamentals
Android – Event Handling
Android Introduction Hello World.
Android Introduction Hello Views Part 1.
ITEC535 – Mobile Programming
HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung
תכנות ב android אליהו חלסצ'י.
Mobile Software Development Framework: Android
Android Introduction Hello Views Part 2.
Android GUI Project John Hurley CS 454.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
MultiUni Trần Vũ Tất Bình
CIS 470 Mobile App Development
Android GUI Project John Hurley CS 454.
CMPE419 Mobile Application 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,
Activities and Intents
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Notifications
Android Project Structure, App Resources and Event Handling
Adding Components to Activity
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Android N Amanquah

Installation: Install jdk Install android sdk starter pack (this also installs sdk tools) Install platform tools (eg unzip platform-tools_r03-windows, rename to “platform tools”, directly under android-sdk/) Install sdkPlatform (eg unzip android-2.2_r02-windows into “platforms”) Create an AVD using android sdk and avd mgr Netbeans: Install nbandriod into netbeans Eclipse: install ADT add SDK's tools/ and platform-tools to your PATH http://developer.android.com/sdk/installing.html

Building Blocks There are four building blocks to an Android application: Activity - composed of Views, responds to events Intent Receiver Service – long lived running code eg media plyr Content Provider eg store in SQLite db AndroidManifest.xml. declare the components of your application capabilities and requirements of your components

Intents Intent what an application wants done- a request to do smth. Use Intent to move from screen to screen Two main components of intent data structure: the action and the data to act upon Typical values for action are MAIN (entry point: can be started from icon), VIEW, PICK, EDIT, etc. The data is expressed as a Uniform Resource Indicator (URI) Eg to view a website: new Intent(android.content.Intent.VIEW_ACTION, ContentURI.create("http://www.ashesi.edu.gh"));

Intent Filters Intent Filter a description of what intents an activity (or intent receiver) is capable of handling Activities publish their IntentFilters in the AndroidManifest.xml file. Navigating from screen to screen is accomplished by resolving intents. To navigate forward, an activity calls startActivity(myIntent).  systems looks for matching intent filters Advantages: reuse of existing functionality Activities can be replaced/subsituted.

Intent Receivers execute in reaction to an external event App need not be running (eg to a phone call) Apps can broadcast intents Context.broadcastIntent().

Hello world: programmatically package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        TextView tv = new TextView(this);        tv.setText("Hello, Android");        setContentView(tv);    } } Note: copying and pasting this code results in additional invisible characters Past in Notepad first

Hello world: by XML package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } Configure the xml file to indicate what is loaded in the activity

XML Layout- a hierarchy of views <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content“ android:text="Hello World"/> </LinearLayout> View class is base for all widgets ViewGroup

Views views in a window are arranged in a single tree can add views from code or from tree of views in XML layout files After creating view, do some of the ff Set properties eg setText SetFocus Set up listeners Set visibility

View Hierarchy- view w button <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a TextView" /> <Button android:id="@+id/button" android:text="Hello, I am a Button" /> </LinearLayout>

Comparison to Swing Activities i-(J)Frame in Swing. Views -(J)Components in Swing. TextViews -(J)Labels in Swing. EditTexts -(J)TextFields in Swing. Buttons -(J)Buttons in Swing. Handling Events is similar: myView.setOnClickListener(new OnClickListener(){ ... // Swing myButton.addActionListener(new ActionListener() {...

XML layout <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android"   android:id="@+id/textview"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:text="@string/hello"/> These refer to string.xml and also create a new id called textview which can be referred to in code. A compiled object representation of the layout defined in /res/layout/main.xml is R.layout.main Textview can be referred to subsequently as R.id.textview

Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.anddev.android.hello_android"> <application android:icon="@drawable/icon"> <activity android:name=".Hello_Android" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

References & resources in code '@' prefix to introduce a resource reference android:textColor="@color/opaque_red" (will be in color.xml) R.java is an auto-generated Xml: android:id="@+id/my_button“ In code: Button myButton = (Button) findViewById(R.id.my_button);

A button (View) and event Views may have an integer id associated with them. –assigned in xml file Eg: define btn and assign an id: <Button      android:id="@+id/my_button"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="@string/my_button_text"/> In the onCreate method of activity, find the button: Button myButton = (Button) findViewById(R.id.my_button); Event button.setOnClickListener(new OnClickListener() {     public void onClick(View v) {         // Perform action on clicks         Toast.makeText(HelloFormStuff.this, “Msg displayed in msgbox", Toast.LENGTH_SHORT).show();     } }); @+id/foo means you are creating an id named foo in the namespace of your application. You can refer to it using @id/foo. @android:id/foo means you are referring to an id defined in the android namespace. This namespace is the namespace of the framework The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).

Create a form by adding widgets Create a basic linear view eg <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent" > </LinearLayout> Add widgets to this layout. Add their corresponding events if any, to onCreate()

Radio Button(use radioGroup)   <RadioGroup       android:layout_width="fill_parent"       android:layout_height="wrap_content"       android:orientation="vertical">       <RadioButton android:id="@+id/radio_red"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="Red" />       <RadioButton android:id="@+id/radio_blue"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="Blue" />     </RadioGroup> To do something when each RadioButton is selected, you need an View.OnClickListener. Place radio group inside say a LinearLayout

Acting when clicked: Add ff to onCreate() method: private OnClickListener radio_listener = new OnClickListener() {     public void onClick(View v) {         // Perform action on clicks         RadioButton rb = (RadioButton) v;         Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();     } }; Add ff to onCreate() method:   final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);   final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);   radio_red.setOnClickListener(radio_listener);   radio_blue.setOnClickListener(radio_listener);

Layouts

Excercise Create a range of layouts. Test them See http://developer.android.com/resources/tutorials/views/index.html