0% found this document useful (0 votes)
77 views274 pages

آموزش برنامه نویسی اندروید

This document is an introduction to a book on Android programming using the MoSync Framework. It discusses two approaches to Android development: native Android development using Java, and mobile web application development using a cross-platform framework. It explains that the book will cover the basics of native Android development in the first three chapters, and then focus on mobile web development from chapter four onward as this is the author's area of expertise. It also notes that web-based apps cannot access hardware features as directly but are suitable for many application types. The document includes a table of contents that lists chapter topics like getting started with Eclipse, writing code for controls, running and testing apps, and more.

Uploaded by

mobin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views274 pages

آموزش برنامه نویسی اندروید

This document is an introduction to a book on Android programming using the MoSync Framework. It discusses two approaches to Android development: native Android development using Java, and mobile web application development using a cross-platform framework. It explains that the book will cover the basics of native Android development in the first three chapters, and then focus on mobile web development from chapter four onward as this is the author's area of expertise. It also notes that web-based apps cannot access hardware features as directly but are suitable for many application types. The document includes a table of contents that lists chapter topics like getting started with Eclipse, writing code for controls, running and testing apps, and more.

Uploaded by

mobin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

: .

MoSync Framework

Programming for Android OS.


Mobile Web Application
Framework : MoSync

:
9) 1390(



6037 9918 0175 3850

/ .
:
0343446510008

:
:
Native .
.
.


. .
Mobile Web Application

.
. Cross Platform.
iOS windows

phone .


. .

: 9................................
10 .......................................................................................................
11 .......................................................................................
14 .......................................................................................................
15 ............................................................................................
18 .....................................................................................
! 23 ....................................................
30 ............................................................................
34 .........................................................................
35 .........................................................................................................
39 ............................................................................................................

: 43................................
44 .....................................................................................................
65 ...........................................................................................

68 ......................................................................
72 ........................................................................................
75 ...........................................................................................................

: 79......................
80 ..............................................................................
91 .....................................................................................
93 .........................................................................................................
)94 ................................................. (Application Components
)100 ............................................. (Activating Components
102 ....................................................................................
)103 ................................................................... (The Manifest File
104 ......................................................................
106 ..........................................
108 ....................................................
)113 ........................................................................................ (Activities
114 .............................................................................
118 ................................................................................

6
122 ......................................................................................................
123 ..........................................................................
)124 ................................................................... (intent filters
126 .......................................................................................................
128 ..................................................................
130 .............................................................................................
131 .....................................................................
147 ................................................................................
153 .................................................................................
154 .....................................................................................
155 ................................................................................

: 170 ............. XML


)171 ............................................................. (Application Resources
View Layout173 ...........................................................................................
176 ......................................................................................
177 .......................................................................................
)179 .................................................................................................. (Events

: 180 ........................
181 ...................................................................................................
MoSync 188 .........................................................
189 .........................................
196 .....................................................................................
204 ................................................................................

: 206 .....................
207 .......................................................................
)208 .............................................................................(JSON messages
)209 ............................................................ (string stream messages
209 .........................................................................................
210 ............................................................................
213 .................................................................................

: 219 ............. SQLite


220 .....................................................................................
222 .................................................................................................... SQLite
SQLite 222 ....................................................................

8
226 ................................................................................SQLite
233 .............................................................................. SQLite
234 ......................................................................... SQLite
SQLite 235 ...................................................................
237 ........................................................................

: jQuery245 ........ jQuery Mobile


248 .................................

10


1 ) (Smartphone
2 3 " " 4Open Handset Alliance
" "Google . 12 3
2.8 XML C 2.1 .
.
.
. 5
6 7
8

.
1

Open source
Handheld
3
Tablet
2

4 [Link] .

)Kernel(Nucleus
Rich
7
User Friendly
8
End User
6

11


.
.
.
.
.
.



. - 1
.

SQLite
.


.1Bluetooth,2 EDGE,3 3G,4GPS,5GSM,6 Wi-Fi

Component-Based

12

.

7 .

8 9
. OpenGL
.
MP3, AAC , OGG , AMR , MIDI

MPEG4 WAV , BMP , GIF , PNG , JPG .


Adobe Flash GIF
.
html5 Adobe Flash

Open specification for short-range wireless communication


Enhanced Data Rates for Global Evolution-advanced standard for wireless
)communication (next step up from GSM3
Third Generation
4
Global Positioning System
5
Global System for Mobile Communications
6
Wireless Fidelity
7
High Quality
8
Vector
9
Bitmap
2

13

Streaming .

) .
HTML5 (

.
Dalvik
.
1 )2 (
.

iOS ARM
3

ARM, MIPS, Power

Architecture, x86 . 2008


.
Tablet PC .

Touch Screen
Track Ball
3
Advanced Risk Machine
2

14
(Integrated browser):
WebKit .
) 1 (

) (Isolate.

.


C++ ) 2 ( . C++

- . C C++
- :
90 Sun Micro system
)( C++

Life Cycle
Syntax

1
2

15

.
C++ 1 )
2 (
)
( 3 4
.
.
5 )( Byte Code
6 .
.


.
. 1SDK
2.
1

Portable
Intermediate code
3
Security
4
Platform Independent
5
Intermediate code
6
Java Virtual Machine
2

16
) (Software Development Kit
OS X .
.
) (IDE
) (SDK .


.
. ) (JDK Android Eclipse

SDK 3ADT. 4

. 32 64
.
.
) (Eclipse IDE
[Link]
1

Software Development Kit


Emulator
3
Android development Tools
4
Plug-in
2

17


.
SDK )
!(
[Link]


[Link]
.
.
.
C++ )
C++,C# (
.

.

18
1
.
[Link]
.


.
!






RIM .

Open mind

19


.

2012
.
.
.

.
.
: )
(
.
.

2005 .

20


.

.
.


.

.
2006 .
2007
.

21

2007
.
.

. Open Handset Alliance 5
2007 .
34

.
LG 1NTT DoCoMo T-Mobile HTC Nvidia
eBay
. :

.
.

Nippon Telegraph and Telephone(telephone


telephone company dominating the
)telecommunication market in Japan

22
HTC T-Mobile .
Open Handset
Alliance 22 2008 HTC

T-Mobile G1 Dream Era G1 .


2008 . 14
Open Handset Alliance

.
.
NEC
ST-Ericsson NXP ZTE
.

23

Apache

License .

.

!

.
:
Cupcake
1.5
Donut
1.6
clair
2 2.1 clair MR11.

clair Maintenance Release1

24
) FroYo ( Frozen yogurt
. 2.2
Gingerbread .
.

.
2011
3 ) Honey-Comb ( .
CES .

.
1.5 Cupcake
1.5 ). Cupcake

Base (
.
:

25


YouTube Picasa


) (A2DP
).(AVRCP


1.6 Donut

15 2009 1.6 .
2629 :
) (

26


) (Bookmarks ) (History ) (Contacts

VPN x8021 CDMA/EVDO


WVGA

2 2.1 clair

2 2.1 1.6 .
2 26 2009 . SDK 2009
201 ) 2.0.1

3 ( SDK . 2.1 12
2010 . :

Home Screen
Text to Speech
3
Bug
2

27


Multi Touch



HTML5


312
Microsoft Exchange




2.1

2.2 FroYo

28
2.2 20 2010 .
:
2 5 2
)1JIT
.
2
.
(.
V8
Microsoft Exchange




Just In Time
Machine Independent

1
2

29

2.3
2.3 Gingerbread .
.
3.0
.
) ( iOS .

)
.
( .
.
.
). !(

30

.
2.1
.
2010
2.1 clair
1.6 25
1.5 .

5/0 .


. 1
2009 2.1 2 1.6 2.2
.
HTC

31

.
.
XPERIA X10
1.6 .
X10 .
X10
2.1 . 2.2

2.2 .
6 X10 !
.

.
HTC .

.

32
2.2
2.1
Open Handset Alliance
.

.
2010 .

RIM .
1970 .




.
29 2007
2008

33

. .
2010 6/1
6/9
.

. 61
21 .
.
36 .

17 . 70
.
50 .

RIM .
.

34
20 .

.

2010 .

.
.



HTC .




.

35


.
MOTOBLUR
.

. HTC


.
HTC
.

HTC.

36

.


.
70 .
30
.

46 .
25 .

13


.

37


) (
!
HTC
!
50000
iTunes
175000
.

.

.

.

38

.


.
.

.

. Androlib
Androidzoom .

.



) (Goggles .

39


.
.

. .
. Google I/O 2010

.


.
.

.

40

.

.

41

:
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................

42

:
:

44


Eclipse
File New Android Project ).
(1-1

45

).(2-1
. . SDK 1 .
SDK
)
(.
SDK
.

) (. SDK
.
) (Application Name
. ) (Package Name ). ( 3-1
2
. Min SDK Version
SDK API Level

SDK .
)Version(SDK Version
Dot

1
2

46


) (
8
2.2
.
2.2 2.2 .

47

48

49

: 1 2 .
. 3 .






.
Package Explorer

) (4-1
. ) (1-1
.

Package name
Unique
3
Lowercase letter
2

50


activity

.

[Link]

[Link]



SDK

Android Library



.
...

Assets

Res

User Interface

51

res/drawable

XML

res/layout


) String (

res/values

[Link]

52
) (1-1
.
. ) (5-1 1
.

)Directory(Folder

53

[Link] [Link].
).
(

54
;package [Link]
;import [Link]
;import [Link]
{ public class MyFirstProject extends Activity
/** Called when the activity is first created.*/
@Override
{ )public void onCreate(BundlesavedInstanceState
;)[Link](savedInstanceState
;)setContentView([Link]
}

import .
)( onCreate .
).
( .
.
)( onCreate )( main
! Android Life

Cycle


)( Main End .

55

MyFirstProject Activity )(onCreate

1 2 . )( onCreate
Activity
savedInstanceState .
;)super. onCreate(savedInstanceState
;)(savedInstanceState

savedInstanceState
.
.

.
) setContentView([Link]

setContentView([Link].
[Link] .
.
onCreate .

) (parent super class

) (Derivation . Extends .
Override

56
. gen Package Explorer
.
[Link]

( ).
.
.
.
/* AUTO-GENERATED FILE. DO NOT MODIFY.
* This class was automatically generated by the
* aapt tool from the resource data it found. It
*should not be modified by hand.*/
package [Link];
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int btn_Button1=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

57

) Package Explorer (1-5 1 Android 2.2


.
.
: gen/[Link] Android 2.2 Library
.
) asset( 1-5

.

.
res 1-5 2.
res :
: res/drawable-hdpi/ .1
) (Resolution .
Library
Sub Directory

1
2

58
) . (HDPI=high dot per inch LCD
.
) (Dimension
.
: res/drawable-ldpi/ .2 drawable-

hdpi
.
: res/drawable-mdpi/ .3
drawable-hdpi drawable-ldpi
1
.
:

res/drawable-xdpi
.

Medium

59

Text Box : res/layout/ .4

. ... Radio Button Check Box Label Button


. 1(UI)
2 xml
xml
xml UI layout .
. [Link]
: MyFirstProject [Link]
<?xml version="1.0" encoding="utf
"utf-8"?>
<LinearLayout
xmlns:android="[Link]
"[Link]
android:orientation="vertical"
"vertical"
android:layout_width="fill_parent"
"fill_parent"
android:layout_height="fill_parent"
"fill_parent"
>
<TextView
android:layout_width="fill_parent"
"fill_parent"
android:layout_height="wrap_content"
"wrap_content"
android:text="@string/hello"
"@string/hello"
/>
<Button android:text="Finish" android:id="@+id/btn_finish"
android:layout_width="wrap_content"
"wrap_content"
android:layout_height="wrap_content"
"wrap_content"></Button>
</LinearLayout>

1
2

User interface
Graphic Layout

60

xml .

> <LinearLayout .
.

" android:orientation="vertical

) (orientation 1.

" : android:layout_width="fill_parent

" : android:layout_height="fill_parent

Text view Button .

. Text view
fill_parent
LinearLayout . wrap_content
Text view
. ) (6-1 2
)Vertical(Portrait
Graphical Layout

1
2

61

. tab
. [Link]
switch.
) (User Interface Design
.

: Res/values .5 [Link] .
Resources .

62
[Link]
.
>?"<?xml version="1.0" encoding="utf-8
><resources
<string name="hello">Hello World,
>MyFirstProject!</string
><string name="app_name">MyFirstProject</string
></resources

xml string .

). 1 Name(.
Resources
.
String, Integer Array, String Array, Color, Dimension, Drawable,
Item, Style/Theme

)( 2

.
.
Attribute
Modular

1
2

63

( 5-1) Package Explorer


. [Link]
. xml
.
) (
.
. ...
<?xml version="1.0" encoding="utf-8"?>
encoding
<manifest xmlns:android="[Link]
"[Link]
/apk/res/android" package="[Link]"
"[Link]"
android:versionCode="1" android:versionName="1.0">
android:versionName
<uses-sdk android:minSdkVersion="8"
android:minSdkVersion
/>
<application android:icon="@drawable/icon"
"@drawable/icon"
android:label="@string/app_name"
"@string/app_name">
<activity android:name=".MyFirstProject"
".MyFirstProject"
android:label="@string/app_name"
"@string/app_name">
<intent-filter>
<action android:name="[Link]"
"[Link]" />
<categoryandroid:name=
"[Link]" />
</intent-filter>
</activity>
</application>
</manifest>

64
" android:versionCode="1 1

) 2 ( .
" android:versionName="1.0 String
. Ultimate
. Version Name
.
" android:minSdkVersion="8
8

Application Android:icon Android:Lable
.
3 . @drawable res/drawable
Icon
) LDPI MDPI (HDPI . [Link]).
1

Integer
Market
3
Relative
2

65

Resources Value ( Intent .


Action Category
Activity Activity to Fire up

Launcher . Activity
) ( 1.
Activity Intent .
default. Properties .



) (Widget . ) (Button
).

View

Launch

66

(Import).
;import [Link]

)( onCreate ). Bold(
{ )public void onCreate(Bundle savedInstanceState
;)[Link](savedInstanceState
;)setContentView([Link]

;)Button btn_finish=(Button) findViewById([Link].btn_Finish


}


1

C++ . xml
. xml .
2 3 .
;)Button btn_finish=(Button) findViewById([Link].btn_Finish

imperative
Source Code
3
User Interface
2

67

xml .
. 1 btn_finish
findViewById .
[Link].Object_Name
[Link]
id
Object_Name .
) (Object_Name android:id xml
. xml Finish :
"<Button android:text="Finish
""Finish" android:id="@+id/btn_finish
"android:layout_width="wrap_content
""wrap_content
"android:layout_height="wrap_content
>"wrap_content"></Button

2 ""@+id/Object_Name
.

;) Button btn_finish=(Button) findViewById([Link].btn_Finish


Type Cast

identification code
Paradigm

1
2

68


) ( 1
. Window Android SDK And AVD

Manager . 7-1 )
2AVD 3SDK Eclipse (.

New 8-1 .

)Virtual Device(Emulator
Android Virtual Device
3
Software Development kit
2

69

70
. Resolution

. SD card
2.
Create AVD .
Run Run
Control+F11 . Hello World 9-1
.

71

1 .
!
.
) ( .

Boot up

72
) ( 10-2
) .( 11-2


.
) ( USB
F5 .
)

). USB

(. ) (
.
!
Hello World
.
activities, intents, intent :

filters, services, Content Providers .

73

74

75


File Import .
12-2 Existing Projects into

Workspace .

76

11 -1 Browse .
Package Explorer .

77

78
:

:
:
.

.

80

.
. .

:
Application and Widgets
Application Framework
Android Runtime
Libraries
Linux Kernel

81

82
)(Linux Kernel
) (Proven Foundation
. ).
1(.
2
.
3 4 5
.

.
.


Super Computer
Hardware Abstraction
3
Memory Management
4
Process Management
5
Networking
2

83

.
.

1 2 .

...


.
.


4. C C++
.
C C++

Reliability
Performance
3
Voice communication
4
Native Libraries
2

84
. .
)

( .



).(1BSD

.
MP3,MP4,JPG,PNG.



. Browser Engine
.

System C library

Media Libraries
SGL
WebKit Library_SSL2

Open GL .

)3D libraries(OpenGL

3 Bitmap
) Vector(

Free Type

1 2

SQLite
1

Barkley Software Distribution


Secure Socket Layer
3
Render
2

85


Android Runtime.
4 5.
6
.Net Common

language Runtime Java Virtual Machine


.
. Dan Bornstein
.

Powerful
Light Weight
3
RDB=Relational Data Base
4
Dalvik Virtual Machine
5
Core Java Libraries
6
Portability
2

86
1 2
.

RAM CPU
Dalvik VM Java VM
3 Sun open

source .

.

. Java Virtual machine

.
Dalvik Dalvik virtual machine ..
) (

j2ME MIDP Runner
1

Machine Independent Instruction


Byte Code
3
License
2

87

.
) (1
) 2 ( 3 .
)(Application Framework

) (open development platform



.
) (
4 5
.

6 API
7 API= Application Program Interface).

Interpreter
Executable code
3
Machine code
4
background services
5
Notifications
6
Developers
7
the core applications
2

88
(.
1 2 3 .

)
( . 4
. JDK API
. API ) (Package
.

ArrayList .
.
.
JDK>>API>>Package>>Class
Example : import [Link]

The application architecture


Facilitate
3
Reuse
4
Replacement
2

89

Package ( Class library).



:

) : (View System View


lists, grids, :

.text boxes, buttons, embeddable web browser


) : (Content Providers

).
(.
) : (Resource Manager
1
) .(layout files

.

localized strings

90
) : (Notification Manager
.

) : (Activity Manager 1
.

) : (Location Manager
GPS 2 .

)(Application and Widgets


. 3
.


. Email Phone dialer,
1

Life Cycle
Accelerometer
3
End Users
2

91

SMS ,Calendar, Maps,Web Browser, Contacts ,Andrio Market

. .
Android Runtime .
.
) (Application ) (Widget .
. )
Gadgets ( ) (Home Screen
.
.
....

92


.

1
)
( .
.
.
.
) (virtual machine .
)(isolation
.

2
.
)

Linux User ID
Linux Process

1
2

93

!( ) (shuts down
.

)(Principle of least Privilege


.
.

.


. .


) sign 1(.

Certificate

94
1
) (users contacts SMS ) (SD card
.
.
. [Link]

)(Application Components
2 )(building blocks

.
.

.

.

Device

95

.
) (Lifecycle )
(
.
.

.1 ) : (Activities )
( .
.


.
)
( .
.

1 .
Trade off

96
Activity
.

.2 ) : (Services) 1(
.
2.


) (remote processes .
.
.

.
Live Wallpaper.
.
4 . Service

Process
User interface
3
background
4
Animated Picture
2

97

.3 ) :(Content Providers 1
.
.
. SQLite
.
)
( . Content provider

.
.


.

.

Framework
Reading and Writing data

1
2

98

. Notepad
.
Content Provider
API ) (Transaction .

.4 ) : (Broadcast Receivers
1 .
.

.


.
3
.
4
1

System-wide broadcast announcements


Initiate
3
Status bar
4
Gateway
2

99

.
.
Broadcast Receiver

) (Intent object .
.



. .

.
.
.

)
( .

100
.
) (single entry point).
)( main C++ (


.
.
1 ) (intent
. .

)(Activating Components
) (
) (Asynchronous Message Intent .
Intent )
Message

101

(
.

Intent

. 1 2.

)
(
.

.

)

.
. " "battery is low(.

Explicit
Implicit

1
2

102
.
Content Resolver . Content

Resolver .

.

.1 )( startActivity .

)( startActivityForResult .
.2 )( startService )(bindService
.

103

.3 1 )(sendBroadcast

)(sendOrderedBroadcast

)( sendStickyBroadcast

.4 )( query Content Resolver


) (query .

)(The Manifest File



.
[Link]
.
.
.
:

.1 1
.
Broadcast Receiver

104
.2 API API
.

.3
. .
.4 API Google Maps
library .


.

.
>?"<?xml version="1.0" encoding="utf-8
><manifest...
"<application android:icon="@drawable/icon
"<activity android:name=".MyFirstProject
>android:label="@string/app_name" ...
></activity
...
Permission

105
></application
></manifest

> <application android: icon )


( . .

)( > <activity android: name


android: label
.
:

<activity> .1
<service> .2
<receiver> .3
<provider> .4


Source Code

106
.

.
)( BroadcastReceiver
)( RegisterReceiver .


)
( .
1 ) (
.
)(intent actions .
)
(
.

Explicit

107


intent

filters .
.



.

.
><intent-filter
.


Send
) ( .
send ) (ACTION_SEND

108

). )( startActivity (.



.


.
.


.

API
21 ) (API Level 7
. API

109

.
.

.


.

) :(Screen size and density



: ) 1 ( )
2dpi ( .

.

Dimension
Dots Per Inch

1
2

110
:) (small) (normal
)(large ). (extra large
: ) (low density
) (medium density ) (high density
)(extra high density



)(UI layout ) (image resources .

.
><supports-screens .

) :(Input configurations
.
1 2.

Trackball
Five-way navigation pad

1
2

111

><uses-configuration .
.

) :(Device features

OpenGL .

><uses-feature
.

) :(Platform Version
16 23
API
. API API
1.0 API Level 1 2.3
API Level 9 . API 1.0

><uses-sdk
API .

112


.

.
.

) : (Define Permission
. :
: INTERNET
: READ_CONTACTS

: WRITE_CONTACTS
: RECEIVE_SMS

: ACCESS_COARSE_LOCATION
wi

Contacts
)Incoming SMS(Text Message

1
2

113

: ACCESS_FINE_LOCATION GPS


:
<manifest
"xmlns:android="[Link]
> "package="[Link]
><uses-permission android:name="[Link].RECEIVE_SMS" /
></manifest

Android security

model :
[Link]

)(Activities

1
.
2 ) ( .
Interact
user interface

1
2

114

1.



. ) Main

Activity (
.
.
2 3 .
4 .
Push
.

) (5LIFO .
1

float
start
3
stop
4
stack
5
last in, first out
2

115

Back
) (Pop .
1 .
) (foreground
2 .

) (Home Application .
. )
( .
.
.
) (.

. .
) (Application-Stack .

Data Structure
Status line

1
2

116
1 .
) ( Home Program
. Back
) (
.
2
. .
.
3
)
( .
)
(.

4 .
1

Back
Web Browser
3
On User Demand
4
Activitys lifecycle callback methods
2

117


.
:
)(Creating activity
)( Stopping activity
)(Resuming activity
).(Destroying activity


.
1
.

.
.

Object

118

.
.



.

) (stack.


Activity
1
2 .
:

Override
Behavior

1
2

119

) : (onCreate
. .
) : (onStart
.
) : (Resumed
) (foreground .
) .
(.
) :(Paused

. )
(
.

) :(Stopped
)
)(background( . stop )

120
Activity (
.
.

) : (onRestart

.
) : (onDestroy
. .
)(onDestroy

. 1.
) : (onSaveInstanceState
.

Text Field .

Terminate
Cursor

1
2

121

1
.
) :(onRestoreInstanceState

)( onSaveInstanceState .

.


.
.

. )( finish
.
.
.
Override

122


Activity )
( .


.
.

)( : onCreate .
.
) (initialize.
)( setContentView
.
User Interface .
)( : onPause
)

123

( .

.
.



. ><activity
1 ><application . :
> <manifest
> <application
><activity android: name=".ExampleActivity" /

></Application
></manifest

Child

124

)(intent filters
> <intent-filter

.

) (SDK
.
Main ) (launcher .
:

"<activity android:name=".MyFirstProject
>"android:label="@string/app_name
><intent-filter
><action android:name="[Link]" /
<category android:name
>="[Link]" /
></intent-filter
></activity

125

> <action .
> <category
) (.

. main
1 .
.

2 .
3 <intent-

>filter ><action
><category ><data .
.

Launcher
Intent Filter

Intent .

1
2

126


)( startActivity
.

. )
(
.
) ( .

.


.
.
.
SignInActivity .
;)Intent intent = new Intent(this , [Link]
;)startActivity(intent

127


SMS .
.

.
.
.

.
.
;)Intent intent = new Intent (Intent.ACTION_SEND
;)[Link](Intent.EXTRA_EMAIL , recipientArray
;)startActivity(intent

EXTRA_EMAIL
. .

to: .
.

128


.
)( startActivity
)( startActivityForResult .
)( onActivityResult .

)(startActivityForResult .


.
.
{)(Private void pickContact
//Create an intent to "pick" a contact, as defined by the content provider
URI
;Intent intent
;)intent = new Intent(Intent .ATION_PICK,Contacts.CONTENT_URI
;)startActivityForResult(intent,PICK_CONTACT_REQUEST
}
@Override
Protected void onActivityResult(int requestCode,int resultCode, Intent
{ )data

129
/* if the request went well(ok) and the request was
PICK_CONTACT_REQUEST */
If(resultCode == Activity.RESULT_OK && requestCode ==
PICK_CONTACT_REQUEST) {
//Perform a query to the contact ' s content provider for the contact 's
name
Cursor cursor = getContentResolver().query([Link]())
new String[] {Contacts.DISPLAY_NAME},null,null,null);
if([Link]()) { //True if the cursor is not empty
int cloumnIndex =
[Link](Contacts.DISPLAY_NAME);
String name = [Link](columnIndex);
//Do Something with the selected contact 's name
}

onActivityResult()
. .
. RESULT_OK result Code
.

requestCode

. startActivityForResult()

130
query
) .(data
Content Resolver
) (query ) (content provider
Cursor .


)( finish .

)( finishActivity .

:
.
.
.
.

131



1 .

.
.

:
{ public class ExampleActivity extends Activity
@override
{ )public void onCreate(Bundle savedInstanceState
;)[Link] (savedInstanceState
//The activity is being created.
}
@override
{ )(protected void onStart
;)([Link]
;)([Link](this, "onStart", 1).show
}
@Override
callback

132
protected void onRestart() {
[Link]();
[Link](this, "onRestart", 1).show();
}
@Override
protected void onResume() {
[Link]();
[Link](this, "onResume", 1).show();
}
@Override
protected void onPause() {
[Link]();
[Link](this, "onPause", 1).show();
}
@Override
protected void onStop() {
[Link]();
[Link](this, "onStop", 1).show();
}
@Override
protected void onDestroy() {
[Link]();
[Link](this, "onDestroy", 1).show();

133
}

:
) (super class .
;)([Link](this, "onDestroy", 1).show


) 1 Interval (.
) ( .
.
.

134

135

136

: 1 :
)([Link]

)([Link]

)([Link]

137

: 2 Back Finish .
:
)([Link]

)([Link]

)([Link]

: 3 ) (Home key :
)([Link]

)([Link]

: 4 :
)([Link]

)([Link]

)([Link]

)([Link]

)([Link]

)([Link]


Control+F11 7 9 ) 1
Num Lock ( .
2 .

. .

Keypad
Change Screen Orientation

1
2

138
) (Home key )( onDestroy .
)
Task Manager
( .
Home key
. :
)([Link]

)([Link]

)([Link]

.
:

.1 ) :(Entire Lifetime
)( onCreate )( onDestroy
. ) (
)( onCreate . ) (Resource
)( onDestroy . 1

Thread

139

thread
)( onCreate )( onDestroy .

.2 ) :(Visible Lifetime
)( onStart )( onStop .
. )( onStop

.
.
)( onStart BroadcastReceiver
1 .

)( onStop .
)( onStart )( onStop .

.

.3 ) :(Foreground Lifetime
)( onResume )( onPause .
register
unregister

1
2

140

.
)( onPause
sleep
.

.

) (
.

.
)( onCreate
.
)( onCreate )(onResume

Stop ) )( ( onRestart
)( onResume . )(onResume

. )( onResume

141

. )( onPause .
)( onPause .

)( onCreate(),onResume(),onPause .
)

.
.
.


)
( .

142

143

)(onCreate

)(onRestart

)(onStart


.


View
.



) SavingActivityState
(.
)(onStart
.


) (Stop
)(onStart
.


.

)(onStart

)(onStart

)(onResume

)(onStop

144

)(onResume

)(onPause

)(onStop



.

)(Stack
.
)(onPause
.


.



CPU
.



.

. )(onResume


)(onStop.

.

)(onPause

)(onResume

)(onStop

)(onRestart

)(onDestroy

145

)

(

.


)( onRestart

)( onDestroy.

)(onDestroy


.


.


) )( finish
(

.
)( isFinishing
.


.
)( onPause )( onResume

146

)( onPause .

147

)( onPause
.
1 )( onStop )( onDestroy
.
) (
)( onPause .

.

:
.
) ( Processes and Threading
.


) (Pause
) (Stop .

Recover

148
1 Activity
.
.
) (Resume
.

Activity
.
) (Resume .
.

.
.
.

.

object

149

)( onSaveInstanceState
.
Bundle Bundle.
)( putString
.
Bundle )( onCreate
)( onSaveInstanceState
. Bundle
)( onCreate 1 .

Null

150

2
.
) ( .
)
(.

)( onSaveInstanceState .
)

151

) (BACK key
( .
)( onStop )( onPause .

)( onSaveInstanceState
)( onSaveInstanceState
Activity .
)( onSaveInstanceState View ) (layout
. 1
.

.
EditText
CheckBox .
ID android:id
. ID
.

Widget

152
)( onSaveInstanceState

1.

.

)( onSaveInstanceState


)(super class .

: )( onSaveInstanceState 2
) (
) ( .
)( onPause )
(.

Override
Guarantee

1
2

153


) (
1 .
.
.

.
.


2 3 )
( .
) (restarts
) )( onDestroy )( onCreate ( .

1

Orientation
Configuration
3
Runtime
2

154

.
1 .

)
( :
)( onSaveInstanceState
)( onRestoreInstanceState
)( onCreate



. ) (Pause ) (Stop
.

Flexibility

155

.
1 .
A B :
.1 )( onPause A .

.2)( onStart() onCreate )( onResume B


) . (.
.3 A
)( onStop .


. 2
)( onPause
)( onStop .

Overlap
Data Base

1
2

156
.
. Intent
)( startActivity
)
( .
) ( .

)(startActivityForResult .
.

157


) ( .
.

XML
. .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip" >
<TextView
android:id="@+id/tvName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Number 1:"

158
android:paddingRight="10dip" />
<EditText
android:id="@+id/etNumber1"
android:layout_toRightOf="@+id/tvName1"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:inputType="number"
android:singleLine="true"
android:imeOptions="actionNext" />
</RelativeLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip" >
<TextView
android:id="@+id/tvName2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Number 2:"
android:paddingRight="10dip" />
<EditText
android:id="@+id/etNumber2"
android:layout_toRightOf="@+id/tvName2"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:inputType="number"
android:singleLine="true"
android:imeOptions="actionDone" />
</RelativeLayout>
...

159

XML
res/layout
[Link] [Link] [Link] .
. [Link]
.
. )

( .

>?"<?xml version="1.0" encoding="utf-8


<Button
"xmlns:android="[Link]
"android:id="@+id/btnBack
"android:layout_width="fill_parent
"android:layout_height="fill_parent
>android:text="Click here to back to Main screen!" /

160


layout_width layout_height fill parent .

[Link] TextView
EditBox
.
.

161
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvNumber1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvNumber2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvNumber3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btnResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Return Result" />
</LinearLayout>

. [Link] (

162

layout
. .
.
1.
2.
3.
4.
5.
6.

public class TestIntentActivity extends Activity {


EditText etNumber3;
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);

7.
8.

final EditText etNumber1 =


(EditText) findViewById([Link].etNumber1);

9. final EditText etNumber2 =


10. (EditText) findViewById([Link].etNumber2);
11. etNumber3 =
12. (EditText) findViewById([Link].etNumber3);
13. Button btnNext =

163
14. (Button) findViewById([Link]);
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.

[Link](new OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new
Intent([Link], [Link]);
startActivity(intent);
}
});
Button btnSum = (Button)
findViewById([Link]);
[Link](new OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new
Intent([Link], [Link]);
[Link]("Number1",[Link]().toString());
[Link]("Number2",[Link]().toString());
startActivityForResult(intent, 1);
}
});
}

35. @Override
36. protected void onActivityResult(int requestCode, int
resultCode, Intent data)
37. {
38. if (resultCode == RESULT_OK && requestCode == 1) {
39. if ([Link]("Result")){
40. [Link]([Link]([Link]().g
etInt("Result")));
41. }
42. }
43. }
44. }

:
. EditText
final EditText etNumber1 =
(EditText) findViewById([Link].etNumber1);
final EditText etNumber2 =

164
;)(EditText) findViewById([Link].etNumber2

;)etNumber3 = (EditText) findViewById([Link].etNumber3

13 btnNext 22 layout .
NextActivity .

)( startActivity 20
.

23 34 btnSum layout .
)( [Link] Intent
.
39 40
putExtra . 1 2 .
.
. 31 )(startActivityForResult

Key
Value

1
2

165

.
.

35 42 )( onActivityResult .
. 38
) (RESULT_OK
1 39 40 .
)( startActivityForResult

.

40 Result EditBox
. .
29 30 .
) (SumAvtivity . .
{ public class SumActivity extends Activity
@Override
{ )public void onCreate(Bundle savedInstanceState
;)[Link](savedInstanceState
;)setContentView([Link]
;)(Bundle extras = getIntent().getExtras
{ )if(extras == null
;return
}

1.
2.
3.
4.
5.
6.
7.
8.
9.

166
10. String value1 = [Link]("Number1");
11. String value2 = [Link]("Number2");
12. TextView tvNumber1 = (TextView)
findViewById([Link].tvNumber1);
13. TextView tvNumber2 = (TextView)
findViewById([Link].tvNumber2);
14. TextView tvNumber3 =(TextView)
findViewById([Link].tvNumber3);
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.

[Link]("Number 1 is: " + value1);


[Link]("Number 2 is: " + value2);
final int i = [Link](value1);
final int j = [Link](value2);
[Link]("Number 1 + Number 2 is: " +
[Link](i+j));
Button btnResult = (Button)
findViewById([Link]);
[Link](new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
[Link]("Result", i+j);
setResult(RESULT_OK, intent);
[Link]();
}
});
}
}

layout 5 : SumAvtivity
. [Link]


12 6
.

167

Number1 Number2

10 11
.

1213 14 TextView XML


.

15 19 TextView
.

20 29 . XML
.
Result
. SetResult

RESULT_OK ) .
24 Intent
27

.
(.

168
putExtra
boolean String int ...
Intents and Intent Filters .


. .
{ public class NextActivity extends Activity
@Override
{ )public void onCreate(Bundle savedInstanceState
;)[Link](savedInstanceState
;)setContentView([Link]
;)Button btnBack = (Button) findViewById([Link]
{ )([Link](new OnClickListener
@Override
{ )public void onClick(View v
;)([Link]
}
;)}
}
}

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.


.
.
.

. .

169

: XML
:

171

)(Application Resources

. 1
.

XML .

.
.
. res


. XML
.
.

Source Code

172
SDK
1
XML .
[Link]

/res/drawable SDK [Link]



.



. XML
.
/res/values-

FR
.

Identification Code

173

1 2 .

.
) (orientation
. 3

4 .
.

View Layout
View ) (single object View .
Layout View
. )(Label

View TextView.

qualifiers
alternative resources
3
portrait orientation
4
landscape orientation
2

174
View
. view
.
View 1 View
. 2
.
Button,EditText,TextView ... .
import
. :
;import [Link]
;import [Link]
;import [Link]

3 view ViewGroup

view Layout .
. XML
1

Base Class
Widgets
3
Layouts
4
Derived
2

175

Layout
Layout . :

view Linear

Layout.
View Grid Layout

) View
( .
View Relative Layout

.
1
2
) View (3 4.

Form
Desktop Application
3
Layout
4
Assign
2

176


.
) (xml
:
Eclipse ADT UI Designer
Droid Draw
Asset Studio


1 2 3 .

) (

Method
Procedural
3
Declarative
2

177

XML
. XML
. XML HTML1.

.

) (XML .
XML

. XML
) (Functionality
.

) (XML
) (functionality
.

Hyper Text Markup Language

178

.
Res/Layout XML

.
view
XML 1 .
view ViewGroup .
ViewGroup )( setContentView
. )(onCreate

)(Events
Event
Listener . Event

resource

179

. ) (Events controllers
.
.
Listener .

181


) (MoSync ) (SDK1 . SDK

IDE Eclipse .
SDK
SDK
. SDK

. SDK .
Editor,Compiler,Linker,Libraries,Emulator,

MoSync SDK 2
.
. Cross-Platform .
.
C++,Java Script(jQuery Mobile),HTML5

Software Development Kit


Open Source

1
2

182
.
!


iPhone ....
MoSync SDK
.
MoSync SDK Android SDK
iPhone SDK Windows phone SDK .
SDK
.
SDK
. API
2 ... .
) NativeUI( OpenGL
.

Mobile Sorcery
)Location(GPS

1
2

183

SDK

HTML5,JavaScript,C/C++ .
HTML5 JavaScript C,C++
!
IDE Eclipse
1 . GCC 3.4.6
2 MoSync
.
3 MoSync Intermediate Language .
Pipe-tool
) Front-End Back-End

.
(.

Eclipse-Based
Backend
3
Intermediate Code
2

184
1GCC C . egcs
Gcc . GNU C/C++ Compiler .
. SDK C OpenSource
.
Pipe-tool MoSync

.2 .
) (pass 25000
.
Pipe-tool. IDE


build IDE
. Pipe .


.
.

[Link] .
MoSync's code transformation engin

185

iOS, Android, Windows Phone, Windows Mobile, Symbian,


JavaME
1 MoRE2

.
3 .

MoRE . 16
4 .
.
N95 K700i .
.

.
. Device Profile Database

Emulator
MoSync Runtime Environment
3
MoSync bytecode
4
stylus
2

186
. 1 2
.

API

) (BlueTooth,GPS ...
. (.h file) 3 . )
( .
) runtime

Runtime( .
.

Vendor
Directory
3
Header file
2

187

188


.
.

MoSync

.
. SDK

[Link] .

189

2.7 .
.
: SDK 1 2
ME 3
4 .
iOS ) (iPhone,iPad,iPod
SDK SDK .
) (Mac
SDK MoSync SDK for OS X

MoSync SDK for Windows


Application Packages
3
Smart Phone
4
Pocket PC
2

190
XP

) Java SE Runtime Environment (JRE) 6


Oracle/Sun (
300
. .exe
.)

Unpacking ) (
.

191

). (Fade ) (License
.)

192


. ).

(.
.
)

( .

193


.
.


.
).([Link]/forum
Help Register
. )
(.

194
?Already registered

Click Here .
.) (.

:
: Online user guides
[Link] .
.

195

: Example applications )
( Project

Explorer ) . MoSync/examples
(
: Online tutorials
.
: API reference manual API
MoSync SDK .
: Developer center
.
: Screencasts
SDK IDE.
Welcome Screen
Show this screen at startup .

Help Welcome .

196

( IDE .

197

198
IDE :
: Project Explorer View
)(import
.
. File Manager .
: Editor View .

1 2
. ) 3 (
Ctrl+Spacebar
.
: Device Profiles View
) (
.

1

highlighting
indenting
3
identifier
2

199

.


.
: Finalizer View
: Problems View
: Console View
: MoRE Emulator

) (

. (Samsung/Galaxy S )
.

)
(

200

201

MoRE

.
SDK )
SDK ( . Window Preferences
. MoSync Tools Android

( SDK .

Emulator . )
(
iOS )
Ask Every Time
iPhone iPhone
( . .
MoRE . )

202

203

204


MoSync 3.0
.
. ) ([Link]
.

205

206

207


.
C++ HTML5 .
HTML5
HTML5
C++
1
.
:

Xml .
.
Wormhole C++ library (WebAppMoblet, MessageStream,
)MessageStreamJSON
) JavaScript libraries (included in the file [Link]

Hybrid Project

208

Wormhole C++

[Link] include [Link]


[Link] .
:
)1. JSON messages(MessageStreamJSON
)2. string stream messages(MessageStream

)(JSON messages
[Link]() 1
C++ .
:
)[Link](message, callbackFunction

message String .
.
.
Built in

209

callbackFunction 1.

. )2 (
.

)(string stream messages


JSON messages ) 20
(.
)[Link](stringArray, callbackFunction

.
.
.


Hybrid .
> File > New > Project
Optional
Asynchronous Mechanism

1
2

210
MoSync Project > HTML5 > HTML5/JS/C++ Hybrid Project

Template

. JSON message
string stream messages .
C++
1 ...



C++ .



.
. C++ .

Vibrate

211

C++
:
;)")'callJS("alert('Hello World

)" alert("Message_string
.
.
;)( [Link](this, "Message_string", 1).show
).
!(

.
. :
;)(int x=getUserAge
;]char func[512
;)sprintf(func,"alert(%s);",x
;)callJS(func

212

.
!
;"char x[]="MiladFashi
;]char func[512
;)sprintf(func,"alert(%s);",x
;)callJS(func

. char *x
!
.
.


) ( :
;)sprintf(func,"alert( ' %s ' );",x


sprintf .
single quotation

213

sprintf ) Concat (
+
.
.
)( strcat strcat
. )( strcat
. strcat
.
.
Hybrid Break point .

.


)( callJS
.

214

.
)() maGetScrSize API (maapi.h
)( setBoxSize
flipbox
).

3
7 (.
:
) (html
string stream messages :
)([Link]=function
{
;)]"[Link](["Custom", "screenSize
}

:
)void handleMessageStream(WebView* webView, MAHandle data

215
{
// Create a message stream object. This parses the message data.
// The message object contains one or more strings.
MessageStream stream(webView, data);
// Pointer to a string in the message stream.
const char* p;
while (p = [Link]()){
if (0 == strcmp(p, "Custom")){
const char* command = [Link]();
if (NULL != command && (0 == strcmp(command, "screenSize"))){
MAExtent scrSize = maGetScrSize();
int width = EXTENT_X(scrSize);
int height = EXTENT_Y(scrSize);
char buf[512];
sprintf(buf,"setBoxSize(%d,%d)",width,height);
callJS(buf);
}
}
}
}

flipbox setBoxSize(x,y)
.
.

216
)function setBoxSize(x,y
{
;)"$("#flipbox").animate({width:'+='+x},"slow
;)"$("#flipbox").animate({height:'+='+y},"slow
}

jquery.
jQuery jQuery
jQuery [Link] .
.
.
.
:
[Link]
[Link]
[Link]
[Link]

flipbox CSS :

217
#flipbox {
width: 10px; //
height:10px;
line-height: 200px;
background-color: #ff9000;
font-family: 'ChunkFive Regular', Tahoma, Helvetica;
font-size: 2.2em;
color: #ffffff;
text-align: center;
}

218
:

:
SQLite

220 SQLite




.
. ...
.
.
.

) (Client )
Client ) (Desktop (

.

.

221

.


.



.
.

.
.

SQL Server MySql
...

SQLite.

222 SQLite

SQLite
2000 . 1
SQLite . .
dll API .
Table
.

SQLite

. )Command(
.
API SQLite
.

2
Firefox .
Firefox
[Link] Hipp
Add-On

1
2

223


).
(.
:
[Link]

Fire Fox . ) (
Tools SQLite Manager . ) (
Database New

Database
.

1 .

RDBMS

224 SQLite

225

Database Connect Database


.


1 .
Provider
API SQLite C++
++C .
Provider SQLite

1 Php: php
Provider.

2 Java: SQLiteJDBC
:
[Link]
3 .NET: Provider phx software
:
Provider

226 SQLite
[Link]

.

.
The Definitive Guide to SQLite
Author: Michael Owens
Publisher : Apress

SQLite
SQLite 1

. 2000 .
3 4 5
6 7.

Embedded Database
Relational DB
3
Portability
4
Easy to Use
5
Compact
6
Efficient
7
Reliability
2

227

API
C
1 )Administration( .
2
3 .
4
. .
.
) (.

Sybase SQL any

where,Microsoft 'S Jet Engine,


.
) (Large-Scale
) (Embedded !

IBM 'S DB2

.EveryPlace, Oracle 's log

Network Configuration
Overhead
3
Network Call
4
LightWeight
2

228 SQLite
SQLite
. . .
. Provider

. SQLite . )

C . SQLite C

229

1 SQLite
.
:
Apples Mac OS X
Safari web browser, [Link] email program, RSS manager,
Apples Aperture photography software.
Solaris operating environment
Mozilla Projects mozStorage
C++/JavaScript API layer
Firefox, Thunderbird, Sunbird.
SQLite has been added as part of the PHP 5 standard library.
Linux-based Palm OS
Symbian OS [Link] OS [Link] most smart
phone OS and cell phone applications .
D-Link Media Lounge.
Music players.

Embedded

230 SQLite
Complete New Yorker DVD set-a digital library of every issue
of the New Yorker magazine-.

SQLite .

) ( .

Interface SQLite C API.


Tokenizer Lexical Analyser ). Scanner
(.

Modular Architecture

231

Syntax Analyser .

Semantic Analyser
SQL1.
2 3
.
Virtual Machine ) virtual database engine (VDBE
. .
4 .
. 128 ) (opcode
. SQL
Select,update,delete, .
:
:SQL

Structured Query Language


Syntax Analyase and Validation
3
Data Structure
4
VDBEs byte code
2

232 SQLite
SELECT name FROM episodes LIMIT 10;

( )
0 Integer

10 0

1 MustBeInt 0 0
2 Negative

0 0

3 MemStore 0 1
4 Goto

0 15

5 Integer

0 0

6 OpenRead 0 2
7 SetNumColumns
8 Rewind

0 13

9 MemIncr

0 13

10 Column

0 3

11 Callback

1 0

12 Next

0 9

13 Close

0 0

14 Halt

0 0

0 4

15 Transaction

0 0

16 VerifyCookie

0 190

17 Goto

0 5

18 Noop

0 0

233



.
.
[Link] .

SQLite
:
)Portability ( : 1632 64
. Big , Little Endian Byte Order
. Encoding UTF-8,UTF-16 .
) Compactness ( SQLite :
.
) 256( !
) Simplicity ( : API .

234 SQLite
) Flexibility ( :
SQLite .
.

SQLite
) (Query
.

) .(SQL Server
SQLite
) (Medium-Scale .
SQLite

.
2 SQLite
. 2Terabyte .

235

)(RAM

.
256 RAM )
dirty page
Bitmap Allocation( . 100
25 RAM .
1 SQLite .
. Trigger .
View SQLite .

.

SQLite
API
) (low-level SQLite :

Nested Transaction

236 SQLite

: maDBOpen .

: maDBClose .

: maDBExecSQL SQL .
cursor handle .

: maDBExecSQLParams SQL
) MoRE iOS (.

: maDBCursorDestroy cursor
maDBExecSQL , maDBExecSQLParams
.

: maDBCursorNext .
) (Result Set.

.

: maDBCursorGetColumnData )
(
data handle ) .

237

)( )(
(.

: maDBCursorGetColumnText
.

: maDBCursorGetColumnInt
int.

: : maDBCursorGetColumnDouble
) double ( .



.
Database API :
.1 )( maDBOpen .

Absolute path

238 SQLite

.
.2

maDBExecSQL

insert,update,delete, .
Command select

Cursor Handle .
.
.3
maDBCursorNext
.
.
.
.4 .
maDBCursorDestroy .
.5
)( maDBClose .

239

. maapi.
1 )( .
Open Source

.
.
:
[Link] .

SQLite Manager ) .
(.
Words . VARCHAR

. ) (english ) (persian
. .

low-level functions
Add-on

1
2

240 SQLite
. SQL
:
"CREATE TABLE "Words" ("english" VARCHAR NOT NULL , "persian
) VARCHAR NOT NULL

. )


. 504
. .
.
.

241


!
"#include "maapi_defs.h

)( maDBOpen .
:
*MAHandle maDBOpen(const char
)char path

242 SQLite
. Path
.
: [Link]
"/mnt/sdcard/[Link]"

C )
: (
const char *path="/mnt/sdcard/[Link]";

:
void openDataBase(){
const char *path="/mnt/sdcard/[Link]";
MAHandle MAHDB = maDBOpen(path);
MAHandle cursor;
cursor = maDBExecSQL(MAHDB,"Select * from Words");
char func[512];
char eword[50];
maDBCursorNext(cursor);
maDBCursorGetColumnText(cursor, 0, &eword,50);
sprintf(func,"alert('%s')",eword);
callJS(func);
maDBClose(MAHDB);

243
}

)( maDBExecSQL :
MAHandle maDBExecSQL(MAHandle databaseHandle,

) const char * sql

)( maDBCursorNext :
)int maDBCursorNext(MAHandle cursorHandle

.
-2 . :
#define MA_DB_OK 0
#define MA_DB_ERROR -2

)( maDBCursorGetColumnText :
int maDBCursorGetColumnText(MAHandle cursorHandle,int colum
)nIndex,void* buffer,int bufferSize

cursorHandle

) ( columnIndex

244 SQLite
.
.

Buffer
bufferSize

: jQuery
jQuery Mobile

.

.

246 jQuery Mobile jQury

247

249


.
.
UserFriendly
.
.

. ...
.
:
HDPI=high dot per inch -1

MDPI=medium dot per inch -2

LDPI=low dot per inch -3

250


(

)
:

DPI

Screen Resolution

Screen Size

Device Name

275

540 x 960

Motorola Atrix

254

480 x 800

3.7

Google Nexus 1

163

320 x 480

3.5

iPhone 3GS

326

640 x 960

3.5

iPod Retina Display

132

1024 x 768

9.7

iPad

168

1024 x 600

PlayBook

168

1024 x 600

'Galaxy Tab 7

150

1280 x 800

10.1

Motorola Xoom

168

1024 x 600

Nook Color

. ) iPad 5(iOS5
2048*1536
9 . iPad

251

Galaxy mini 3 240*320


. .

.
3 10
. APK 3
10 .
.
) CSS3(Media Query
) ([Link],[Link].
. CSS

CSS ....
Media Query Adapting Pages for Mobile with Media
Queries Adobe Dreamweaver CS5.5 Studio Techniques
Designing and Developing for Mobile with jQuery, HTML5, and

CSS3 DAVID POWERS .


:

252
[Link]


: Screen Size .
:Screen density 1
.
: ) (DPI=dot per inch ) PPI=pixel per

(inch . dpi . ppi


dpi )
( ppi .
.
: Orientation . ) (landscape
) (portrait
. aspect

ratio aspect ratio


.

Quantity

253

:Resolution .
:

dpi .
Multiple Screen Support
! ) (density
. .

)Density-independent pixel (dp

.
) : Density-independent pixel (dp

. :
)dp = px / (dpi / 160
dp: Density-independent pixel
px: Pixel
dpi: dot per inch

254
dp px :
)px = dp * (dpi / 160

160 . 160


Density-independent pixel .
) (s5570
. 240*320 . 120 dpi . Sony

Ericsson Xperia X10 480*854 245 dpi


. 160
Density-independent pixel
.
dp .
:
dp(width) = 240 / (120 / 160) = 320

255

120 240
. 160
320 ).
2 . 120
240 2
(.
dp(Height) = 320 / (120 / 160) = 426.67

.
!
: Xperia X10
dp (width) = 480 / (240 / 160) = 320

240 480
. 160
320 .
dp (Height) = 854 / (240 / 160) = 569.3

256


).( maGetScrSize
. C++
HTML C++


) ( . [Link]
[Link] 160 Density-

independent pixel !
.

.

.
.

257

25

544 .

. 569
. ).
(.
:
;)maScreenSetFullscreen(1

.
AVD Emulator
.
. Run Run

configurations .
. .
Extra high

High density

Medium

Low density

258
(120), ldpi

density (160),

(240), hdpi

mdpi

density (320),
xhdpi

Small

QVGA

480x640

screen

(240x320)

Normal

WQVGA400

HVGA

WVGA800

screen

(240x400)

(320x480)

(480x800)

WQVGA432

WVGA854

(240x432)

(480x854)

640x960

600x1024
Large

WVGA800**

WVGA800*

screen

(480x800)

(480x800)

WVGA854**

WVGA854*

(480x854)

(480x854)
600x1024

Extra

1024x600

WXGA

Large

(1280x800)

screen

1024x768

1536x1152

2048x1536

1920x1152

2560x1536

1920x1200

2560x1600

1280x768
* To emulate this configuration, specify a custom density of 160 when
creating an AVD that uses a WVGA800 or WVGA854 skin.
** To emulate this configuration, specify a custom density of 120 when
creating an AVD that uses a WVGA800 or WVGA854 skin.
This skin is available with the Android 3.0 pla orm

259


.
) 3(
. QVGA
skin Built-in QVGA .
: XperiaX10 ) 4( .
WVGA854 skin
Built-in WVGA854 .
: Samsung Galaxy Tab 2 (10.1) )10.1
( . WXGA
skin Built-in WXGA .
) Android 3.0 (API level 11 .
.
)

( .

260

)
( .
160 .
.html
.
><script
;)[Link]([Link]
;)"[Link](",

261

;)[Link]([Link]
></script

10
1280 x 800 px
) (1280>800
) (landscape
.
.
800*1280 !
Orientation .
Orientation .

MoSync\examples\cpp\ScreenOrientation
. )
()

( .

262

263

CTRL+F11

). (.
) (MoRE F4
). (.

264
ScreenOrientation
MAUtil::Moblet
Orientation
. )(maScreenSetOrientation

.
)int maScreenSetOrientation ( int orientation


.
.

:
#define SCREEN_ORIENTATION_LANDSCAPE 1
#define SCREEN_ORIENTATION_PORTRAIT 2
#define SCREEN_ORIENTATION_DYNAMIC 3

SCREEN_ORIENTATION_DYNAMIC

265

Orientation
.
1 2 .
. . 2
.
;)maScreenSetOrientation(SCREEN_ORIENTATION_DYNAMIC

:
//Get the screen size.
;)(MAExtent extent = maGetScrSize
) MAExtent maGetScrSize ( void

)( MAExtent maGetScrSize MAExtent .


typedef int MAExtent
.
.
Orientation .
)void customEvent(const MAEvent& event

266
Orientation
.

.

) rotateUI ( :
)if ([Link] == EVENT_TYPE_SCREEN_CHANGED
{
;)(rotateUI

EVENT_TYPE_SCREEN_CHANGED 21
. .
extent MAEXTENT
. Orientation
.

267


.
if (EXTENT_X(extent) > EXTENT_Y(extent)) { // Landscape

}
else { // Portrait


Orientation HTML5 !
hybrid UI HTML5
C++ .
Orientation .
WebAppMoblet
HTML5

) (Handling . HTML5
Orientation .[Link]

268
[Link]
:
;)maScreenSetOrientation(SCREEN_ORIENTATION_DYNAMIC

HTML jQuery Mobile .


) tap,

(taphold,swipe, orientationchange, scrollstart, scrollstop.


HTML5
)
(.

269

.
:
>")(<body onorientationchange="rotateUI

)( rotateUI.
[Link] 4
:

: 90 ).
(landscape
: 0 / ).
portrait (.
: -90
.
: 180 ) ( .

><!--Create by MILAD FASHI_1391/02/18--

270
<!DOCTYPE html>
<html>
<head>
<script src=" js/[Link]"></script>
<script src=" js/[Link]"></script>
<script src=" js/[Link]"></script>
<link rel="stylesheet" href=" js/[Link]"
/>
<title>Orientation in HTML5</title>
<style type="text/css">
[Link]
{
background-color:#f9c456;
margin:0;
}
[Link]
{
opacity:0.4;
position:absolute;
filter:alpha(opacity=60); /* For IE8 and earlier */
}
</style>
<script type="text/javascript">
//global variables

271
var X;
var Y;
var maxX=1280;//maximum width of screen(Samsung Galaxy
Tab2 10.1 inch width for base of calculation)
var maxY=800;//maximum height of screen(Samsung Galaxy Tab2
10.1 inch height for base of calculation)
[Link]=function()
{
setSize();
}
function setSize()
{
X=[Link];//width of native device
Y=[Link];//height of native device
//set size for multiple screen
support(tablet,handset(smart phone),...)
//setting background :
$("#bg").css("width",X);
$("#bg").css("height",Y);

//setting openPanelButton:
var openPanelWidth = parseInt($("#openPanel").css("width"),10);
var widthCalc=(X*openPanelWidth)/maxX;
$("#openPanel").css("width",widthCalc);
}

272
function rotateUI()
{
if([Link]!=180)/*[Link]==90 ||
[Link]==-90 || [Link]==0*/
{
//Exchange X and Y dimension
var temp=X;
X=Y;
Y=temp;
}

//Rearrange background
$("#bg").css("width",0);
$("#bg").css("height",0);
$("#bg").animate({width:'+='+X},"fast");
$("#bg").animate({height:'+='+Y},"fast");

}
</script>
</head>
<body onorientationchange="rotateUI()">
<div id="bg" class="background">
<img id="openPanel" src="pic/[Link]"
class="openPanel"></img>

273
</body>
</html>

274
. .
.


[Link]@[Link] .

You might also like