Flash
Development
for
Android Cookbook
Over 90
recipes
to
build
exciting
Android
applications
with
Flash,
Flex,
and AIR
Joseph Labrecque
[PACKTl
III
IV
I V I
J
PUBLISHING
Table
of Contents
Preface
1Chapter
1:Getting
Ready
to Work with Android:Development
Environment
andProject
Setup
7 Introduction 8Using
Flash Professional CS5.5todevelop
Androidapplications
8Targeting
AIR for Android with Flash Professional CS5.5 10Using
Flash Builder 4.5 todevelop
Androidapplications
13Enabling
Flash Builder4or Flex Builder toaccess FlexMobile SDKs 15Using
Flash Builder 4 and belowtodevelop
Androidapplications
18Enabling
Powerflasher FDT 4.1toaccessFlex Mobile SDKs 21Using
Powerflasher FDT 4.1 and below todevelop
Androidapplications
23Converting
astandard Flexproject
toa Flex Mobileproject
26Configuring
the AIRSDKtopackage
AIR forAndroidapplications
on Windows 29Configuring
theAIRSDKtopackage
AIR for Androidapplications
onLinuxor MacOS 30
Chapter
2:Interaction
Experience: Multitouch,
Gestures,
and OtherInput33
Introduction 34Detecting supported
deviceinput
types 34Detecting
whetheror nota devicesupports
multitouch 36Verifying specific gesture
support
forcommon interactions 38Using
gestures
tozoom adisplay
object
41Using gestures
topan adisplay object
43Using gestures
toswipe
adisplay object
46Using
gestures
to rotateadisplay object
49Accessing
rawtouchpoint
data 52Creating
a customgesture
based upon touchPointdata 55Table ofContents
Invoking
the virtualkeyboard programmatically
62Responding
toAndroidsoft-key
interactions 66Responding
to trackball andD-Pad events 68Chapter
3:
Movementthrough Space:
Accelerometer andGeolocation Sensors
Z3
Introduction 74Detecting
whetheror notanAndroid devicesupports
the accelerometer 74Detecting
Android device movementin 3Dspace 76Adjusting
the accelerometer sensorupdate
interval 78Updating display object position
through
accelerometerevents 82Switching
betweenportrait
andlandscape
based upon device tilt 86Detecting
whether or nota devicesupports
ageolocation
sensor 89Retrieving
devicegeolocation
sensordata 93Adjusting
thegeolocation
sensorupdate
interval 96Retrieving
map datathrough geolocation
coordinates 101Chapter
4: Visual and AudioInput:
Camera andMicrophone
Access 107 introduction 107Detecting
camera andmicrophone support
108Using
thetraditional camera API tosave acaptured image
110Using
the Mobile CameraUl APItosave acaptured photograph
113Using
the Mobile CameraUl API to save acaptured
video 118Using
the devicemicrophone
tomonitor audiosample
data 122Recording
Microphone
AudioSample
Data 125Chapter
5: RichMedia Presentation:
Working
withImages,
Video,
and Audio 131 Introduction 131Loading photographs
from the device cameraRoll 132Applying
Pixel Bender Shader effects toloadedimages
136Playing
video files from the localfilesystem
or over HTTP 141Playing
remote video streamsover RTMP 146Playing
audiofiles from the localfilesystem
or overHTTP 152Generating
anaudiospectrum
visualizer 156Generating
audio tones foryourapplication
159Chapter
6: StructuralAdaptation:
Handling
DeviceLayout
andScaling
163 Introduction 164Detecting
useable screenbounds and resolution 164Detecting
screen orientationchanges
166Scaling
visual elementsacrossdevices at runtime 169Scaling
visual elements based onstage
resize in Flash Professional CS5.5 172Employing
theProject panel
in Flash Professional CS5.5 176Freezing
aFlexapplication
tolandscape
orportrait
mode 179Defining
ablank Flex mobileapplication
183Defining
a Flex mobile view-basedapplication
185Defining
aFlex mobile tabbedapplication
withmultiple
sections 188Using
asplash
screen within a Flex mobileapplication
191Configuring
the ActionBar withinaFlex mobileproject
foruse withViewNavigator
194Hiding
the ActionBar control in asingle
view
fora Flex mobileproject
198Chapter
7:Native Interaction:
StageWebView
and URI Handlers
201
Introduction 201
Opening
awebsite in the default Android browser 202Rendering
awebsite within anapplication
205Managing
theStageWebView history
210Using StageWebView
to load adsusing ActionScript
216Using StageWebView
toload ads withinaFlex mobileproject
219Making
aphone
callfromanapplication
225Sending
a text messagefromanapplication
228Invoking Google
maps from anapplication
231Invoking
the Android Marketusing
application
URIs 236Sending
e-mail fromanapplication
239Chapter
8: Abundant Access;File
System
and Local
Database 243 Introduction 243Opening
a local file from devicestorage
244Saving
a file to devicestorage
247Saving
data acrosssessionsthrough
local sharedobject
252Storing application
stateautomatically by using
Flex 257Creating
a localSQLite
database 260Providing
adefaultapplication
database 266Automating
database tasks with FlexORM 271Chapter
9: Manifest Assurance:
Security
and Android Permissions
279
Introduction 279
Setting application permissions
with the Android Manifest file 280Preventing
the devicescreenfromdimming
283Establishing
Android custom URI schemes 286Anticipating
AndroidCompatibility Filtering
290Instructing
anapplication
to be installed to Device SDCard 292Encrypting
a localSQLite
database 294too-Table of Contents
Chapter
10:
Avoiding
Problems:
Debugging
and
ResourceConsiderations
301Introduction
301Debugging
anapplication
with Flash Professional 302Debugging
anapplication
with Flash Builder 305Rendering application
elementsusing
thedevice GPU 310Automating application
shutdownupondeviceinterruption
events 311Exiting
yourapplication
with the device back button 313Monitoring
memoryusage
and frame rate in anapplication
314Chapter
11: Final Considerations:Application Compilation
andDistribution
319
Introduction
320Generating
acode-signing
certificateusing
Flash Professional 320Generating
acode-signing
certificateusing
Flash Builder 322Generating
acode-signing
certificateusing
FDT 323Generating
acode-signing
certificateusing
the AIRDeveloper
Tool 325Preparing
icon files for distribution 327Compiling
anapplication using
Flash Professional 330Compiling
anapplication
using
Flash Builder 334Compiling
anapplication
whenusing
FDT 336Compiling
anapplication using
the AIRDeveloper
Tool 337Submitting
anapplication
tothe Android Market 339Index