Android: Development App

fansbutterflyMobile - Wireless

Jul 19, 2012 (5 years and 1 month ago)

378 views



Android:
App

Development

By Miroslav Kopecky


Miroslav Kopecky

M$ Windows Admin, Programmer

Java Application Tester

Software Engineer at SUN

Java ME - SunSPOT project

Coordinator at SUN

Co-Founder of
GeeCON

PhD Candidate

Java EE, Groovy , Python, Android, Matlab ...


Agenda #1


ANDROID FOREWORLD


ANDROID SDK / EMULATOR / IDE - Eclipse


INTRODUCTION TO APP DEVELOPMENT


DEMO 1 – Custom Dialog


DEMO 2 – Which one?


DEMO 3 – SQLite Demo


DEMO 4 – Earthquake




Let's start ...


JavaME powered …




What is Android ?


Modern open-source mobile operating system

Linux kernel 2.6*

Libraries / Android Runtime

Is a software stack for mobile devices … features

Application framework

Dalvik virtual machine

SQLite, Media support, Bluetooth...

Core applications (Email,Calendar...)

Open Handset alliance – 65 companies


Android design schema



Application Framework


Underlying all applications is a set of services
and systems, including

Views

Content Providers

Resource Management

Notification Manager

Activity Manager

startActivity(Intent)


Android SDK / API Levels / IDE


API Level is an integer value that uniquely
identifies the framework API revision offered by
a version of the Android platform

Current SDK Android 2.1 API 7→ →

IDE – the best is Eclipse

Contains ADT (Android Development Tools)

ADT 0.9.5, DDMS

Demo 0

<uses-sdk android:minSdkVersion="7" />


Android SDK / API Levels / IDE

android:minSdkVersion

android:targetSdkVersion

android:maxSdkVersion
<manifest>
  
...
  
<uses­sdk 
android:minSdkVersion="5" />
  
...
</manifest>


Android SDK / API Levels / IDE


Eclipse


Java, Debuger, DMSS, Android Junit Test, Junit, LogCat,
EmulatorControl → KLM ...


EMULATOR

Plugin Eclipse/IntelliJIDEA

Debugging as appliaction written in JAVA

Variables, breakpoints …


Introduction to App Development

Java programming language → package *.apk

application lives in its own world (ID,VM)

Application Components

Activities, Servicies, Broadcast receivers

are activated by asynchronous
messages called intents


Content providers

The AndroidManifest.xml File

essential information about the application

Project Structure –
src, gen, res → layouts, values ...


The Project Structure
AndroidManifest.xml

<uses-sdk android:minSdkVersion="7" />

<uses-permission
android:name="android.permission.READ_CONTACTS">
</uses-permission>
Folder “/res”

Drawable

Layout - main.xml

Values - strings.xml
Folder “gen” - R.java

Folder “src”


Introduction: UserInterface

Build by using view class

Layout

Creating Menus

Submenus

Define Menus in XML / Menu Features

Event listener

Override an existing callback method

Advanced Topics

Adapters & Cursor

Styles and Themes

new
SimpleCursorAdapter


Example 0
– ProgressDialog

private
 ProgressDialog 
progressDialog
;

Define the 
Handler
 that receives messages from 
the thread and update the progress. 

With single Thread   →
StartThread

showDialog
(
START_DIALOG
);

protected Dialog 
onCreateDialog
(int id)


Example 1
– Custom Dialog


extends Activity - root

@Override

onCreate(Bundle savedInstanceState)

super.onCreate(
savedInstanceState
);

button1
= (
Button
) findViewById(
R.id.customDialogButton
);
button1
.
setOnClickListener
(new
OnClickListener()
{

public void
onClick
(
View
v) {

dialog1.show();

Log.d("Presentation1START", "DIALOG1");

button1
.setEnabled(false);

}

});


Example 1
– Custom Dialog

extends

Dialog
implements

OnClickListener


Interface
 
ReadyListner
 {   →
ready
(
String

onCreate
(
Bundle
 savedInstanceState)
root Activity
 : 
OnReadyListener1
 
implements
 
custDialog.ReadyListener
;

private
class
OnReadyListener1

implements

custDialog.ReadyListener
{

public void
ready
(
String
text
) {

Log.d("Presentation2TART", "TEXT is " + text);

tv1.setText(
text
);

button1.setEnabled(true);

} }


Example 2
– Which one?


extends Activity - root

SelectBeerDialog
 
dialog2 = new 
SelectBeerDialog
(this, false, false, 
new OnReadyListener2()
);
@Override

public void

ready
(boolean
okocim
, boolean
zywiec
){

String text="I don't like BEER";

if(
okocim
){

text="I love OKOCIM";

if(
zywiec
){

text=text + " and ZYWIEC!";

}

} else if (zywiec){

text="I love ZYWIEC";


Example 3
– SQLite Demo..
import
 android.content.ContentResolver 
and
 
android.database.Cursor

SelectBeerDialog
 
dialog2 = new 
SelectBeerDialog
(this, false, false, 
new OnReadyListener2()
);
ContentResolver

cr
=
getContentResolver
();

Cursor

cur
=
cr
.query(
ContactsContract.Contacts.CONTENT_URI
,

null, null, null, null
);
if (
cur
.getCount() > 0) {

String names ="";

while (
cur
.moveToNext())


Example 4
– Earthquake

extends
meteco
extends
Activity - root

button2
=(
Button
)
findViewById
(
R.id.earthquakeButton
)

Intent – Adapter – Broadcast Receiver – DataStorage – Maps –
Geocoding - Services – Background 2D overlay

Manifest File → others activites definition

<uses­permission 
android:name="android.permission.INTERNET"/>
<activity android:name="
.Earthquake
" />
<activity android:name="
.Preferences
" android:label="
Earthquake Preferences
"/>


Example 4
– Earthquake


Internet access → resources from there

Geoconding

Google MAPS
WhW?


Sensors ->= Compass

Dealing with Sensors
/
Hardware
CompassView 
compassView
;
SensorManager 
sensorManager
;

SensorEventListener

onSensorChanged(
SensorEvent
 evt)


Android:
App

Development
- closer look at

By Miroslav Kopecky


Agenda #2

GeeCONWidget EXAMPLE

AppWidgetManager, meta-tag, AppWidgetProvider

ButtonWidget EXAMPLE

CALCULATOR EXAMPLE

Activity, OnClickListener, JUnit a Android Junit, Toast


TEMPERATURECONVERTER EXAMPLE

ViewGroup and Views, Junit testing, Toast Message



#1 : GeeCONWidget

AndroidManifest.xml

<receiver android:name=".GeeCONWidget" 
android

widget_provider.xml



#2 : ButtonWidgets

AndroidManifest.xml

<receiver android:name=".ButtonWidget" 
android

widget_provider.xml



#3 : Calculator Example

Java Class → Caluclator.java

Android Activity → CalculatorAcitivy.java



#4 : Temperature Converter



How to creat ViewGroup without XML

Testing



THANK YOU ! & Q and A
Miroslav.Kopecky@GeeCON.org


References...

http://www.openhandsetalliance.com/

http://developer.android.com/sdk/index.html

http://source.android.com/projects

http://www.android.com/