Professional Documents
Culture Documents
Developing Android
Developing Android
by Véronique Brossier
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
May 2011: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Developing Android Applications with Adobe AIR, the image of a Royal Flycatcher,
and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-39482-0
[LSI]
1303389007
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
1. AIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Installing the Adobe Development Tools 2
Flash Professional CS5.5 2
Flash Builder 4.5 2
Installing the AIR Runtime on an Android Device 2
What Is in the AIR SDK 3
New ActionScript Libraries 4
Functionalities Not Yet Supported 5
AIR on the Desktop Versus AIR on Android 5
Mobile Flash Player 10.1 Versus AIR 2.6 on Android 6
vii
Using Flash Professional 13
Using Flash Builder 14
Mobile Utility Applications 15
Launchpad 15
Device Central CS5 15
Package Assistant Pro 15
De MonsterDebugger 16
Installing AIR on an Android Device via a Server 16
Other Tools 16
Conclusion 18
3. Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Android Software Development Kit 20
Installing the Android SDK 20
Installing the Android Debug Bridge 21
Detecting Your Device 22
Using the Dalvik Debug Monitor 22
Using the logcat Command 23
Using the Virtual Device Manager and Emulator 24
How Does AIR Run on Android? 25
Starting AIR with intent 25
AIR Access to Android APIs 26
Using the Command-Line Tool 27
A Basic Review 27
Conclusion 28
Table of Contents | ix
7. Multitouch Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
A Brief History 79
What Is Multitouch and Gesture? 80
How Does It Work? 80
The Multitouch Class 81
The GestureEvent Class 82
The Zoom Gesture 82
The Rotate Gesture 83
The Pan Gesture 85
The Swipe Gesture 86
The Press and Tap Gesture 87
The Two-Finger Tap Gesture 88
The TouchEvent Class 88
The GestureWorks Library 91
Designing for Touch 91
Conclusion 92
8. Accelerometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
What Is a Motion Sensor? 93
The Accelerometer Class 93
Visualizing the Values 95
A Simple Animation 95
Updates and Screen Rendering 96
Setting Boundaries 97
Rotating Toward the Center 98
Shake Me 99
Smoothing Out Values 100
Conclusion 102
9. Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
The Gallery Application and the CameraRoll Class 103
Selecting an Image 104
Adding an Image 109
The Camera Application and the CameraUI Class 109
Uploading to a Remote Server 111
EXIF Data 111
Conclusion 114
x | Table of Contents
Using GPS 119
Using the Cellular Network and WiFi 119
How to Know if GPS or WiFi Is Active 120
AIR and Android 121
Reverse Geocoding 122
Maps 124
Launching Google Maps 124
Static Maps 125
Dynamic Maps 129
EXIF Data and the Map Object 132
The speed Property 134
Conclusion 134
Table of Contents | xi
Resolution 163
Performance 164
Playing Video 164
Embedded Video 165
External Video 165
Progressive Video 165
RTMP Streaming 169
HTTP Dynamic Streaming 171
Peer-to-Peer Communication 171
Controls 171
YouTube 172
Capturing Video 172
Video and the CameraUI Class 172
The Camera Class 175
Documentation and Tutorials 176
Conclusion 176
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Table of Contents | xv