Professional Documents
Culture Documents
36
Android 1.0
:
www.misoo1.com
tom-kao.blogspot.com
(2008 10 )
miso o.t w@ gma il.co m
2 Android 36
2008 4
e-book
tom-kao.blogspot.com www.misoo1.com
( )
Android () 4
( Android
)
Android 36
Android C
Android
Andriod
Google
Android
!
2008.10.3
tom-kao.blogspot.com
4 Android 36
1.2
1.3
1.4
1.5
OS
~ . ~
, 14
1.1
2.1
2.2
2.3
2.4
2.5
( )
, 31
IoC
( )
~ ~
, 54
3.1
( ) ( )
3.2
3.2.1
3.2.2
( )
3.2.3
( )
3.2.4
( )
( )
~ ~
12 ,
4.1
#1 Menu
4.2
#2 (Button) 1
4.3
#3 (Button) 2
4.4
#4 (Layout)
4.5
#5 List 1
4.6
#6 List 2
4.7
#7 (Relative Layout)
4.8
#8 (Table Layout)
4.9
#9
82
5.1
5.2
Use Case
6.1
6.2
6.3
6.4
6.5
#17 .xml
6.6
#18 onResume()
6 Android 36
7.1
#19 Activity
7.2
#20
SQLite , 193
8.1
8.2
(Table)
8.3
8.4
8.5
8.6
8.7
SQL
8.8
SQL
5 , 201
9.1
#21SQLite
9.2
9.3
9.4
9.5
#25 (Transaction)
10
10 , 237
10.1
#26 BroadcastReceiver
10.2
#27 Service
10.3
#28 ProgressDialog
10.4
#29 KeyEvent
10.5
10.6
#31 MapView
10.7
#32 WebView
10.8
#33
10.9
#34 COR
#35 State
10.10
11
C , 307
11.1
#36 C
11.2
Android C
A327
A-1
A-2
A-3
A-4
A-5
A-6
B336
B-1
Omia
B-2 Google
B-3 IT :()
B-4
B-5 Android Eclipse
8 Android 36
Misoo
Misoo
Misoo
(Co-design) Misoo
Russia
Voronezh,
Russia
20 Linter
Android
10 Android 36
(video player)
(DBMS)
GPS (Blackberry, WinCE, J2ME)
(wireless protocol)
(Flash-based)
11
Misoo e-book
Misoo ?
( )
Misoo
TEL: (02) 2739-8367
E-mail: misoo.tw@gmail.com
Misoo
TEL: (02) 2739-8367
TEL: 400-886-0806
Misoo
E-mail: misoo.tw@gmail.com
E-mail: sv@softcompass.com
tom-kao.blogspot.com
www.misoo1.com
12 Android 36
Google Android
www.misoo1.com
2 Android ()
*** 308 www.android1.net ***
( )
~~ . ~~
( )
Android
13
14 Android 36
1.1
1.2
1.3
1.4
1.5
OS
15
1.1
(Domain)
(Share)
( Productivity)
(Abstraction)
(Reuse)
1
16 Android 36
(Abstract
Class)
17
(Concrete
Class)
(Class Library)
18 Android 36
(Default
Behavior)
1.2
(Framework) 20 1980 Smalltalk
MVC Apple Macintosh MacApp
.Net Framework
20
1980
----- Smalltalk-80
1980
----- Macintosh
1990
1990
----- IBM
2000
MVC Framework
MacApp Framework
MFC Framework
19
2007
1.2.1
Smalltalk-80
MVC
Smalltalk80
MVC(Model-View-Controller) Samlltalk
(User Interface) 1980 Smalltalk-80
1990 Smalltalk-V
MVC
ModelView Controller
1-1
MVC
20 Android 36
1.2.2
MacApp
1980
Apple MacApp Macintosh
3
application
document
view view
Macintosh view window
view frame
command document view MacApp
application
document
document
viewwindow frame document
document view
window frame
frame
view
view
command
command
document view
21
MacApp
window frame command
application document view
TDocument
TView TApplication
documentview application
MacApp
1.2.3
Visual C++
MFC
Windows Windows
ListArray Date
OLE
ODBC SQL
OracleSybase
MFC MacApp MFC
CWinApp CMainFrame CView CDocument
:
22 Android 36
1.2.4
23
Business
Financials
Order
Management
Java VM
Unix NT
1.2.5
.Net Framework
1.2.6
Google Android
24 Android 36
1.3
(Reuse)
1-4
(Multi-platform)
API
(Domain)
AUTOSAR
25
Android +
Android
1.4
(Reusability)
(abstract)
26 Android 36
1.5
OS
1.5.1
OS OS(
Linux Windows)
( 1-4 )
1-5
1-6
(Mindset)
27
1-6
1.5.2
Linux / Windows OS
OS
1-7 ( 1-6)
(Hotel)
28 Android 36
1-8 OS
1-9 OS
8 7
1000 7
1-10
29
1-11
( )
OS
1-12
( )
( )
Android
( )
30 Android 36
(Platform)
!
Android
Android ()
Android ()
Cheese
C
11
31
2.1
2.2
2.3
2.4
2.5
IoC
32 Android 36
2.1
(Default) (default)
(
)
(Event-Driven)
2-1
33
OS(Linux/Windows)
()
f1()
abstract
f2()
f3()
f4()
f1()
f2()
f4()
2-1
Linux Windows
4
1.
2.
34 Android 36
3.
4.
f2() Linux/Windows
f3()
f2()
f3() f3() f3()
f4() f4() f4() f4()
f4()
(Mindset)
2.2
----
(IoC)
IoC(Inversion of Control)
( )
IoC OO ( C++Java )
Java (Superclass) (Subclass)
IoC IoC
IoC IoC
AndroidSpring
35
2.2.1
(Function Library) ( )
( )
public myFunction() {
int x = abs( y );
}
abs() (
) (Class
Library)
Person
public class Person {
private String name;
public void SetName(String na) { name = na; }
public void Display()
{ System.out.println("Name: " + name ); }
}
Customer
public class Customer extends Person {
public void Init() { super.SetName(Tom);
public void Show() { super.Display(); }
}
36 Android 36
Android Android
// Android
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle icicle)
{ super.onCreate(icicle);
setContentView(R.layout.main);
}
( MyActivity) onCreate() ( Activity)
onCreate()
setContentView() Activity Android
2.2.2
( ) ( )
2.2.2.1
Java
Shape
// Shape.java
package _framework;
public class Shape {
public void Paint() { this.Draw(); }
public abstract void Draw();
}
Draw() Paint()
Draw() ( ) Draw() ( )
// Circle.java
package _objects;
import java.awt.Color;
import java.awt.Graphics;
import _framework.*;
public class Circle extends Shape {
private Graphics m_gr;
private int x, y, radius;
public Circle(Graphics gr) { m_gr = gr; }
public void SetValue(int x0, int y0, int rad){
x = x0; y = y0;
radius = rad;
}
public void Draw(){ //
m_gr.setColor(Color.BLACK);
m_gr.drawOval(x-radius, y-radius, 2*radius, 2*radius);
}}
JMain
// JMain.java
import java.awt.*;
import javax.swing.*;
import _framework.Shape;
import _objects.*;
class JP extends JPanel {
public void paintComponent(Graphics gr) {
super.paintComponents(gr);
Circle cir = new Circle(gr);
cir.SetValue(160, 100, 45);
Shape sp = cir;
sp.Paint();
}}
public class JMain extends JFrame {
public JMain() { setTitle(""); setSize(400, 300); }
public static void main(String[] args)
{ JMain frm = new JMain();
JP panel = new JP();
frm.add(panel);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
37
38 Android 36
}}
JP sp.Paint() Shape
Paint() Circle Draw()
(Inversion)
(Inversion of Control)
2.2.2.2
Android
Android
// Android
public class MyView extends View {
private Paint paint;
public MyView(Context context) {
super(context);
private Paint paint= new Paint();
}
public void ReDraw() { this.invalidate(); }
@Override
protected void onDraw(Canvas canvas) { //
paint.setAntiAlias(true);
paint.setColor(Color.YELLOW);
canvas.clipRect(30, 30, 100, 100);
}}
ReDraw() Android
invalidate() Android MyView
onDraw() onDraw()
View onDraw()
39
2.3
Person Customer
Person
Customer
()
2-2
Java
// Person.java
package _abstract_classes;
public abstract class Person {
protected String name;
public void setName(String na) { name = na; }
public abstract void display();
}
// Customer.java
package _abstract_classes;
public class Customer extends Person {
public void display()
{ System.out.println("Customer: " + super.name); }
}
40 Android 36
VIP
Person
Customer
()
()
VIP
2-3
Java
// VIP.java
package _concrete_classes;
import _abstract_classes.*;
public class VIP extends Customer {
private String tel;
public VIP(String na, String t) {
super.setName(na);
tel = t;
}
public void display()
{ super.display();
System.out.println("TEL: " + tel);
}}
41
VIP()
setName()
display() Customer::display()
Product
Product
Person
pc
Customer
()
()
TV
VIP
2-4
Java
// Product.java
package _abstract_classes;
public abstract class Product {
protected int pno;
protected Customer cust;
public Product(int no) { pno = no; }
public void soldTo(Customer cobj) { cust = cobj;
public void inquire() {
this.print();
System.out.println("sold to ...");
cust.display();
}
42 Android 36
// JMain.java
import _abstract_classes.*;
43
import _concrete_classes.*;
public class JMain {
public static void main(String[] args)
{ TV t = new TV(1100, 1800.5);
VIP vp = new VIP("Peter", "666-8899");
t.soldTo(vp);
t.inquire();
}}
Product TV
Product inquire() TV print()
TV print()
TV print()
Product print()
TV
inquire()
TV print()inquire()
TV print()
public void print()
{ System.out.println("TV No: " + pno);
System.out.println("Price: " + price);
}
Product inquire() VIP display()Product
VIP
VIP
cust
cust display()
inquire() cust VIP display()
44 Android 36
VIP display()
main() Product
soldTo()
inquire() TV print() VIP
display()
TV print() inquire() VIP display()
inquire()
inquire() print()
45
IoC
2.4
Java
Product Product
TV (Run-time)
Product inquire()
(IoC)
IoC IoC
IoC
IoC
IoC
Factory
Document Initialize() {
doc = new Document();
doc.Setter( new Integer() );
}
()
()
Document
IDisplay pd;
IDisplay
Integer
void Setter(IDisplay d) { dp = d; }
void Display() { dp.Display();
}
2-5
46 Android 36
Java
Java
Step-1:
_framework Java
// IDisplay.java
package _framework;
public interface IDisplay {
public void Display();
}
_framework Factory Java
// Factory.java
package _framework;
import _objects.*;
import _objects.Integer;
public class Factory {
private Document doc;
public Document Initialize()
{ doc = new Document();
doc.Setter(new Integer());
return doc;
}}
Step-2:
// Document.java
package _objects;
import _framework.*;
47
// Integer.java
package _objects;
import _framework.*;
public class Integer implements IDisplay
{ int value;
public Integer() { value = 100; }
public void Display()
{ System.out.println("Value = " + String.valueOf(value));
}}
Step-3:
JMain
// JMain.java
import _objects.*;
import _framework.*;
public class JMain {
public static void main(String[] args)
{ Factory fa = new Factory();
Document doc = fa.Initialize();
doc.Display();
}}
Step-4:
Factory
//
public class Factory {
private Document doc;
public Document Initialize() {
doc = new Document();
48 Android 36
2.5
2.5.1
49
747
Linux/Windows
50 Android 36
(Override)
2.5.2
Java
Java
(Override)
// Employee.java
package _objects;
public abstract class Employee {
public abstract void SetFee(float basic_fee, float disc);
public abstract float GetTotal();
public abstract void display();
}
// SalesPerson.java
package _objects;
public abstract class SalesPerson extends Employee{
51
SalesPerson display()
this.GetTotal();
SalesSecretary GetTotal()
public float GetTotal() {
return BasicFee * Discount 100;
}
52 Android 36
JMain
main() {
linda.display()
}
SalesPerson
display() {
this.GetTotal()
}
()
SalesSecretary
GetTotal() {
.
}
main() SalesPerson
( )
~~ . ~~
( ) (
)
(Abstraction)
53
54 Android 36
3.1
3.2
( ) ( )
3.2.1
3.2.2 ()
3.2.3 ()
3.2.4 ()
55
Android
Android
3.1 () ()
Java
(Abstract)
Step 1.
Step 2.
Step 3.
56 Android 36
(Abstraction)
(Reuse)
1
57
3-1
Step 1 ----
Step 2 ----
3-2 3-3
58 Android 36
()
3-2
( )
( )
)
( ) 3-3
()
()
3-3
59
( )
( )
()
()
()
3-4
----
(Reusability)
60 Android 36
3.2
3.2.1
(Abstract Class)
Step 1.
Step 2.
Step 3.
(Concrete
Class)
public abstract class Person {
//.......
public abstract void Display();
}
Display()
61
// EX03_01
// Person.java
package _objects;
public abstract class Person {
protected String name;
public void SetName(String na)
{ name = na; }
public abstract void Display();
}
// Employee.java
package _objects;
public class Employee extends Person {
public void SetName(String na)
{ super.SetName(na);
}
public void Display()
{ System.out.println("Employee: " + name ); }
}
// JMain.java
import _objects.*;
public class JMain {
public static void main(String[] args)
{ Person p = new Employee();
p.SetName("Peter Chen");
p.Display();
}
}
Employee Display()
Employee
Person::Display()
3
Display()
62 Android 36
name = na;
}
public void SetSalary(int s) {
salary = sa
}
public class Person {
private String name;
}
public class Person {
private String name;
public void SetName( String na ) {
}
name = na; }
public abstract class Person {
private String name;
public void SetName(String na) {
public abstract void Display();
}
name = na; }
Display() Person
63
Java
(Default)
Java
// EX03_02
// Employee.java
package _objects;
public class Employee
{ private String name;
private String sex;
static class Fee {
public static float BasicFee;
public static float Discount;
public static float GetTotal(){
return BasicFee * Discount; }
}
public Employee(String na, String sx) { name = na; sex = sx; }
public void SetFee(float basic_fee, float disc)
{ Fee.BasicFee = basic_fee;
Fee.Discount = disc; }
public void Display() { System.out.println(name + "'s fee: " + Fee.GetTotal());}
}
// Customer.java
package _objects;
public class Customer
{ private String name;
private String sex;
static class Fee {
public static float AnnualFee;
64 Android 36
3.2.2
()
public class Person
{ private String
name; private String
sex;
......
}
65
66 Android 36
// EX03_03
// Person.java
package _objects;
public class Person {
protected String name;
protected String sex;
}
// Employee.java
package _objects;
public class Employee extends Person{
static class Fee {
public static float BasicFee;
public static float Discount;
public static float GetTotal() { return BasicFee * Discount; }
}
public Employee(String na, String sx){ name = na; sex = sx; }
public void SetFee(float basic_fee, float disc)
{ Fee.BasicFee = basic_fee;
Fee.Discount = disc; }
public void Display() { System.out.println(name + "'s fee: " + Fee.GetTotal()); }
}
// Customer.java
package _objects;
public class Customer extends Person {
static class Fee {
public static float AnnualFee;
public static float Discount;
public static float GetTotal() { return AnnualFee * 32.25f * Discount; }
}
public Customer(String na, String sx){ name = na; sex = sx; }
public void SetFee(float annual_fee, float
disc){ Fee.AnnualFee = annual_fee /
32.25f;
// Convert to US$ to NT$
Fee.Discount = disc;
}
public void Display() { System.out.println(name + "'s fee: " + Fee.GetTotal()); }
}
// JMain.java
import _objects.*;
public class JMain {
67
Person
3.2.3
()
Step 1:
Employee Customer
Java
// EX03_04
// Person.java
package _objects;
public class Person {
protected String name;
protected String sex;
public Person(String na, String sx)
{ name = na; sex = sx; }
}
// Employee.java
package _objects;
public class Employee extends Person{
static class Fee {
public static float BasicFee;
public static float Discount;
public static float GetTotal()
Person
68 Android 36
69
Step 2:
Java
AA
BB
private String x;
public void Print()
{ System.out.println(x)
;
}
.....
private int x;
public void Print()
{ System.out.println(x)
;
}
.....
String x;l
int x;
void Print() {
System.out.println( x );
}
void Print() {
System.out.println( x );
End Sub
GetData()
70 Android 36
AA
BB
private String x;
public final void Print()
{ System.out.println(GetData());
}
public String GetData() {
return x;
}
.....
private int x;
public final Print() {
System.out.println(GetData());
}
public String GetData() {
return String.valueOf(x);
}
.....
Print()
GetData()
SuperAB
pubic final void Print() {
System.out.println( GetData() );
}
public String GetData() {}
BB
AA
private String x;
private int x;
SuperAB
abstract
GetData()
71
GetData()
Print() Print()
( )
// EX03_05
// JMain.java
package _objects;
public class JMain {
private void print(double x, int y) {
System.out.println(x+y);
private void print(int k, int y)
{
System.out.println(k*y);
public static void main(String[] args) {
JMain mObj = new JMain();
mObj.print(3.6, 6);
mObj.print(2, 60);
}}
print()
System.out.println(
}
}
int y ) {
x+
);
System.out.println(
int y ) {
k*
);
72 Android 36
Step-2a
Number
Double
Integer
print()
public void print( Number numb,
}
Step-2b
int y ) {
print()
public void print( Number numb, int y)
{ System.out.println( numb.prStr(y) );
}
Java
// EX03_06
// Number.java
package _objects;
public abstract class Number { public abstract String prStr(int y); }
// jvInt.java
package _objects;
public class jvInt extends Number{
private int x;
public jvInt(int i) { x = i; }
public String prStr(int y) { return String.valueOf( x * y );
}
// jvFloat.java
package _objects;
public class jvFloat extends Number {
prStr()
private float x;
public jvFloat(float a)
{ x = a;
}
public String prStr(int y) { return String.valueOf(x + y);
}
// JMain.java
import _objects.*;
import _objects.Number;
public class JMain {
private void print(Number numb, int y) { System.out.println(numb.prStr(y)); }
public static void main(String[] args)
{ JMain mObj = new JMain();
jvFloat a = new jvFloat(3.6f);
jvInt b = new jvInt(2);
mObj.print(a, 6);
mObj.print(b, 60);
}}
9.6
120
print()
// EX03_07
// Number.java
package _objects;
public abstract class Number {
public abstract String prStr(int y);
public void print(int y) { System.out.println( this.prStr(y) ); }
}
// jvInt.java
package _objects;
public class jvInt extends Number{
private int x;
public jvInt(int i) { x = i; }
public String prStr(int y) { return String.valueOf(x * y);
}
// jvFloat.java
package _objects;
public class jvFloat extends Number {
73
74 Android 36
private float x;
public jvFloat(float a) { x = a; }
public String prStr(int y) { return String.valueOf(x + y); }
}
// JMain.java
import _objects.*;
import _objects.Number;
public class JMain {
public static void main(String[] args)
{ JMain mObj = new JMain();
jvFloat a = new jvFloat(3.6f);
jvInt b = new jvInt(2);
mObj.print(a, 6);
mObj.print(b, 60);
}}
EX03-04
public class Employee {
......
public void Display() {
System.out.println(name + "'s fee: " + Fee.GetTotal());
}
Employee.Fee Customer.Fee
Fee.GetTotal() Display()
Overridable
// EX03_08
// Person.java
package _objects;
public class Person {
name = na;
sex = sx;
}
// Employee.java
package _objects;
public class Employee extends Person{
static class Fee {
public static float BasicFee;
public static float Discount;
public static float GetTotal(){ return BasicFee * Discount;
}
public Employee(String na, String sx){ super(na, sx); }
public void SetFee(float basic_fee, float
disc){ Fee.BasicFee = basic_fee;
Fee.Discount = disc;
}
public void Display() {
System.out.println(name + "'s fee: " + Fee.GetTotal());
}}
// Customer.java
package _objects;
public class Customer extends Person {
static class Fee {
public static float AnnualFee;
public static float Discount;
public static float GetTotal(){ return AnnualFee * 32.25f * Discount;
}
public Customer(String na, String sx) { super(na, sx); }
public void SetFee(float annual_fee, float disc)
{ Fee.AnnualFee = annual_fee / 32.25f;
// Convert to US$ to NT$
Fee.Discount = disc;
}
public void Display() {
System.out.println(name + "'s fee: " + Fee.GetTotal());
}}
// JMain.java
import _objects.*;
public class JMain {
75
76 Android 36
GetFee() Display()
SetFee()
3.2.4
()
3.2.4.1
(abstract function)
Java
public abstract class Graph { //
public abstract void draw();
public abstract void paint();
}
Graph
// IGraph.java
public interface IGraph {
void draw();
void paint();
}
77
Java Interface ?
1997 OOP ( C++)
Interface
Java (
Android .Net) Android
OnClickListener Android
// Android MyActivity.java
public class MyActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private final int DB_Version = 1;
private final int DB_Mode = Context.MODE_PRIVATE;
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private SQLiteDatabase db=null;
private Button btn;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
btn = new Button(this);
btn.setText("Exit");
btn.setOnClickListener(this);
setContentView(btn, new LinearLayout.LayoutParams(WC, WC));
try { db = createDatabase("MyDB", DB_Version, DB_Mode, null);
catch(FileNotFoundException
e){ Log.e("ERROR",
e.toString()); db = null;
}
if (db != null) setTitle("create DB OK!");
else setTitle("Error!");
}
public void onClick(View v){
if(v.equals(btn))
this.finish();
}}
78 Android 36
3.2.4.2
Java
// EX03_09
package _objects;
public class //
{ private String Name;
public float ComputeTuition(int credit) {
if (credit > 6) credit = 6;
return (credit -1) * 500 + 5000;
}}
// BasicFee.java
package _objects;
public class //
{ private String Name;
public float ComputeTuition(int credit) {
if (credit > 6) credit = 6;
return credit * 700 + 5000;
}}
ComputeTuition()
----- (credit-1)*500
----- credit *700
ComputeTuition()
Overridable GetValue()
ComputeTuition()
// EX03_10
package _student;
import _interface.*;
79
public class {
private String Name;
public float ComputeTuition(int credit) {
if (credit > 6) credit = 6;
return tc.GetValue(credit) + 5000;
}
protected abstract float GetValue(int credit);
}
public class extends {
//
public float GetValue(int credit)
{ return (credit -1) * 500;
}
public class extends {
//
public float GetValue(int credit) { return credit * 700;
}
}
GetValue()
// EX03_11
package _interface;
public interface ITuition //
package _student;
import _interface.*;
public class {
private String Name;
private ITuition tc;
public void Setter(ITuition tuiObj) { tc = tuiObj;
public float ComputeTuition(int credit) {
if (credit > 6) credit = 6;
return tc.GetValue(credit) + 5000;
}}
package _tuition_plugin;
import _interface.*;
public class implements ITuition { //
public float GetValue(int credit) { return (credit -1) * 500;
}
public class implements ITuition { //
public float GetValue(int credit) { return credit * 700; }
80 Android 36
ITuition
JMain
import _student.*;
import _tuition_plugin.*;
public class JMain {
public static void main(String[] args) {
float t1, t2;
Lily = new ();
under_tui = new
(); Lily.Setter(under_tui);
t1 = Lily.ComputeTuition(5);
Peter = new ();
grad_tui = new
(); Peter.Setter(grad_tui);
t2 = Peter.ComputeTuition(7);
System.out.println( "Lily: " + String.valueOf(t1) + ", Peter: "
+ String.valueOf(t2));
}}
Lily Peter
Lily: 7000, Peter: 9200
OOP + UML + OOAD +
Architecture Design
B-4
4 Android 12 81
( )
~~ . ~~
Android
Android
82 Android 36
Android
12
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
4.10
4.11
4.12
#1 Menu
#2(Button) 1
#3(Button) 2
#4(Layout)
#5 List 1
#6 List 2
#7 (Relative Layout)
#8(Table Layout)
#9
#10 View
#11 RadioButton
#12 Activity Activity
4 Android 12 83
Android 36
35 Android Java 36
Android C
Android ( 35 )
Android
Cheese
C ( 36 )
Android
Android SDK Eclipse -A
Android SDK
Android
Android
-A
www.misoo1.com
tom-kao.blogspot.com
36 !!
84 Android 36
4.1 #1 Menu
Menu Android
Menu
4.1.1
1.
<MENU>
2.
3.
4.1.2
Step-1:
Step-2:
Android ex01
Activity ex01
4 Android 12 85
Step-3:
/res/values/strings.xml
Step-4:
4.1.3
onCreate() onCreateOptionsMenu()
<Add Item> onOptionsItemSelected()
ex01
4. onCreate() Activity onCreate()
ex01::onCreate()
1.
2.
3.
86 Android 36
setContentView(R.layout.main) main.xml
(Layout)
5.
onCreateOptionsMenu() menu.add(0,
ADD_ID, R.string.menu_add) /res/values/strings.xml
Add Item
4.1.4
()
onCreate() create
Java
<<Interface>>
IGraph
void onPaint()
void paint()
<<abstarct>>
Shape
void onPaint() {
// }
void paint() { onPaint(); }
Bird
void onPaint() {
super.onPaint();
//
}
paint() onPaint()
onPaint()
4 Android 12 87
// IGraph.java ----
public interface IGraph
{ void onPaint();
void paint();
}
//-------------------------------------------------------// Shape.java ----
import java.awt.*;
public abstract class Shape implements
IGraph{ Graphics m_gr;
public Shape(Graphics gr) { m_gr = gr; }
public void onPaint(){
//
m_gr.setColor(Color.black);
m_gr.fillRect(10,30, 200,100);
}
public void paint() { onPaint(); }
}
//-----------------------------------------------// Bird.java ----
import java.awt.*;
public class Bird extends Shape
{ Graphics m_gr;
public Bird(Graphics gr) {
super(gr);
m_gr = gr;
}
public void
onPaint(){ super.onPa
int();
// ()
m_gr.setColor(Color.cyan);
m_gr.drawArc(30,80,90,110,40,100);
m_gr.drawArc(88,93,90,100,40,80);
m_gr.setColor(Color.white);
m_gr.drawArc(30,55,90,150,35,75);
m_gr.drawArc(90,80,90,90,40,80);
}}
//-------------------------------------------------------// JMain.java ----
import java.awt.*;
import javax.swing.*;
class JP extends JPanel {
public void paintComponent(Graphics gr){
super.paintComponents(gr);
88 Android 36
4.1.5
()
/res/values/strings.xml
R.java menu.add(0, ADD_ID, R.string. menu_add)
R.java
4 Android 12 89
(R.java)*.java *.xml
res/layout/ *.xml Eclipse .xml
R /src/
4.2.1
Android
1.
2.
3.
90 Android 36
4.2.2
Step-1:
Step-2:
Android ex02
Activity ex02
Step-3:
/res/layout/main.xml
4 Android 12 91
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
/>
</LinearLayout>
Step-4:
4.2.3
onCreate() Activity
onCreate() (
ex01) onCreate() setContentView(R.layout.main)
main.xml
(Layout)
2. Button btn = (Button)findViewById(R.id.button);
( R.layout.main) btn btn
id id/button
3. btn.setOnClickListener(this);
(Event Handler)
id id/button
this
ex02 (Current Object) ex02
OnClickListener
onClick(View arg0)
1.
92 Android 36
4.
ex02 onClick()
onClick() switch id
id id/button (
OK) (Title) this is OK button
id
id/button2 ( Exit) finish()
( Activity)
4.3 #3(Button) 2
btn.setOnClickListener(this)
onClick()
btn.setOnClickListener(listener) listener
onClick()
4.3.1
1.
2.
3.
4.3.2
4 Android 12 93
Step-1:
Step-2:
Android ex03
Activity ex03
Step-3:
/res/layout/main.xml
94 Android 36
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
/>
</LinearLayout>
Step-4:
4.3.3
btn.setOnClickListener(listener);
btn listener onClick()
2. 2 btn.setOnClickListener(this);
btn onClick()
3.
1.
4.3.4
(Button)
Button setBackgroundResource()
2)
ImageButton
1)
Button ImageButton
4 Android 12 95
// ---- ex03_a.java ------------------------------------package com.misoo.ex03;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class ex03 extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ImageButton btn = (ImageButton)findViewById(R.id.button);
ImageButton btn2 = (ImageButton)findViewById(R.id.button2);
btn.setOnClickListener(listener);
btn2.setOnClickListener(listener2);
}
OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
setTitle("this is OK button");
}
};
OnClickListener listener2 = new OnClickListener() {
public void onClick(View v)
{ finish(); }
};
}
96 Android 36
/res/drawable/ ok.jpg
exit.jpg
ImageButton /res/layout/main.xml
Android
Android
4 Android 12 97
4.4 #4
Android
Android
(view, Button )
(Layout)
4.4.1
1.
4.4.2
Step-1:
Step-2:
Android ex04
Activity ex04
// ---- ex04.java
package com.misoo.ex04;
import android.app.Activity;
----
98 Android 36
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class ex04 extends Activity {
private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
ImageButton btn = new ImageButton(this);
Drawable dw = this.getResources().getDrawable(R.drawable.ok);
btn.setImageDrawable(dw);
btn.setOnClickListener(listener);
LinearLayout.LayoutParams param =
new LinearLayout.LayoutParams(WC, WC);
layout.addView(btn, param);
ImageButton btn2 = new ImageButton(this);
dw = this.getResources().getDrawable(R.drawable.exit);
btn2.setImageDrawable(dw);
btn2.setOnClickListener(listener2);
layout.addView(btn2, param);
LinearLayout out_layout = new LinearLayout(this);
out_layout.setOrientation(LinearLayout.HORIZONTAL);
Button btn3 = new Button(this);
btn3.setText("Cancel"); btn3.setTextColor(Color.WHITE);
btn3.setBackgroundColor(Color.RED); btn3.setOnClickListener(listener3);
out_layout.addView(layout, param);
LinearLayout.LayoutParams param2 =
new LinearLayout.LayoutParams(WC, WC);
param2.topMargin = 30;
out_layout.addView(btn3, param2);
setContentView(out_layout);
}
OnClickListener listener = new OnClickListener(){
public void onClick(View v) { setTitle("this is OK button");
};
OnClickListener listener2 = new OnClickListener() {
4 Android 12 99
Step-3:
4.4.3
LinearLayout
()
OK
Cancel
LinearLayout
()
Exit
5.
LinearLayout View
6. ImageButton btn = new ImageButton(this);
Drawable dw = this.getResources().getDrawable(R.drawable.ok);
100 Android 36
btn.setImageDrawable(dw);
btn.setOnClickListener(listener);
/res/drawable/ok.jpg
7. LinearLayout.LayoutParams param =
new LinearLayout.LayoutParams(WC, WC);
LayoutParams WC
8. layout.addView(btn, param);
ImageButton Button layout
9. btn2 layout
10. LinearLayout out_layout = new LinearLayout(this);
out_layout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout out_layout
4.4.4
/res/layout/ xml (
main.xml)
setContentView(R.layout.main) main.xml
onCreate()
onCreate()
.xml
4 Android 12 101
4.5 #5 List 1
List List
Menu
4.5.1
1.
List
2.
3.
<Reload> List
102 Android 36
4. <Prod-x> (Title)choice:
305.5
5. Menu <Exit>
4.5.2
Step-1:
Step-2:
Android ex05
Activity ex05
4 Android 12 103
data[2] = "Item-3";
xdata[2] = "Prod-z";
104 Android 36
price[0] = 305.5;
price[1] = 56.75;
price[2] = 100.25;
}
public String[] loadData() {
k = !k;
if(k) return xdata;
else return data;
}
public double getPrice(int i) { return price[i]; }
}
Step-3:
4.5.3
()
1. MVC(model-view-controller)
(Pattern)
2. ex05 Activity controller
3. ListView View view
4. model
5. DataModel dm = new DataModel();
DataModel
6. adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, dm.loadData());
ArrayAdapter dm.loadData()
( adapter)
7. lv.setAdapter(adapter);
lv adapter
8. lv.setOnItemClickListener(this);
ListView
this ex05
ex05
OnItemClickListener onItemClick ()
9. setContentView(lv);
4 Android 12 105
lv
4.5.4
1.
()
adapter DataModel
loadData() DataModel adapter
2.
lv.setAdapter(adapter);
ListView
106 Android 36
4.6
#6: List 2
List
ArrayList<Map<String, Object>>
4.6.1
1.
List
2.
4.6.2
Step-1:
Step-2:
Android ex06
Activity ex06
4 Android 12 107
import android.widget.AdapterView.OnItemClickListener;
public class ex06 extends Activity {
private ListView lv;
private TextView tv;
private DataModel dm;
private ArrayList<Map<String, Object>> coll;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
dm = new DataModel();
setContentView(R.layout.list);
lv = (ListView)findViewById(R.id.list);
lv.setOnItemClickListener(listener);
tv = (TextView)findViewById(R.id.text);
coll = dm.loadData();
SimpleAdapter adapter = new SimpleAdapter(this, coll,
android.R.layout.simple_list_item_1, new String[] { "prod_na" },
new int[] {android.R.id.text1});
lv.setAdapter(adapter);
}
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
tv.setTextColor(Color.YELLOW);
tv.setText(coll.get(arg2).get("prod_type").toString()); }
}; }
// ---- DataModel.java
package com.misoo.ex06;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-------------------------------------
108 Android 36
item.put("prod_na", "Windows");
coll.add(item);
return coll;
item.put("prod_type", "Mobile");
}}
Step-3:
/res/layout/list.xml
Step-4:
4.6.3
1.
(Table)
prod_na
prod_type
Linux
ST
Windows
Mobile
prod_na List
xml
"<list><item><prod_na>Linux</prod_na><prod_type>ST</prod_type></item>
<item><prod_na>Windows</prod_na><prod_type>Mobile</prod_type></item>
</list>"
4 Android 12 109
4.6.4
ListView UI View
Activity Context Android View-Context
ListView Activity
setContentView(lv);
}
110 Android 36
ListActivity
// ---- ex06_a.java ------------------------------------package com.misoo.ex06_a;
import java.util.ArrayList;
import java.util.Map;
import com.misoo.ex06_a.DataModel;
import android.app.ListActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ex06_a extends ListActivity {
private DataModel dm;
private ArrayList<Map<String, Object>> coll;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
dm = new DataModel();
coll = dm.loadData();
this.setListAdapter(new SimpleAdapter(this, coll,
android.R.layout.simple_list_item_1, new String[] { "prod_na" },
new int[] {android.R.id.text1}));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
setTitleColor(Color.RED);
setTitle(coll.get(position).get("prod_type").toString());
}}
// ---- DataModel.java
-------------------------------------
ex06 DataModel.java
4 Android 12 111
4.7
(#4) LinearLayout
4.7.1
1.
2.
112 Android 36
4.7.2
Step-2:
ListView
Activity ex07
4 Android 12 113
114 Android 36
Step-3:
/res/layout/list.xml
Step-4:
4.7.3
1.
LinearLayout
view_y
view_x view_y view_x
15
4 Android 12 115
2.
RelativeLayout r_layout = new RelativeLayout(this);
setContentView(r_layout);
3.
Activity( ex07)
LayoutInflater inflate = (LayoutInflater)
getSystemService( Context.LAYOUT_INFLATER_SE
RVICE);
LAYOUT_INFLATE_SERVICE inflate
3.
LinearLayout layout = (LinearLayout)inflate.inflate(R.layout.list, null, null);
inflateinflate()/res/layout/list.xml
LinearLayout
5. RelativeLayout.LayoutParams param
= new RelativeLayout.LayoutParams(120, WC);
RelativeLayout layout
120
6. layout.setId(1);
r_layout.addView(layout, param);
layout ID layout r_layout
TextView
ListView
r_Layout
layout
7. tv = (TextView)layout.findViewById(R.id.text);
ListView lv = (ListView)layout.findViewById(R.id.list);
116 Android 36
layoutViewtvlv
8. ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, data);
lv.setAdapter(adapter);
data[]lvList
9.
tv = (TextView)layout.findViewById(R.id.text);
ListView lv = (ListView)layout.findViewById(R.id.list);
10.
11.
layoutViewtvlv
Button btn1 = new Button(this);
btn1.setId(2);
btn1.setText("OK");
btn1.setOnClickListener(listener);
ID2OKlistener
param = new RelativeLayout.LayoutParams(60, WC);
param.addRule(RelativeLayout.RIGHT_OF, 1);
param.leftMargin = 15;
param.topMargin = 20;
r_layout.addView(btn1, param);
60 layout 15
20btn1r_layout
20
TextView
OK
ListView
15
r_Layout
layout
<Exit>
4 Android 12 117
4.7.4
118 Android 36
4.8
#8 (Table Layout)
LinearLayout RelativeLayout
4.8.1
1.
2. 5 View 4 view 2
(Table)
4.8.2
Step-1:
Step-2:
Android ex08
Activity ex08
4 Android 12 119
import android.widget.TableRow;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
public class ex08 extends Activity implements OnClickListener {
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
RelativeLayout r_layout = new RelativeLayout(this);
setContentView(r_layout);
TableLayout tableLayout = new TableLayout(this);
r_layout.addView(tableLayout, new RelativeLayout.LayoutParams(WC, WC));
tableLayout.setId(1);
TableRow tableRow1 = new TableRow(this);
tableLayout.addView(tableRow1, new TableLayout.LayoutParams(WC, WC));
ImageView iv = new ImageView(this);
tableRow1.addView(iv);
iv.setImageDrawable(getResources().getDrawable(R.drawable.star_big_on));
EditText edit1 = new EditText(this);
tableRow1.addView(edit1);
TableRow tableRow2 = new TableRow(this);
ImageView iv2 = new ImageView(this);
iv2.setImageDrawable(getResources().getDrawable(R.drawable.gallery_photo_4));
tableRow2.addView(iv2);
EditText edit2 = new EditText(this);
tableRow2.addView(edit2);
tableLayout.addView(tableRow2, new TableLayout.LayoutParams(WC, WC));
Button btn = new Button(this); btn.setText("Exit");
btn.setOnClickListener(this);
RelativeLayout.LayoutParams param =
new RelativeLayout.LayoutParams(WC, WC);
param.addRule(RelativeLayout.BELOW, 1);
param.topMargin = 20;
r_layout.addView(btn, param);
}
public void onClick(View arg0) { finish();
120 Android 36
Step-3:
4.8.3
1.
view TableLayout
Linda
0936-345678
Wander
0931-543211
Tom
0945-678888
view
TableLayout
TableRow
TextView
2.
ex08
view
4 Android 12 121
RelativeLayout
TableLayout
TableRow
Exit
Button
EditText
ImageView
3. view
RelativeLayout r_layout = new RelativeLayout(this);
setContentView(r_layout)
4.
TableLayout r_layout
TableLayout tableLayout = new TableLayout(this);
r_layout.addView(tableLayout, new RelativeLayout.LayoutParams(WC, WC));
5.
TableRow tableLayout
TableRow tableRow1 = new TableRow(this);
tableLayout.addView(tableRow1, new TableLayout.LayoutParams(WC, WC));
6.
view tableRow
ImageView iv = new ImageView(this);
tableRow1.addView(iv);
122 Android 36
4.9 #9
Activity
setContentView()
4.9.1
1.
2.
<MENU>
3.
<Change>
4 Android 12 123
4.
<Change>
4.9.2
Step-1:
Step-2:
Android ex09
Activity ex09
124 Android 36
Step-3:
/res/layout/list.xml
4 Android 12 125
</LinearLayout>
Step-4:
4.9.3
1.
main.xml layout1
LayoutInflater inflate = (LayoutInflater)
getSystemService( Context.LAYOUT_INFL
ATER_SERVICE);
layout1 = (LinearLayout)inflate.inflate(R.layout.main, null, null);
2.
list.xml layout2
layout2 = (LinearLayout)inflate.inflate(R.layout.list, null, null);
8.
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case CHG_ID:
selection = !selection;
if(selection) setContentView(layout1);
else
setContentView(layout2);
//.
}
4.9.4
LayoutInflater inflate = (LayoutInflater)
getSystemService( Context.LAYOUT_INFL
ATER_SERVICE);
layout1 = (LinearLayout)inflate.inflate(R.layout.main, null, null);
setContentView(layout1);
setContentView(R.layout.main)
126 Android 36
4.10
#10 View
4.10.1
1.
2.
DrawView
RadioButton DrawView
3.
RadioButton DrawView
4.10.2
Step-1:
Step-2:
Android ex10
Activity ex10
4 Android 12 127
// ---- DrawView.java
package com.misoo.ex10;
-------------------------------------
128 Android 36
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
private Paint pa = new Paint();
private boolean yn = false;
public DrawView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
yn = !yn;
if(yn) pa.setColor(Color.GRAY);
else pa.setColor(Color.WHITE);
canvas.drawRect(10, 10, 100, 100, pa);
pa.setColor(Color.YELLOW);
if(yn) pa.setColor(Color.YELLOW);
else pa.setColor(Color.BLUE);
pa.setStrokeWidth(4);
pa.setStrokeCap(Paint.Cap.ROUND);
canvas.drawLine(10, 55, 100, 55, pa);
canvas.drawLine(55, 10, 55, 100, pa);
pa.setColor(Color.RED);
canvas.drawRect(50, 50, 60, 60, pa);
}
}
Step-3:
4.10.3
1.
Layout View
View
Context Activity
Android
4 Android 12 129
Button btn1 = new Button(this);
Button btn2 = new Button(this);
Context( Activity)( this) Button
Context View
btn1
btn2
Activity
(Context )
2.
Button
Button
(View )
Android View
ButtonListViewRadioButton
RadioButton ra;
ra = new RadioButton(this);
param = new LinearLayout.LayoutParams(WC, WC);
130 Android 36
param.topMargin = 40;
layout.addView(ra, param);
Button layout
View ?
DrawView
ButtonTextView
10. DrawView
LinearLayout.LayoutParams param =
new LinearLayout.LayoutParams(150, 300);
param.leftMargin = 1;
dv = new DrawView(this);
layout.addView(dv, param);
9.
<<Google Android
>>
1. UI
2. Android C
3. Android
4 Android 12 131
RadioButton
RadioGroup RadioButton
4.11.1
1.
2.
3.
<Change Color>
RadioButton RadioGroup
132 Android 36
4.11.2
Step-1:
Step-2:
Android ex11
Activity ex11
4 Android 12 133
btn.setBackgroundDrawable(dw);
btn.setOnClickListener(listener);
para = new LinearLayout.LayoutParams(WC, WC);
layout.addView(btn, para);
rg_layout = new RadioGroup(this);
params = new RadioGroup.LayoutParams(WC, WC);
rg_layout.setOrientation(RadioGroup.VERTICAL);
rg_layout.setLayoutParams(params);
rg_layout.setOnCheckedChangeListener(this);
RadioButton button1 = new RadioButton(this);
button1.setText("Yellow"); button1.setId(1001);
params = new RadioGroup.LayoutParams(WC, WC);
rg_layout.addView(button1,params);
RadioButton button2 = new RadioButton(this);
button2.setText("Blue"); button2.setId(1002);
params = new RadioGroup.LayoutParams(WC, WC);
rg_layout.addView(button2,params);
setContentView(layout);
}
public int getColor() { return mColor; }
private OnClickListener listener = new OnClickListener() {
public void onClick(View v) { setContentView(rg_layout); }
};
public void onCheckedChanged(RadioGroup arg0, int arg1) {
if(arg0.getCheckedRadioButtonId() == 1001) mColor = Color.YELLOW;
else mColor = Color.BLUE;
this.show_layout_01();
}}
Step-3:
View DrawView
// ---- DrawView.java
package com.misoo.ex11;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
-------------------------------------
134 Android 36
Step-4:
4.11.3
4 Android 12 135
4.12.1
Activity Activity
2.
1.
Activity
Activity
4.12.2
Step-1:
Step-2:
Android ex12
Activity ex12
136 Android 36
super.onCreate(icicle);
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
para = new LinearLayout.LayoutParams(230, 140);
DrawView dv = new DrawView(this);
layout.addView(dv, para);
Button btn = new Button(this);
btn.setText("Change Color"); btn.setOnClickListener(listener);
para = new LinearLayout.LayoutParams(WC, WC);
layout.addView(btn, para);
setContentView(layout);
}
public int getColor() { return mColor; }
private OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
Intent in = new Intent(ex12.this, rgActivity.class);
startActivityForResult(in,RG_REQUEST);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RG_REQUEST) {
if (resultCode == RESULT_CANCELED)
setTitle("Canceled...");
else if(resultCode == RESULT_OK) {
String data_str = (String)data.getCharSequenceExtra("DataKey");
setTitle(data_str);
if(data_str.contains("Y")) mColor = Color.YELLOW;
else mColor = Color.BLUE;
}
}}}
Step-3:
Activity rgActivity
// ---- rgActivity.java
package com.misoo.ex12;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
-------------------------------------
4 Android 12 137
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class rgActivity extends Activity implements OnCheckedChangeListener{
private final int WC = RadioGroup.LayoutParams.WRAP_CONTENT;
private RadioGroup rg_layout;
RadioGroup.LayoutParams params;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
rg_layout = new RadioGroup(this);
params = new RadioGroup.LayoutParams(WC, WC);
rg_layout.setOrientation(RadioGroup.VERTICAL);
rg_layout.setLayoutParams(params);
rg_layout.setOnCheckedChangeListener(this);
RadioButton button1 = new RadioButton(this);
button1.setText("Yellow");
button1.setId(1001);
params = new RadioGroup.LayoutParams(WC, WC);
rg_layout.addView(button1,params);
RadioButton button2 = new RadioButton(this);
button2.setText("Blue"); button2.setId(1002);
params = new RadioGroup.LayoutParams(WC, WC);
rg_layout.addView(button2,params);
setContentView(rg_layout);
}
public void onCheckedChanged(RadioGroup arg0, int arg1) {
String cc;
if(arg0.getCheckedRadioButtonId() == 1001) cc = "Y";
else cc = "B";
Bundle bundle = new Bundle();
bundle.putString("DataKey", cc);
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}}
Step-4:
View DrawView
package com.misoo.ex12;
import android.content.Context;
138 Android 36
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
private Paint pa;
private Context ctx;
public DrawView(Context context) {
super(context);
ctx = context; pa = new Paint();
}
@Override protected void onDraw(Canvas canvas) {
ex12 obj = (ex12)ctx;
pa.setColor(obj.getColor()); canvas.drawRect(10, 10, 100, 100, pa);
pa.setColor(Color.GREEN);
pa.setStrokeWidth(4);
pa.setStrokeCap(Paint.Cap.ROUND);
canvas.drawLine(10, 55, 100, 55, pa); canvas.drawLine(55, 10, 55, 100, pa);
pa.setColor(Color.RED);
canvas.drawRect(50, 50, 60, 60, pa);
}}
Step-5:
4.12.3
Activityex12 ex12
DrawView Button
2.
<Change Color> onClick()
1.
3. rgActivity onCheckedChanged()
public void onCheckedChanged(RadioGroup arg0, int arg1)
{ String cc;
4 Android 12 139
4.
5.
setResult() cc ex12
finish() rdActivity ex12
ex12 ex12 onActivityResult()
4.12.4
rgActivity
(Reuse)
Activity
140 Android 36
Misoo ?
( )
Misoo
TEL: (02) 2739-8367
E-mail: misoo.tw@gmail.com
Misoo
TEL: (02) 2739-8367
TEL: 400-886-0806
***
Java
E-mail: sv@softcompass.com
Misoo
Android
E-mail: misoo.tw@gmail.com
***
C/C++
Android
<<
Androi d >>
1.
2. Android (Object-Oriented
Application Framework)
3. Java Android
4. C/C++ Android
5. Android
5 Use
Case 141
Use Case
5.1
5.2
Use Case
Android Use Case
142 Android 36
Model
Language) Use
Case
Android
Use Case Use Case
(Layout) Use Case
Activity
Layout 4
Step-1
Use Case
5 Use
Case 143
Use Case
( ) Use Case
Use Case
Use Case
Use Case
(Layout)
5-3 UCDx UCDy
UCDz
144 Android 36
(Layout) Activity
Activity
5-4 Activity_A Activity_B
Activity 1
1 1 Activity
5-5
5 Use
Case 145
Android
1:1 N:1 Android
Use Case
146 Android 36
5.2
Use Case
(
5-6) Android Use Case
5 Use
Case 147
-A
Use Case
Activity
148 Android 36
Android
2.
-B
Use Case
Activity
Android
]
Misoo Android
6 Use
Case ---
-A 6
149
Use Case
--- -A6 (#13~#18)
6.1
6.2
6.3
6.4
6.5
6.6
150 Android 36
6-1
Use Case
( 6 ) ( 7 ) Android
Use
Case Android
-A
-B
6 Use
Case ---
-A 6
151
6.1
Use
Case
-A Use Case
-A
Use Case
Activity
Activity
BaseActivity
InclusionActivity BaseActivity
User startActivity()
InclusionActivity Inclusion Use Case
BaseActivity
Android Use Case
6.1.1
152 Android 36
6.1.2 Activity
-A Activity
ac01 Activity ac01_layout
pu_layout puckup Activity
6.1.3
Activity UML
(Sequence Diagram)
---- 1 create()
(
Android
6 Use
Case ---
-A 6
153
)ac01 ac01_layout
---- 2 pressPickup() Menu <Pick
Up An Item> ac01 Android
startActivity() ( )pickup ( Activity )
pu_layout
---- 3pickUpAnItem() pu_layout Menu
pickup
SharedPreferences ac01
---- 4 pressShowResult() Menu <Show
Result> ac01 SharedPreferences
pickup
6.1.4
1.
ac01_layout <MENU>
2.
3.
<MENU>
154 Android 36
4.
ac01_layout
5.
6.
6.1.5
6 Use
Case ---
-A 6
package com.misoo.ex01_01;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class ac01 extends Activity {
public static final int PICKUP_ID = Menu.FIRST;
public static final int SHOW_ID = Menu.FIRST + 1;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main); }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, PICKUP_ID, "Pick Up An Item");
menu.add(1, SHOW_ID, "Show Result"); return true; }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case PICKUP_ID:
Intent in = new Intent(ac01.this, pickup.class);
startActivity(in);
return true;
case SHOW_ID:
SharedPreferences passwdfile = getSharedPreferences( "ITEM", 0);
String im = passwdfile.getString("ITEM", null);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("choice: " + im);
return true; }
return super.onOptionsItemSelected(item);
}}
Step-3:
Activity pickup
155
156 Android 36
import android.view.Menu;
public class pickup extends Activity {
public static final int ITEM_1_ID = Menu.FIRST;
public static final int ITEM_2_ID = Menu.FIRST + 1;
public static final int ITEM_3_ID = Menu.FIRST + 2;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main); }
@Override public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, ITEM_1_ID, 0, "item-1");
menu.add(0, ITEM_2_ID, 1, "item-2");
menu.add(0, ITEM_3_ID, 2, "item-3");
return true;
}
@Override public boolean onOptionsItemSelected(Menu.Item item) {
Editor passwdfile = getSharedPreferences("ITEM", 0).edit();
passwdfile.putString("ITEM",item.getTitle().toString());
passwdfile.commit();
finish();
return super.onOptionsItemSelected(item);
}}
Step-4:
6.1.6
1. ac01
Intent in = new Intent(ac01.this, pickup.class);
startActivity(in);
2.
Activitypickup
pickup
Editor passwdfile = getSharedPreferences("ITEM", 0).edit();
passwdfile.putString("ITEM",item.getTitle().toString());
passwdfile.commit();
finish();
finish() item
SharedPreferences
6 Use
Case ---
-A 6
3.
ac01
SharedPreferences passwdfile = getSharedPreferences("ITEM", 0);
String im = passwdfile.getString("ITEM", null);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("choice: " + im);
SharedPreferences item TextVie w
6.2
#14: startActivityForResult()
startActivity()
6.2.1
6.2.2 Activity
6.2.3
(Sequence Diagram)
Android
157
158 Android 36
6-3 startActivityForResult()
6 Use
Case ---
-A 6
159
6.2.4
5 <Show Result>
TextView
6.2.5
Step-1:
Step-2:
Android ex02
Activity ac01
160 Android 36
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICKUP_REQUEST) {
if (resultCode == RESULT_CANCELED)
setTitle("Canceled...");
else if(resultCode == RESULT_OK) {
TextView tv = (TextView)findViewById(R.id.tv);
String data_str = (String)data.getCharSequenceExtra("DataKey");
tv.setText("choice: " + data_str);
}
}
}}
Step-3:
Activity pickup
// ---- pickup.java
package com.misoo.ex01_02;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
----
6 Use
Case ---
-A 6
161
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
return super.onOptionsItemSelected(item);
}}
Step-4:
6.2.6
1. ac01
Intent in = new Intent(ac01.this, pickup.class);
startActivityForResult (in,PICKUP_REQUEST);
Activitypickup startActivityForResult ()
2. pickup
bundle.putString("DataKey", item.getTitle().toString());
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
setResult() item mIntent
3. ac01 ac01 onActivityResult()
protected void onActivityResult(int requestCode, int resultCode,
String data, Bundle extras) {
//..
}
data item
162 Android 36
6.3
pickup Menu
ListView
ListView
6.3.1
ListView Menu
6.3.2
ListView Menu
6.3.3
Step-1:
Step-2:
Android ex01_03
Activity ac01
//-------------------------------------------------------------------------------------------------Step-3:
Activity pickup
6 Use
Case ---
-A 6
163
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class pickup extends Activity {
private ListView lv;
private Map<String, Object> item;
private List<Map<String, Object>> coll;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
coll = new ArrayList<Map<String, Object>>();
lv = new ListView(this);
this.addData();
SimpleAdapter adapter = new SimpleAdapter(this, coll,
android.R.layout.simple_list_item_1, new String[] { "title" },
new int[] {android.R.id.text1});
lv.setAdapter(adapter); lv.setOnItemClickListener(listener);
setContentView(lv); }
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String str = coll.get(arg2).get("price").toString();
Bundle bundle = new Bundle(); bundle.putString("DataKey", str);
Intent mIntent = new Intent(); mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}};
protected void addData() {
item = new HashMap<String, Object>();
item.put("title", "Item-1"); item.put("price", "US$50"); coll.add(item);
item = new HashMap<String, Object>();
item.put("title", "Item-2"); item.put("price", "US$800"); coll.add(item);
item = new HashMap<String, Object>();
item.put("title", "Item-3"); item.put("price", "US$777"); coll.add(item);
}}
Step-4:
6.3.4
1.
4 ListView
Use Case
164 Android 36
6.4
4 ListActivity
Use Case
6.4.1
6.4.2
1.
2.
<Pickup>
6 Use
Case ---
-A 6
3.
6.4.3
Step-1:
Step-2:
Android ex01_04
Activity ac01
165
166 Android 36
Step-3:
Activity pickup
6 Use
Case ---
-A 6
167
168 Android 36
Step-4:
6.4.4
1. 4 ListActivity ListView
Android ListView Activity
ListActivity
2. pickup ListActivity ListView
setListAdapter() SimpleAdapter
Activity
6.5
#17: .xml
6 Use
Case ---
-A 6
6.5.1
ac01.xml
6.5.2
6.5.3
Step-1:
Step-2:
Android ex01_05
Activity ac01
169
170 Android 36
Step-3:
Activity pickup
//---------------------------------------------------------------------------------Step-4:
/res/layout/ac01.xml
6 Use
Case ---
-A 6
Step-5:
6.5.4
onCreate()
ac01.xml onCreate()
setContentView(R.layout.ac01); ac01.xml
2. ac01.xml
1.
6.6
#18: onResume()
1 startActivity() pickup
pickup SharedPreferences ac01
SharedPreferences
2~5
startActivityForResult() pickup
startActivity()
onResume() onStart()
6.6.1
6.6.2
Activity
171
172 Android 36
6.6.3
6-4 onResume()
pu_layout
---- 3pickUpAnItem() pu_layout Menu
6 Use
Case ---
-A 6
173
---
3.1 pickup
SharedPreferences
---- 3.2 pickup finish()
ac01
---- 3.2.1 ac01 ac01
onResume() SharedPreferences
item
6.6.4
6.6.5
Step-1:
Step-2:
Android ex01_06
Activity ac01
174 Android 36
btn2.setBackgroundResource(R.drawable.x_jude); btn2.setOnClickListener(this); }
@Override protected void onResume() {
super.onResume();
if(init_state) { init_state = false; return;
}
SharedPreferences passwdfile = getSharedPreferences( "ITEM", 0);
String im = passwdfile.getString("ITEM", null);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText( im ); }
public void onClick(View v) {
if (v == btn){ Intent in = new Intent(ac01.this, pickup.class);
startActivity(in); }
if(v == btn2){ this.finish(); }
}}
Step-3:
Activity pickup
6 Use
Case ---
-A 6
175
lv.setBackgroundResource(R.drawable.gallery_photo_4);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); }
@Override public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, EXIT_ID, 2, "Exit");
MenuItem im = menu.findItem(EXIT_ID);
im.setIcon(R.drawable.exit_em2);
return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case EXIT_ID:
if(current > -1){
String str = coll.get(current).get("title").toString();
Editor passwdfile = getSharedPreferences("ITEM", 0).edit();
passwdfile.putString("ITEM",str);
passwdfile.commit();
finish(); }
break; }
return super.onOptionsItemSelected(item);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
current = position; }
protected void addData() {
item = new HashMap<String, Object>();
item.put("title", "Item-1"); item.put("price", "US$50"); coll.add(item);
item = new HashMap<String, Object>();
item.put("title", "Item-2"); item.put("price", "US$800"); coll.add(item);
item = new HashMap<String, Object>();
item.put("title", "Item-3"); item.put("price", "US$777"); coll.add(item);
}}
Step-4:
/res/layout/ac01.xml
176 Android 36
6.6.6
1. Android Activity
6-5 (:http://code.google.com/android/reference/android/app/Activity.html)
6 Use
Case ---
-A 6
177
2.
ac01 startActivity() pickup
ac01 onPause() onStop()
ac01
pickup ac01
ac01 onRestart()onStart() onResume()
ac01 onResume()
onRestart()onStart()
onResume() SharedPreferences
item
6.6.7
Android ac01
Android Activity
(Process)
Android
Activity
Activity
(Focus) Activity
Activity
1.
2.
3.
()
( )
---- onPause()
---- onResume()
---- 6-5
( )
---- onPause()
onStop()
178 Android 36
----
onRestart()
onStart() onResume()
---- 6-5
ac01
onPause() onStop()
ac01
onRestart()
onStart()onResume()
onResume()
(tom-kao.blogspot.com)
Android
Android
..
7 Use
Case ---
-B 2
179
Use Case
--- -B2 (#19~#20)
7.1
7.2
#19 Activity
#20
180 Android 36
-B Use Case
-B
Use Case
Activity
Activity ac01
Use Case User
Use Case User Android
7 Use
Case ---
-B 2
181
7.1
#19 Activity
7.1.1
7.1.2
Activity
-B Activity
Activity ac01
Activity ac01_layout pu_layout
Android ( Layout)
(View, Button )
Android (Activity)(Activity)
7.1.3
Activity UML
182 Android 36
7-2 ac01
7 Use
Case ---
-B 2
7.1.4
1.
ac01_layout
2.
<Pickup> pu_layout
3.
List ac01_layout
7.1.5
Step-1:
Step-2:
Android ex01_07
Activity ac01
// ---- ac01.java
package com.misoo.ex01_07;
import android.app.Activity;
----
183
184 Android 36
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class ac01 extends Activity implements OnClickListener {
private String[] data = {"Item-1", "Item-2", "Item-3"};
private Button btn, btn2;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
set_ac01_layout(); }
public void set_ac01_layout() {
setContentView(R.layout.ac01);
btn = (Button)findViewById(R.id.pu_btn);
btn.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.exit_btn);
btn2.setOnClickListener(this); }
public void onClick(View v) {
if (v == btn) this.set_pu_layout();
if(v == btn2) this.finish(); }
public void set_pu_layout(){
setContentView(R.layout.pickup);
ListView lv = (ListView)findViewById(R.id.list);
ArrayAdapter<String> arrayAdapter
= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(listener);
}
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
set_ac01_layout();
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("choice: " + data[arg2]);
}};
}
Step-3:
/res/layout/ac01.xml
7 Use
Case ---
-B 2
Step-4:
/res/layout/pickup.xml
Step-5:
185
186 Android 36
7.1.6
1. ac01
public void set_ac01_layout() {
setContentView(R.layout.ac01);
//
}
7 Use
Case ---
-B 2
187
7.2
#20:
Step-1 Use Case ( )
Step-2 .xml (
)
Step-3 .xml
Step-4 Activity
Use Case 1:1 Use Case
N:1 Activity N:1
Activity 1:1 Android
!
7.2.1
7.2.2
Activity
ac01
7.2.3
Activity
(Sequence Diagram)
Android
188 Android 36
7 Use
Case ---
-B 2
7.2.4
7.2.5
Step-1:
Step-2:
Android ex01_08
Activity ac01
189
190 Android 36
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class ac01 extends Activity implements OnClickListener {
private String[] data = {"Item-1", "Item-2", "Item-3"};
private Button btn, btn2;
private ListView lv;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
set_ac01_r_layout();
}
private void set_ac01_r_layout() {
RelativeLayout rel_layout = new RelativeLayout(this);
setContentView(rel_layout);
LayoutInflater inflate = (LayoutInflater) getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout)
inflate.inflate(R.layout.ac01, null);
layout.setId(1);
RelativeLayout.LayoutParams rel_param =
new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
rel_layout.addView(layout, rel_param);
btn = (Button)findViewById(R.id.pu_btn);
btn.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.exit_btn);
btn2.setOnClickListener(this);
LinearLayout layout_p = (LinearLayout)
inflate.inflate(R.layout.pickup, null);
layout_p.setId(2);
rel_param = new RelativeLayout.LayoutParams(
7 Use
Case ---
-B 2
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
rel_param.addRule(RelativeLayout.RIGHT_OF, 1);
rel_layout.addView(layout_p, rel_param);
lv = (ListView)layout_p.findViewById(R.id.list);
ArrayAdapter<String> arrayAdapter
= new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, data);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(listener);
}
public void onClick(View v) {
if (v == btn) lv.setBackgroundColor(Color.BLUE);
if(v == btn2) this.finish();
}
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("choice: " + data[arg2]);
lv.setBackgroundColor(Color.DKGRAY);
}
};
}
Step-3:
/res/layout/ac01.xml
Step-4:
/res/layout/ac01.xml
Step-5:
7.2.6
1.
2.
ac01.xml pickup.xml
191
192 Android 36
3.
LayoutInflater inflate = (LayoutInflater)
getSystemService( Context.LAYOUT_INFLA
TER_SERVICE);
LinearLayout layout = (LinearLayout)inflate.inflate(R.layout.ac01, null, null);
//
rel_layout.addView(layout, rel_param);
ac01.xml layout layout
rel_layout
4.
LinearLayout layout_p
= (LinearLayout)inflate.inflate(R.layout.pickup, null, null);
//
rel_layout.addView(layout_p, rel_param);
pickup.xml layout_p layout_p
rel_layout .xml
<<>>
8 SQLite
193
SQLite
8.2
(Table)
8.3
8.4
8.5
8.6
8.7
SQL
8.8 SQL
8.1
194 Android 36
8.1
(Relational Database)
1970
(Table)
SQL
SQLite
Android
(Relational
Database)
SQLite
(RDBMS)
SQL Server
SQL
Oracle
Sybase Microsoft SQL Server Access SQL
8.2 (Table)
(Column) (Row)
(Table)
SQL
create table table_name
(column_name1 column_type, column_name2 column_type, );
8 SQLite
195
Student
stud_no
stud_name
101
102
103
Mike
Linda
Tom
8-1
( .Net )
196 Android 36
8.3
(Relationship)
SQL
select stud_no, stud_name from Student;
SQL Student (Row)
( 102
) SQL
select stud_no, stud_name from Student where stud_no = 102;
stud_no
102
stud_name
Linda
102
select stud_no, stud_name from Student where stud_no <> 102 ;
stud_no
101
103
stud_name
Mike
Tom
101 Linda
select stud_name from Student
where stud_no <> 101 and stud_name <> Linda;
stud_name
Tom
8 SQLite
197
Student
Course
Course
course_name
DATABASE
ART
DATABASE
stud_no
101
101
102
Teacher
couse_name
DATABASE
ART
MS OFFICE
HISTORY
teacher_name
?
?
8.5
198 Android 36
Student
(stud_no,
stud_name,
sex, age, grade, phone, )
stud_no
stud_namesexgradephone
(1:1)
1:1
1:1
(1:N)
1:N
(N:N)
8.6
SQL
SQL JOIN
Student Course
Student
stud_no
stud_name
101
102
103
Mike
Linda
Tom
8 SQLite
199
Course
course_name
stud_no
DATABASE
ART
DATABASE
101
101
102
SQL
select Student.stud_name, Course.course_name from Student, Course
where Student.stud_no = Course.stud_no;
Student.stud_name
Mike
Mike
Linda
8.7
Course.course_name
DATABASE
ART
DATABASE
SQL
SQL
New_Course
course_name
DATABASE
ART
DATABASE
stud_no
101
101
102
score1
70.0
60.0
95.0
score2
74.5
45.0
90.5
SQL
select SUM(score1), SUM(score2) from New_Course;
200 Android 36
SUM(score1)
SUM(score2)
225.0
210.0
AVG(score1)
AVG(score2)
73.0
8.8
70.0
SQL
GROUP BY (Group)
select course_name, SUM(score1), SUM(score2) from New_Course
group by course_name
course_name
DATABASE
ART
SUM(score1)
165.0
60.0
SUM(score2)
165.0
45.0
GROUP BY SUM()
GROUP BY
(Column)
9 5
201
9.1
9.2
9.3
9.4
9.5
#21SQLite
#22 SQLite ContentProvider
#23 SQLite ContentProvider
#24 SQLite onCreate()onResume()
#25(Transaction)
202 Android 36
9.1 #21SQLite
(Package) ( )
Activityac01 ac02
9.1.1
ac01
1.
2.
9 5
203
9.1.2
ac02
1. ac01 ac02
2.
3.
4.
5.
6.
204 Android 36
9.1.3 ac01
9.1.3.1
Step-1:
Step-2:
Android SQ01
Activity ac01
9 5
205
btn.setOnClickListener(this);
layout.addView(btn, new LinearLayout.LayoutParams(WC, WC));
btn2 = new Button(this);
btn2.setText("drop Student table");
btn2.setOnClickListener(this);
layout.addView(btn2, new LinearLayout.LayoutParams(WC, WC));
btn3 = new Button(this);
btn3.setText("insert a record");
btn3.setOnClickListener(this);
layout.addView(btn3, new LinearLayout.LayoutParams(WC, WC));
btn4 = new Button(this);
btn4.setText("select *");
btn4.setOnClickListener(this);
layout.addView(btn4, new LinearLayout.LayoutParams(WC, WC));
btn5 = new Button(this);
btn5.setText("Exit");
btn5.setOnClickListener(this);
layout.addView(btn5, new LinearLayout.LayoutParams(WC, WC));
setContentView(layout);
}
//---------------------------------------------------------------------------private DatabaseHelper mOpenHelper;
public void onClick(View v){
if (v == btn){
mOpenHelper = new DatabaseHelper(v.getContext());
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String sql = "create table Student(" + "stud_no text not null, "
+ "stud_name text );";
try { db.execSQL(sql); setTitle("create table ok!"); }
catch (SQLException e) {
Log.e("ERROR", e.toString());
setTitle("create table Error!");
}}
if (v == btn2){
mOpenHelper = new DatabaseHelper(v.getContext());
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String sql = "drop table Student";
try { db.execSQL(sql); setTitle("drop table ok!"); }
catch (SQLException e) {
Log.e("ERROR", e.toString());
setTitle("drop table Error!");
}}
if (v == btn3){
mOpenHelper = new DatabaseHelper(v.getContext());
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String sql_1 = "insert into Student (stud_no, stud_name) values('S108', 'Lily Chen');";
String sql_2 = "insert into Student (stud_no, stud_name) values('S201', 'Tom Kao');";
206 Android 36
String sql_3 = "insert into Student (stud_no, stud_name) values('S333', 'Peter Rabbit');";
try { db.execSQL(sql_1);
db.execSQL(sql_2);
db.execSQL(sql_3);
setTitle("insert records ok!");
} catch (SQLException e) { Log.e("ERROR", e.toString());
}
}
if (v == btn4){
mOpenHelper = new DatabaseHelper(v.getContext());
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
String col[] = {"stud_no", "stud_name" };
cur = db.query("Student", col, null, null, null, null, null);
Integer n = cur.getCount();
String ss = Integer.toString(n);
setTitle(ss + " records");
cur.moveToFirst();
}
if (v == btn5) finish();
}}
Step-3:
9.1.3.2
1.
ac01
StudDB StudDB
2.
if (v == btn){
..
String sql = "create table Student(" + "stud_no text not null, "
+ "stud_name text );";
try { db.execSQL(sql); setTitle("create table ok!"); }
catch (SQLException e)
{ Log.e("ERROR", e.toString());
setTitle("create table Error!");
}}
SQL sql db.execSQL() SQL
SQLite
3. String col[] = {"stud_no", "stud_name" };
cur = db.query("Student", col, null, null, null, null, null);
9 5
207
9.1.4
ac02
9.1.4.1
db.query()
208 Android 36
9 5
209
Step-2:
SQ01/AndroidManifest.xml
210 Android 36
Step-3:
9.1.4.2
1.
ac02
SQL
String sql = "insert into Student (stud_no, stud_name)
values ('S108', 'Lily Chen');";
db.execSQL(sql_1);
Android ContentValues
db.insert()
ContentValues cv = new ContentValues();
cv.put("stud_no", "S108");
cv.put("stud_name", "Lily Chen");
db.insert("Student", null, cv);
2.
db.query()
cur.getCount()
9 5
211
}
cur.isAfterLast()
cur.getString(0) 1 cur.getString(0) 2
MVC
SQLite Model
9.2.1
1.
SQLite ListView
2.
9.2.2
Step-1:
Step-2:
SQ02
Activity ac01
212 Android 36
9 5
213
}
}
Step-3:
ContentProvider DataProvider
214 Android 36
Step-4:
SQ02/AndroidManifest.xml
Step-5:
9 5
215
9.2.3
}
StudDB_2 Student
3.
AndroidManifest.xml
<provider android:name="DataProvider"
android:authorities="com.misoo.provider.SQ02">
</provider>
4.
Android DataProvider
SQLite adapter
ListView
216 Android 36
(Loosely-Coupled) ( PnP Plug and
Play) ContentProvider
Linter (DBMS)
SQLite
SQLite Linter Android
9.3.1
1.
ac01
9 5
217
ac01
218 Android 36
5.
<Exit>
9.3.2
9 5
219
220 Android 36
Step-3:
ListActivity DispActivity
// ---- DispActivity.java
package com.misoo.SQ03;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.SimpleAdapter;
import android.widget.ListView;
----
9 5
221
Step-4:
Activity DataProvider
222 Android 36
} catch (SQLException e) {
Log.e("ERROR", e.toString());
}}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}}
private DatabaseHelper mOpenHelper;
@Override public boolean onCreate() {
mOpenHelper = new DatabaseHelper(getContext());
return true; }
@Override public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = db.query(TABLE_NAME, projection, null, null, null, null, null);
return c; }
@Override public String getType(Uri uri)
{ return null; }
@Override public Uri insert(Uri uri, ContentValues initialValues) {
String field_1 = initialValues.get("stud_no").toString();
String field_2 = initialValues.get("stud_name").toString();
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String sql_1 = "insert into "+ TABLE_NAME +
" (stud_no, stud_name) values('" + field_1 + "', '" + field_2 + "');";
try { db.execSQL(sql_1); }
catch (SQLException e) { Log.e("ERROR", e.toString()); }
return uri; }
@Override public int delete(Uri uri, String where, String[] whereArgs) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.delete(where, whereArgs[0] + "='" + whereArgs[1] + "'", null);
return 0; }
@Override public int update(Uri uri, ContentValues values,
String where, String[] whereArgs) {
return 0;
}}
Step-5:
SQ02/AndroidManifest.xml
9 5
223
Step-6:
9.3.3
1.
AndroidManifest.xml DataProvider
DataProvider
provider
onCreate()
224 Android 36
onPause() Activity
onResume() DataPersist SQLite
onPause() DataPersist DataPersist
SQLite onResume() DataPersist
DataPersist SQLite
9.4.1
1.
SQLite ListView
2.
9 5
225
9.4.2
226 Android 36
Step-3:
Activity DispActivity
9 5
227
}};
Step-4:
DataPersist
228 Android 36
Step-5:
9.4.3
1.
onCreate()
dp = new DataPersist(this);
dp.setConditionToNew();
dp.initData();
9 5
229
dp initData() 3
setConditionToNew()'NEW' SharedPreferences
2. ac01 <Go> onClick()
startActivity() DispActivity
onPause() dp dp
null
3. ac01 Android
4. DispActivity ac01 onResume()
if( dp == null)
dp = new DataPersist(this);
dpnullonPause()SharedPreferences
dp
5. ac01 DispActiviy DataPersist
setConditionToNew() SharedPreferences
6.
setConditionToNew() ('NEW' 'OLD')
SharedPreferences
(Commit) SQLite
SharedPreferences
SQLite
SharedPreferences ( )
COMMIT SQLite
9.5.1
1.
ac01 INIT
230 Android 36
2.
3.
Menu <MENU>
<Input> INPUT (
)
5. <Commit> COMMIT ac01
4.
9 5
231
9.5.2
Step-1: Android SQ05
ac01.java
DatabaseHelper.java DispActivity.java
TransActivity.java 4
Step-2: Activity ac01
//---------- ac01.java -------------------------------package com.misoo.SQ05;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
232 Android 36
9 5
233
Step-3:
SQLiteOpenHelper DatabaseHelper
Step-4:
ListActivity DispActivity
234 Android 36
import android.widget.SimpleAdapter;
import android.widget.ListView;
public class DispActivity extends ListActivity {
private DatabaseHelper mOpenHelper;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mOpenHelper = new DatabaseHelper(this);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String col[] = {"number", "name"};
Cursor cur = db.query("Employee", col, null, null, null, null, null);
ArrayList<Map<String, Object>> coll = new ArrayList<Map<String, Object>>();
Map<String, Object> item; item = new HashMap<String, Object>();
item.put("c1", "-------- Data -------");
coll.add(item);
cur.moveToFirst();
while(!cur.isAfterLast()) {
item = new HashMap<String, Object>();
item.put("c1", cur.getString(0) + ", " + cur.getString(1));
coll.add(item); cur.moveToNext(); }
this.setListAdapter(new SimpleAdapter(this, coll,
android.R.layout.simple_list_item_1, new String[] { "c1" },
new int[] {android.R.id.text1})); }
@Override protected void onListItemClick(ListView l, View v, int position, long id)
{ finish(); }
}
Step-5:
Activity TransActivity
9 5
235
236 Android 36
Step-6
9.5.3
3. TransActivity
1.
switch (item.getItemId()) {
// .
case COMMIT_ID: {
if(uc_state != "INPUT") { tx.setText("Input Data First!!"); return false; }
GoTo_Commit_State();
return true; }
//..
}
INPUT
<COMMIT> COMMIT
10 10
237
10
10
10.1
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
10.10
#26 BroadcastReceiver
#27 Service
#28 ProgressDialog
#29 KeyEvent
#30 UML Statechart
#31 MapView
#32 WebView
#33
#34 COR
#35 State
238 Android 36
10.1.1
1.
2. <repeat_alarm> BroadcastReceiver
Alarm
Mananger Intent Title "from AlarmReceiver"
10 10
239
3.
10.1.2
Step-1:
Step-2:
Android kx01
IntentReceiver AlarmReceiver
package com.misoo.kx01;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ac01 app = ac01.getApp();
app.btEvent("from AlarmReceiver");
}}
Step-3:
Activity ac01
240 Android 36
super.onCreate(icicle);
appRef = this;
setContentView(R.layout.repeat_alarm);
btn = (Button)findViewById(R.id.repeat_al);
btn.setBackgroundResource(R.drawable.bk);
btn.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.stop_al);
btn2.setBackgroundResource(R.drawable.bk);
btn2.setOnClickListener(this);
setTitle("waiting ... Alarm=15");
Intent intent = new Intent(ac01.this, AlarmReceiver.class);
PendingIntent p_intent = PendingIntent.getBroadcast(ac01.this, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 15);
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), p_intent);
}
public static ac01 getApp() { return appRef; }
public void btEvent( String data ) {
k = !k;
if(k)
setTitle(data);
else
setTitle("wait...");
}
public void onClick(View arg0) {
if(arg0 == btn) {
setTitle("Repeating...");
Intent intent = new Intent(ac01.this, AlarmReceiver.class);
PendingIntent p_intent = PendingIntent.getBroadcast(ac01.this, 0, intent, 0);
// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
firstTime += 800;
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(
ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime, 800, p_intent);
}
10 10
241
if(arg0 == btn2){
Intent intent = new Intent(ac01.this, AlarmReceiver.class);
PendingIntent p_intent = PendingIntent.getBroadcast(ac01.this, 0, intent, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.cancel(p_intent);
finish();
}
}}
Step-4:
AndroidManifest.xml
Step-5:
10.1.3
1.
242 Android 36
2.
ac01
onCreate()
AlarmManager Intent
AndroidManifest.xml
<receiver android:name=".AlarmReceiver">
//..
</receiver>
10 10
243
10.2.1
1.
2.
<call_service> 15
244 Android 36
4.
<Exit>
10.2.2
Step-1:
Step-2:
Android kx02
BroadcastReceiver AlarmReceiver
Step-3:
Service NotifyService
10 10
245
Step-4:
Activity ac01
246 Android 36
}}}
Step-5:
AndroidManifest.xml
Step-6:
10.2.3
10 10
247
10.3.1
1.
2.
3.
248 Android 36
4.
Menu <Exit>
10.3.2
Step-1:
Step-2:
Android kx03
Activity ac01
10 10
249
btn2.setOnClickListener(this);
layout.addView(btn2, new LinearLayout.LayoutParams(WC, WC));
setContentView(layout);
}
public void onClick(View v){
if (v == btn){
progressDialog=ProgressDialog.show(this,
"please wait","Loading YourMap",true);
new Thread(){
public void run(){
try{
sleep(8000);
Intent intent = new Intent();
intent.setClass(ac01.this, DispActivity.class);
startActivity(intent);
}
catch(Exception e)
{ e.printStackTrace(); }
progressDialog.dismiss();
}
}.start();
setTitle("this main thread");
}
if(v.equals(btn2)) this.finish();
}}
Step-3:
Activity DispActivity
package com.misoo.kx03;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
public class DispActivity extends Activity implements OnClickListener {
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
public static final int EXIT_ID = Menu.FIRST + 2;
private TextView tx;
250 Android 36
Step-4:
10.3.3
1.
2.
new Thread(){
public void run(){
try{
sleep(8000);
Intent intent = new Intent();
10 10
251
intent.setClass(ac01.this, DispActivity.class);
startActivity(intent);
}
catch(Exception e)
{ e.printStackTrace(); }
progressDialog.dismiss();
}
}.start();
setTitle("this main thread");
}
ac01 "this main thread" 3
1ProgressDialog
2Sleep(8000)
ac01
28 8 DispActivity
progressDialog.dismiss();
ProgressDialog 1 2
10.4.1
1.
252 Android 36
2.
3.
<Z> sub-tree
10 10
253
4.
5.
<Z> sub-tree
<Exit>
10.4.2
Step-1:
Step-2:
Android kx04
Activity ac01
254 Android 36
Step-3:
View GraphicView
// ---- GraphicView.java
package com.misoo.kx04;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
----
10 10
255
}
}
256 Android 36
this.drawNode_recursive(next_node, canvas); }
}}
private void drawNode(int x, int y, ObjectMap curr_node, String plus, Canvas canvas) {
String tx = curr_node.get("name").toString();
paint.setAntiAlias(true);
if(x != 2) {
paint.setColor(Color.DKGRAY);
canvas.drawLine(x-5,y+5, x, y+5, paint);
pa = (ObjectMap)curr_node.get("parent");
Integer last_pos = (Integer)pa.get("last_pos");
int last_y = last_pos;
canvas.drawLine(x-5,last_y+4, x-5, y+5, paint);
}
paint.setColor(Color.BLACK);
paint.setStrokeWidth(1);
paint.setColor(Color.LTGRAY); canvas.drawRect(x, y, x+10, y+10, paint);
paint.setColor(Color.BLUE);
canvas.drawLine(x+2, y+5, x+8, y+5, paint);
if(plus == "+") canvas.drawLine(x+5, y+2, x+5, y+8, paint);
if(plus == "@") canvas.drawRect(x+2, y+2, x+8, y+8, paint);
String level = curr_node.get("level").toString();
int k = Integer.valueOf(level);
switch(k){
case 0: paint.setColor(Color.BLACK); break;
case 1: paint.setColor(Color.BLUE); break;
case 2: paint.setColor(Color.BLACK); break;
case 3: paint.setColor(Color.BLUE); break;
}
if( target_index == acc_index)
paint.setColor(Color.RED);
canvas.drawText(tx, x+13, y+8, paint);
acc_index++;
}
public void build_model() {
root = getNewNode(null, "goal");
lv_0_coll = root.get_sons();
curr_item = getNewNode(root, "money");
lv_0_coll.add(curr_item);
lv_1_coll = curr_item.get_sons();
lv_1_coll.add(getNewNode(curr_item, "salary"));
lv_1_coll.add(getNewNode(curr_item, "bonus"));
lv_1_coll.add(getNewNode(curr_item, "extra_bonus"));
curr_item.put_string("zip", "@");
curr_item = getNewNode(root, "thing");
lv_0_coll.add(curr_item);
lv_1_coll = curr_item.get_sons();
next_node = getNewNode(curr_item, "few");
10 10
257
lv_1_coll.add(next_node);
lv_2_coll = next_node.get_sons();
lv_2_coll.add(getNewNode(next_node, "little"));
lv_2_coll.add(getNewNode(next_node, "fewer"));
next_node.put("zip", "+");
lv_1_coll.add(getNewNode(curr_item, "middle"));
lv_1_coll.add(getNewNode(curr_item, "busy"));
curr_item.put_string("zip", "@");
curr_item =getNewNode(root, "long");
lv_0_coll.add(curr_item);
lv_1_coll = curr_item.get_sons();
lv_1_coll.add(getNewNode(curr_item, "short"));
lv_1_coll.add(getNewNode(curr_item, "middle"));
lv_1_coll.add(getNewNode(curr_item, "long"));
curr_item.put_string("zip", "@");
root.put_string("zip", "@");
}
private ObjectMap getNewNode(ObjectMap pa, String name) {
String lv = null;
String level = null;
if(pa == null) level = "0";
else { lv = pa.get("level").toString();
level = String.valueOf(Integer.valueOf(lv)+1);
}
ObjectMap m_obj = new ObjectMap();
m_obj.put_object("last_pos", new Integer(18));
m_obj.put_string("level", level); m_obj.put_string("name", name);
m_obj.put_object("parent", pa); m_obj.put_object("sons", new MapList());
m_obj.put_string("zip", "+");
return m_obj;
}
public void MoveUp() { target_index--; this.invalidate(); }
public void MoveDown() { target_index++; this.invalidate(); }
public void zip_toggle() {
ObjectMap curr_node = show_list.get(target_index);
String zz = curr_node.get("zip").toString();
if(zz == "@"){
curr_node.put_string("zip", "+");
this.invalidate();
}
if(zz == "+") {
curr_node.put_string("zip", "@");
this.invalidate();
}
258 Android 36
}}
Step-4:
10.4.3
1.
MVC ac01 Controller User
money
thing
few
3.
middle
long
busy
GraphicView onDraw()
protected void onDraw(Canvas canvas) {
// ..
this.drawNode_recursive(root, canvas);
10 10
259
}
(Recursive) Model( )
4. User KeyEvent onKeyDown()
public boolean onKeyDown(int keyCode, KeyEvent msg) {
if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) gv.MoveDown();
// .
}
5.
260 Android 36
(State Machine)
Android
Android
Activity Activity( ) onPause()
onStop()
Andriod
10.5.1
1.
2.
<Calculator>
10 10
261
3.
< 1 ><
><
><
>
1
+) 0
--------------[0 1]
4.
5.
<C>(Reset)
<Exit>
10.5.2
Step-1:
Android kx05
Step-2:
HalfAdder( )
262 Android 36
Calculator
10 10
263
adder.run();
String s_carry = String.valueOf(adder.carry);
String s_sum = String.valueOf(adder.sum);
ax.show("["+s_carry + s_sum +"]");
}}
Step-4:
Activity ac01
264 Android 36
param.topMargin = 25;
r_layout.addView(btn_1, param);
btn_2 = new Button(this);
btn_2.setId(3);
btn_2.setText("Exit");
btn_2.setOnClickListener(this);
param = new RelativeLayout.LayoutParams(WC, WC);
param.addRule(RelativeLayout.RIGHT_OF, 2);
param.addRule(RelativeLayout.ALIGN_TOP, 2);
param.leftMargin = 5;
r_layout.addView(btn_2, param);
}
public void onClick(View arg0) {
if(arg0 == btn_1) {
Intent cal_intent = new Intent(ac01.this, CalActivity.class);
startActivity(cal_intent); }
else
finish();
}}
Step-5:
Activity CalActivity
10 10
265
266 Android 36
btn[3].setId(5);
btn[3].setText("+");
btn[3].setOnClickListener(this);
param = new RelativeLayout.LayoutParams(WC, WC);
param.addRule(RelativeLayout.BELOW, 2);
param.addRule(RelativeLayout.ALIGN_LEFT, 2);
param.topMargin = 5;
r_layout.addView(btn[3], param);
btn[4]= new Button(this); btn[4].setId(6);
btn[4].setText("=");
btn[4].setOnClickListener(this);
param = new RelativeLayout.LayoutParams(WC, WC);
param.addRule(RelativeLayout.RIGHT_OF, 5);
param.addRule(RelativeLayout.ALIGN_TOP, 5);
param.leftMargin = 5;
r_layout.addView(btn[4], param);
btn[5] = new Button(this);
btn[5].setId(7);
btn[5].setText("Exit");
btn[5].setOnClickListener(this);
param = new RelativeLayout.LayoutParams(WC, WC);
param.addRule(RelativeLayout.RIGHT_OF, 6);
param.addRule(RelativeLayout.ALIGN_TOP, 6);
param.leftMargin = 5;
r_layout.addView(btn[5], param);
}
public void onClick(View arg0) {
if(arg0 == btn[0])
{ calc.EvDigitPress(1); curr = 0; }
else if(arg0== btn[1])
{calc.EvDigitPress(0); curr = 1;}
else if(arg0== btn[2])
{ calc.EvCPress(); curr = 2; }
else if(arg0== btn[3])
{ calc.EvPlusPress(); curr = 3; }
else if(arg0== btn[4])
{ calc.EvAssignPress(); curr = 4; }
else if(arg0== btn[5])
{ curr = -1; finish();
setting_color();
}
public void setting_color() {
for(int i = 0; i<6; i++ ) {
if(i == curr) btn[i].setTextColor(Color.RED);
else
btn[i].setTextColor(Color.BLACK);
}}
@Override public boolean onKeyDown(int keyCode, KeyEvent msg) {
if(keyCode == KeyEvent.KEYCODE_1) { calc.EvDigitPress(1); curr = 0; }
if(keyCode == KeyEvent.KEYCODE_0) { calc.EvDigitPress(0); curr = 1;}
if(keyCode == KeyEvent.KEYCODE_C) { calc.EvCPress(); curr = 2; }
if(keyCode == KeyEvent.KEYCODE_P) { calc.EvPlusPress(); curr = 3; }
10 10
267
if(keyCode == KeyEvent.KEYCODE_EQUALS)
{ calc.EvAssignPress(); curr = 4; }
if(keyCode == KeyEvent.KEYCODE_E) { curr = -1;
setting_color();
return true;
finish(); }
}
@Override public void onSaveInstanceState(Bundle icicle) {
super.onCreate(icicle);
icicle.putInt("digit_1", calc.digit_1); icicle.putInt("digit_2", calc.digit_2);
icicle.putInt("state", calc.state);
icicle.putInt("curr", curr);
icicle.putString("tv", tv.getText().toString());
}}
Step-6:
10.5.3
1.
(Bit)
a b (Port)
sum carry
2.
3.
HalfAdder
Calculator
Calculator UML
268 Android 36
10 10
269
calc.EvDigitPress(1);
EvDigitPresscalcCalculatorEvDigitPress()
void EvDigitPress(int
dg){ this.d = dg;
switch(state){
case 0: go_state_first(); break;
// .
}
calc Ready (0 ) calc d
EvDigitPress()
calc
d
SecondDigitInputed <=>
<=> CalActivity EvAssignPress calc calc
SecondDigitInputed Calculating
Calculating
private void go_state_cal(){
state = 4; adder.a = digit_1; adder.b = digit_2;
adder.run();
String s_carry = String.valueOf(adder.carry);
String s_sum = String.valueOf(adder.sum);
ax.show("["+s_carry + s_sum +"]");
}
digit_1 digit_2
carry
270 Android 36
10.6.1
1.
2.
3.
4.
<2> ()
< >< > ()
10 10
271
5.
<E>
10.6.2
Step-1:
Step-2:
Android kx06
MapActivity OverlayMapActivity
272 Android 36
Step-3:
OverlayMapActivity ac01
// ---- ac01.java
package com.misoo.kx06;
import android.os.Bundle;
-----
10 10
273
import android.view.KeyEvent;
import android.view.View;
public class ac01 extends OverlayMapActivity {
@Override protected boolean isRouteDisplayed() { return false; }
@Override protected void onCreate(Bundle pBundle) {
super.onCreate(pBundle); }
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_1)
tx.setText("(1),.");
if (keyCode == KeyEvent.KEYCODE_2)
tx.setText("(2),.");
if (keyCode == KeyEvent.KEYCODE_3)
tx.setText("(3).");
if (keyCode == KeyEvent.KEYCODE_E) finish();
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
mapView.getController().setZoom( mapView.getZoomLevel()+1); }
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
mapView.getController().setZoom(mapView.getZoomLevel() - 1); }
return false; }
public void onClick(View v) {}
}
Step-4:
10.6.3
1.
2.
274 Android 36
3.
Resources r = getResources();
myOverlay overlays = new myOverlay(r.getDrawable(R.drawable.icon));
mapView.getOverlays().add(overlays);
myOverlay overlays 3
4. overlays myOverlay
draw() draw()
Point point = projection.toPixels(item.getPoint(), null);
overlays
canvas.drawCircle(point.x, point.y, 10, paint);
10.6.4
1.
mapView.setSatellite(true);
2.
mapView.setTraffic(true);
3. AndroidManifest.xml
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon">
<!-- Libraries -->
<uses-library android:name="com.google.android.maps" />
10 10
275
10.7
#32: WebView
(Browser)
Android WebView
.ZIP /res/raw/
m1.ZIP show_zip() m1.ZIP
10.7.1
1.
ac01 Menu
<Download> <ShowZip> 2. <Download> WebView
( http://www.misoo1.com)
276 Android 36
2. ( .ZIP
)
3. .ZIP /res/raw/
m1.ZIP
4. ac01 Menu <ShowZip>
show_zip() m1.ZIP ( <resources>)
5.
Menu <Exit>
10.7.2
Step-1:
Step-2:
Android kx07
Activity ac01
10 10
277
Step-3:
Activity download
278 Android 36
Step-4:
10.7.3
1.
download
webView = new WebView(this);
setContentView(webView);
webView.getSettings().setTextSize(WebSettings.TextSize.SMALLEST);
webView.loadUrl("http://www.misoo1.com");
WebView loadUrl()
WebView
2. ac01 show_zip()
InputStream ins = getResources().openRawResource(R.raw.m1);
ZipInputStream z_ins = new ZipInputStream(ins);
ZipInputStream /res/raw/m1.zip
.ZIP z_ins.getNextEntry(); .ZIP
read() z_ins.read(buffer, 0, 100);
3. WebView
.ZIP .ZIP
( MP3 ) VideoView
4. AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
10 10
279
10.8
#33
User
ID ListView
Android
10.8.1
1.
EditText "love"
2. <CENTER> ListView
3. < > ListView
280 Android 36
4.
5.
6.
<Exit>
<Q>
10.8.2
Step-1:
Android kx08
Step-2:
Activity ac01
Step-3:
Instrumentation MyInstrumentation
// ---- MyInstrumentation.java
package com.misoo.kx08;
import android.app.Instrumentation;
import android.content.Intent;
import android.view.KeyEvent;
import android.os.Bundle;
----
10 10
281
Step-4:
Activity InputAct
package com.misoo.kx08;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
282 Android 36
import android.widget.EditText;
import android.widget.TextView;
public class InputAct extends Activity implements OnKeyListener {
private TextView tv;
private EditText et;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.input);
et = (EditText)findViewById(R.id.et);
tv = (TextView)findViewById(R.id.tv);
et.setOnKeyListener(this); }
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER){
tv.setText(et.getText());
Intent intent = new Intent(InputAct.this, SelectAct.class);
startActivityForResult(intent, 152); }
if(event.getKeyCode()==KeyEvent.KEYCODE_Q) { finish(); }
return false;
}}
Step-5:
Activity SelectAct
package com.misoo.kx08;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class SelectAct extends Activity implements OnItemClickListener {
private String[] data = {"Item-1", "Item-2", "Item-3", "Exit"};
private TextView tv; ListView lv;
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.list);
tv = (TextView)findViewById(R.id.tv);
lv = (ListView)findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, data);
lv.setAdapter(adapter); lv.setOnItemClickListener(this);
lv.requestFocus();
10 10
283
}
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
switch(arg2){
case 0: tv.setText(data[arg2]);
break;
case 1: tv.setText(data[arg2]);
break;
case 2: tv.setText(data[arg2]);
break;
case 3: finish(); break;
}}}
Step-6:
/res/layout/input.xml
Step-7:
AndroidManifest.xml
284 Android 36
Step-8:
10.8.3
1.
ac01 onCreate()
Intent intent = new Intent(ac01.this, InputAct.class);
startSubActivity(intent, INIT_TEXT_REQUEST);
2.
ActivityInputAct EditText
Thread
10 10
285
10.9
#34 COR
(Pattern)
1995 Erich Gamma
Design Patterns: Elements of Reusable Object-Oriented Software
COR
Android
10.9.1
1.
<MENU> 4 Menu
2.
<View> View
3.
286 Android 36
4.
5.
10.9.2
COR
COR
(Chain) (
getPower) 1 1
Chain Of Responsibility
10 10
287
head
getPower
successor
Cat
successor
Panasonic
successor
Panasonic
Activity_1
Activity_2
ac01
pass()
head
Activity_3
successor
Task1
successor
Task2
successor
Task3
288 Android 36
10.9.3
Step-1:
Android kx09
Step-2:
Activity ac01
10 10
289
Step-3:
SuperTask
Factory
290 Android 36
// ---- Facrory.java
package com.misoo.kx09;
import android.content.Context;
----
Step-5:
SuperTask Task1
Step-6:
SuperTask Task2
10 10
291
Step-7:
SuperTask Task3
Step-8:
Activity Activity_1
292 Android 36
super.onCreate(icicle);
setContentView(R.layout.act);
Button btn = (Button)findViewById(R.id.btn);
btn.setBackgroundResource(R.drawable.x_jude);
btn.setText("Exit from action.VIEW");
btn.setOnClickListener(this);
}
public void onClick(View arg0) { finish();
}
}
Step-9:
Activity Activity_2
Step-10:
Activity Activity_3
10 10
293
Step-11:
10.9.4
1.
btn.setText("Exit from
Handler
Client
successor
HandleRequest()
ConcreteHandle1
ConcreteHandle2
HandleRequest()
HandleRequest()
294 Android 36
ac01
SuperTask
successor
pass()
Task1
Task2
Task3
pass()
pass()
pass()
2. Task1pass()
public boolean pass(String job) {
if(job == "VIEW"){
this.perform(); return true; }
else {
if(successor == null) return false;
else return successor.pass(job);
}
job "VIEW" (Responsibity)
perform() Activity_1job
"VIEW" job (Successor)
successor.pass(job) (successor == null)
false job
3. Task1perfrom()
private void perform(){
// Intent intent = new Intent(Intent.VIEW_ACTION, null);
Intent intent = new Intent(ctx, Activity_1.class);
ctx.startActivity(intent);
}
Intent Activity Activity_3
10 10
295
10.9.5
10.9.5.1
(Pattern)
(Context)
(Solution)
(Indirect Solution)
(Solution)
(Christopher Alexander)
(Pattern)(Context)
(Problem)
(Solution)
(Design Pattern) 1991
(Reinvent the wheel)
296 Android 36
10.9.5.2
1964 Christopher Alexander
(Pattern)
1970
Alexander
Pattern
1980 Alexander
1987 Ward Cunningham Kent Beck
1995
Erich
Gamma
Ralph Johnson
Design
Patterns:Elements of Reusable Object-Oriented Software
Gamma
Design Pattern
10.10
#35 State
(Distributed)
( Factory )( TaskN )
(Centric)
(Embedded)
(State Machine) Android Activity
Gamma Design Patterns State
10 10
297
Context
state
State
Handle()
Request()
state->Handle()
ConcreteStateA
ConcreteStateB
Handle()
Handle()
State
4 Preparing
TakingOff Flying
Landing
4 State
Contoller
state
State
handle()
Request()
state.handle()
State_V
State_E
handle()
handle()
ViewAct
EditAct
298 Android 36
Controller
10.10.1
1.
<MENU> Menu
2. <Go> View (
Activity
ViewAct)
3. <Next> Edit (
EditAct)
10 10
299
10.10.2
Step-1:
Android kx05
Step-2:
Activity ac01
//---------- ac01.java
package com.misoo.kx10;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
--------------------------------
300 Android 36
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, GO_ID, 0, "Go"); menu.add(0, EXIT_ID, 1, "Exit");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case GO_ID: ctrl.Request(); break;
case EXIT_ID: finish();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
String data, Bundle extras) {
if(data.contains("Next")) ctrl.Request();
else finish();
}}
Step-3:
Controller
//---------- Controller.java
package com.misoo.kx10;
import android.content.Intent;
--------------------------------
10 10
301
}
private class E_State extends SuperState {
public void handle(){
// Intent intent = new Intent(Intent.EDIT_ACTION, null);
Intent intent = new Intent(mCtx, EditAct.class);
mCtx.startActivityForResult(intent, 100);
}}
private class V_State extends SuperState {
public void handle(){
// Intent intent = new Intent(Intent.VIEW_ACTION, null);
Intent intent = new Intent(mCtx, ViewAct.class);
mCtx.startActivityForResult(intent, 101);
}}
private class P_State extends SuperState {
public void handle(){
// Intent intent = new Intent(Intent.PICK_ACTION, null);
Intent intent = new Intent(mCtx, PickAct.class);
mCtx.startActivityForResult(intent, 102);
}}}
Step-4:
Activity ViewAct
package com.misoo.kx10_dd;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ViewAct extends Activity implements OnClickListener {
Button btn, btn2;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.act);
btn = (Button)findViewById(R.id.btn);
btn.setBackgroundResource(R.drawable.x_jude);
btn.setText("Exit from action.View");
btn.setOnClickListener(this);
302 Android 36
btn2 = (Button)findViewById(R.id.btn_next);
btn2.setOnClickListener(this);
}
public void onClick(View arg0) {
Bundle bundle = new Bundle();
if(arg0 == btn)
bundle.putString("DataKey", "Exit");
else
bundle.putString("DataKey", "Next");
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}}
Step-5:
Activity EditAct
10 10
303
bundle.putString("DataKey", "Next");
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}}
Step-6:
Activity PickAct
304 Android 36
Step-7:
/res/layout/act.xml
Step-8:
10.10.3
1. ac01 onCreate()
public void onCreate(Bundle icicle) {
//..
ctrl = new Controller(this);
// ..
}
Controller 'I' (Iinitial)
2.
if(icicle != null)
ctrl.set_state(icicle.getChar("state"));
icicle != null onSaveInstanceState ()
icicle
10 10
305
ac01
(Focus)
Android
onSaveInstanceState ()( )
public void onSaveInstanceState (Bundle icicle)
{ super. onSaveInstanceState (icicle);
icicle.putInt("state", ctrl.get_state());
}
icicle
3. <Go> onOptionsItemSelected()
ctrl.Request();
ctrl Controller Request()
4. Request()
'V'
5. 'V'
goto_V()
306 Android 36
Google Android
Android UI
1
2 Android
3
Android
Android C
4 Android C
5
Android C
6 Faade JNI
7
C
C
8 Linter Android
9
Linter Android
Android
10 Android
11 C 36 307
()
308 Android 36
11
C 36
11.1 #36 C
11.2 Android C
11 C 36 309
11.1 #36
C
1 ~ 35 Android
Android
Android
Cheese
C
Google Android
10.5
<<
>>
Android
5 .java ( Android )
310 Android 36
Java
<< >> NativeHalfAdder HalfAdder
C Android
ac01
Calculator
CalActivity
HalfAdder
NativeHalfAdder
Android
NativeHalfAdder
HalfAdder
( ac01CalActivity Calculator)
11.1.1
1.
11 C 36 311
2.
<Calculator>
3.
4.
5.
<C>(Reset)
<Exit>
11.1.2
Step-1:
Step-2:
Android kx11
Activity ac01
312 Android 36
btn_2.setId(3);
btn_2.setOnClickListener(this);
11 C 36 313
Step-3:
Activity CalActivity
314 Android 36
11 C 36 315
Step-4:
Calculator
//---------- Calculator.java
package com.misoo.kx11;
public class Calculator {
public int digit_1, digit_2, state, d;
--------------------------------
316 Android 36
Step-5:
NativeHalfAdder( )
//---------- NativeHalfAdder.java
package com.misoo.kx11;
--------------------------------
11 C 36 317
Step-6:
HalfAdder( )
//---------- HalfAdder.java
package com.misoo.kx11;
--------------------------------
Step-7:
11.1.3
1.
10.5 10.5.3
11.1.4
NativeHalfAdder (Class
(Function Implementation)
Definition)
Java NativeHalfAdder.java
NativeHalfAdder.class
javah
com_misoo_kx11_NativeHalfAdder.h C
(header) Java C
Linux
./jdk1.6.0_05/bin/javah -classpath ./workspace/AndroidJni/bin
com.misoo.kx11.NativeHalfAdder
318 Android 36
com_misoo_kx11_ NativeHalfAdder.h
/***com_misoo_kx11_ NativeHalfAdder.h */
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_misoo_kx11_NativeHalfAdder */
#ifndef _Included_com_misoo_kx11_NativeHalfAdder
#define _Included_com_misoo_kx11_NativeHalfAdder
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:
com_misoo_kx11_NativeHalfAdder
* Method:
calculate
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
Java_com_misoo_kx11_NativeHalfAdder_calculate
(JNIEnv *, jclass, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
.h javah
NativeHalfAdder.java
NativeHalfAdder.class javah
C com_misoo_kx11
_NativeHalfAdder.c C
HalfAdder C HalfAdder.h
HalfAdder.c
Cross Compiler
com_misoo_kx11_NativeHalfAdder.c
HalfAdder.c .o
11 C 36 319
Linux
arm-2007q3/bin/arm-none-linux-gnueabi-gcc -I./jdk1.6.0_05/include
-I./jdk1.6.0_05
/include/linux -fpic -c com_misoo_kx11_NativeHalfAdder.c
Linux
arm-2007q3/bin/arm-none-linux-gnueabi-gcc -I./jdk1.6.0_05/include
-I./jdk1.6.0_05
/include/linux -fpic -c HalfAdder.c
11.1.5
1.
/* NativeHalfAdder.java
package com.misoo.kx11;
import android.util.Log;
*/
320 Android 36
/* com_misoo_kx11_NativeHalfAdder.c
*/
#include "HalfAdder.h"
#include "com_misoo_kx11_NativeHalfAdder.h"
extern void* HalfAdderNew();
hadder
(Pointer)
11 C 36 321
lw_oopc.h C (Macro)
/* lw_oopc.h */
/* MISOO C */
#ifndef LOOPC_H
#define LOOPC_H
#include <malloc.h>
#define CLASS(type)\
typedef struct type type; \
struct type
#define CTOR(type) \
void* type##New() \
{\
struct type *t; \
t = (struct type *)malloc(sizeof(struct type));
#define CTOR2(type, type2) \
void* type2##New() \
{\
struct type *t; \
t = (struct type *)malloc(sizeof(struct type));
#define END_CTOR return (void*)t; };
#define FUNCTION_SETTING(f1, f2) t->f1 = f2;
#define IMPLEMENTS(type) struct type type
#define INTERFACE(type) struct type
#endif
/*
end
*/
HalfAdder.h HalfAdder
/* HalfAdder.h
*/
#ifndef HA_H
#define HA_H
#include "lw_oopc.h"
CLASS(HalfAdder){
322 Android 36
HalfAdder.c
HalfAdde r
NativeHalfAdder.c HalfAdder
/*
HalfAdder.c
*/
#include "HalfAdder.h"
static void set_ab(void *t, int a, int b) {
HalfAdder* cthis = (HalfAdder*)t;
cthis-> a = a;
cthis-> b = b;
}
static void calc(void* t) {
HalfAdder* cthis = (HalfAdder*)t;
cthis->carry = cthis->a & cthis->b;
cthis->sum = cthis->a ^ cthis->b; }
static int get_carry(void* t)
{ HalfAdder* cthis = (HalfAdder*)t;
return cthis->carry; }
static int get_sum(void* t)
{ HalfAdder* cthis = (HalfAdder*)t;
return cthis->sum; }
CTOR(HalfAdder)
FUNCTION_SETTING(set_digits, set_ab)
FUNCTION_SETTING(run, calc)
FUNCTION_SETTING(get_carry, get_carry)
FUNCTION_SETTING(get_sum, get_sum)
END_CTOR
11.1.6
C lw_oopc.h (macro)
ANSI-C Keil C51
11 C 36 323
lw_oopc.h
(Full copyright of lw_oopc.h content lies with the Author, Huantang Kao(
). No part of it may be reproduced, in any form or by any means,
without permission in writing by the Author.)
1.
2.
11.2
Android C
11.2.1
IT
IT
Android Android
Android
Android
Android Native C
Java
Android C
36
Android Android 50
324 Android 36
C
C
C C
Android Native C
( )
11.2.2
IT
20 (Alvin Toffler)
(Information)
(The third wave)
2008 IT
IT Mainframe 25 PC
IC Internet
20 IT
11 C 36 325
Internet JavaWeb2.0WiMax
IT PC
+ IT
?
25 IT PC
IBM PC IT
2008 IT PC
Google Android () IT
IBM PC (25 )
Google Android (2008)
(25 )
Android (2008)
(25 ----
2008 !)
PC (25 )
(2008)
25 PC 2008
326 Android 36
(+ )
----
---- IT
----
IT
!!
11 C 36 327
1.
Use Case ( )
2.
Use Case ( )
3.
4.
5.
6.
7.
8.
9.
10.
UML ( )
UML + C ( )
Keil-C ( )
Java ( )
VB.net DIY( )
( )
C++ ( )
C ( )
328 Android 36
A-1
A-2
A-3
A-4
A-5
A-6
B-1
Omia
B-2 Google
B-3 IT :()
B-4
B-5 Android Eclipse
329
A-1
Windows
Android SDK 1.0 Eclipse
Step-0 http://code.google.com/android/download_list.html 4
Step-2 android-sdk-windows-1.0_r1
Step-3 eclipse-SDK-3.4-win32
330 Android 36
4.3
<OK>
4.4
<Install>
331
<OK> Eclipse
Step-6Android 1.0
A-2
Windows
Android SDK 1.0 Eclipse
Eclipse
http://code.google.com/android/download_list.html ADT-0.8.0 (
) Step-4
Step-4a():
4a.1 Eclipse
4a.2 <Available Software><Add Site>
332 Android 36
4.5
<Install>
333
A-3
Android
A-3-1
<Finish> , Android
A-3-2
Java
Android
Android
A-3-2-1
A-3-2-2
334 Android 36
A-3-2-1
A-4
Android
335
Linux/Ubuntu
Android SDK 1.0 Eclipse
A-5
JDK 6
Step-1.
Step-2.
/usr/lib/jvm/java-6-sun/
Android-SDK 1.0
http://code.google.com/android/download_list.html
Android-sdk-linux_x86-1.0_r1.zip
/home/tom/
Step-3.
Eclipse
336 Android 36
/home/tom/
Step-4.
Step-5.
A-6
GNUTOOLCHAINS
/home/tom/arm-2007q3/
337
B-1
Omia
2008/10/2 Omia
Google Android
20 (MP4 )
www.misoo1.com tom-kao.blogspot.com
338 Android 36
339
340 Android 36
341
Android Linter
Linter
Android
Abdroid
342 Android 36
343
344 Android 36
345
( )
( ) ( )
e-mail misoo.tw@gmail.com
346 Android 36
B-2
Google
Google
( ) MISOO
Google
Field
CRM
DB
DB
B2-1 (Preferences)
347
( )
!
B2-2 MISOO
348 Android 36
Android ( a2-2)
3G (Link)
POS
Google Map
a2-1
Google Google
Google
Google
Google
Google
e-mail: misoo.tw@gmail.com
349
B-3 IT : ( )
(2008 )
B-3-1
20 (Alvin Toffler)
(information) (the
third wave)
2008 IT
IT Mainframe 25 PC
IC Internet
Intel/Dell IC
B-3-2
Google Android
(container)
( ) ( )
( )
350 Android 36
( )
(
)
1973
9
351
IC IC
Windows
IC
Windows
( ) Google
Android
Android
Apple II
PC
(Factor)
a3-1
()
B3-1
PC
PC 20 3
352 Android 36
IT(India + Taiwan)
Android
DOS/Windows
SQLite( Linter) DBMS Oracle DB
PC
(McKinsey) 2006
a3-2
B3-2 <
software
to manufactured products >
Getting
better
Android
353
B3-3 AUTOSAR
IT PC
IT ()
B-3-3
1
Oracle Oracle
ER-Model SQL ( )
ER SQL
Oracle
Oracle
( )
(
) Oracle
354 Android 36
ER SQL DBMS
Oracle DBMS (Reuse)
(Loop)
2 1
1 2
B-3-4
Android AUTOSAR
IC
Android AUTOSAR
IT
B-3-5
JavaWeb2.0WiMax
355
IT PC +
20 IT
IT
?
B-4
30
20 (OOP: Object-Oriented
Programming)
10 UML + OOP
UML & OOAD(Object-Oriented Analysis & Design)
2008
OOP UML & OOAD
356 Android 36
Use Case
357
B-5
Android
Linter)
Android
Android Windows Linux ARM-CPU
Linux 2.6.23 Android (Application
Framework)
Windows XP Android Linux
1) XP c:\android-sdk-windows-1.0_r1\tools\
2) adb shell # Linux
adb
adb
Android
Android Debug
Bridge c:\android-sdk-windows-1.0_r1\tools\ .exe
.apk
Android *.apk ?
Step-1: Android ( mouse c:\android-sdk-windows-1.0_r1
\tools\ android )
Step-2: *.apk c:\android-sdk-windows-1.0_r1\tools\
Step-3: \tools\ adb install *.apk .apk
Linux \data\app\ .apk
(PS. Andorid .apk )
*.apk ?
c:\android-sdk-windows-1.0_r1\tools\
1) adb shell rm *.apk
358 Android 36
Kill-Server
Eclipse ( * daemon not running.
starting it now * ) Eclipse c:\tools\
shelladb shell
shell Linux Shell
Linux adb shell [command]
adb shell dmesg Linux debug
-------
adb push
adb pull
adb pull /data/data/kk.xml
359
36
MISOO
110 5 510 7F
MISOO 0928-125-033
E-mail misoo.tw@gmail.com
www.misoo1.com
2008 3
2008 10 3
NT$ 450