logo资料库

Hello, Android: Introducing Googles Mobile Development Platform.pdf

第1页 / 共247页
第2页 / 共247页
第3页 / 共247页
第4页 / 共247页
第5页 / 共247页
第6页 / 共247页
第7页 / 共247页
第8页 / 共247页
资料共247页,剩余部分请下载后查看
Contents
Acknowledgments
Changes (Cupcake Updates)
P1.5---July 21
P1.4---July 6
P1.3---June 22
P1.2---June 9
P1.1---May 26
TODO in future releases
Preface
What Makes Android Special?
Who Should Read This Book?
What's in This Book?
FLAGCOLOR What's New for Cupcake?
Online Resources
Fast-Forward >>
Introducing Android
Quick Start
Installing the Tools
Creating Your First Program
Running on the Emulator
Running on a Real Phone
Fast-Forward >>
Key Concepts
The Big Picture
It's Alive!
Building Blocks
Using Resources
Safe and Secure
Fast-Forward >>
Android Basics
Designing the User Interface
Introducing the Sudoku Example
Designing by Declaration
Creating the Opening Screen
Using Alternate Resources
Implementing an About Box
Applying a Theme
Adding a Menu
Adding Settings
Starting a New Game
Debugging with Log Messages
Debugging with the Debugger
Exiting the Game
Fast-Forward >>
Exploring 2D Graphics
Learning the Basics
Adding Graphics to Sudoku
Handling Input
The Rest of the Story
Making More Improvements
Fast-Forward >>
Multimedia
Playing Audio
Playing Video
Adding Sounds to Sudoku
Fast-Forward >>
Storing Local Data
Adding Options to Sudoku
Continuing an Old Game
Remembering the Current Position
Accessing the Internal File System
Accessing SD Cards
Fast-Forward >>
Beyond the Basics
The Connected World
Browsing by Intent
Web with a View
From JavaScript to Java and Back
Using Web Services
Fast-Forward >>
Locating and Sensing
Location, Location, Location
Set Sensors to Maximum
Bird's-Eye View
Fast-Forward >>
Putting SQL to Work
Introducing SQLite
SQL 101
Hello, Database
Data Binding
Using a ContentProvider
Implementing a ContentProvider
Fast-Forward >>
3D Graphics in OpenGL
Understanding 3D Graphics
Introducing OpenGL
Building an OpenGL Program
Managing Threads
Building a Model
Lights, Camera, ...
Action!
Applying Texture
Peekaboo
Fast-Forward >>
Appendixes
Java vs. the Android Language and APIs
Language Subset
Standard Library Subset
Third-Party Libraries
Hello, Widget
Creating Your First Widget
Calling All Widgets!
Stretch to Fit
The Rest of the Story
Running the Widget
Keeping Up to Date
Go Wild
Publishing to the Android Market
Bibliography
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
Prepared exclusively for Trieu Nguyen
What readers are saying about Hello, Android This is a most excellent book: very well written, easy to read, and fun. In addition, any of Android’s quirks are explained along with just the right amount of detail to ensure quality programming principles are followed. Anthony Stevens Founder and CTO, PocketJourney and Top 20 Winner of Google Android Competition Ed Burnette covers an impressive amount of ground in a nicely com- pact book while retaining the popular Pragmatic style. For the mate- rial on 2D and 3D graphics alone, this is worthy of a spot in any Android developer’s library. Mark Murphy Founder, CommonsWare I remember when I first started to work with Android; it was like a huge maze. With this book, the introduction would have been much less painful. I am convinced that by reading this book new Android programmers will have an easier start. Gabor Paller Senior Software Architect, OnRelay, Ltd. Prepared exclusively for Trieu Nguyen Download at Boykma.Com
Hello, Android Introducing Google’s Mobile Development Platform Ed Burnette The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Prepared exclusively for Trieu Nguyen Download at Boykma.Com
Many of the designations used by manufacturers and sellers to distinguish their prod- ucts are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Portions of the book’s cover are reproduced from work created and shared by Google and used according to terms described in the Creative Commons 2.5 Attribution License. See http://code.google.com/policies.html#restrictions for details. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://www.pragprog.com Copyright © 2008 Ed Burnette. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-10: 1-934356-17-4 ISBN-13: 978-1-934356-17-3 Printed on acid-free paper. P1.5 printing, July 21, 2009 Version: 2009-7-21 Prepared exclusively for Trieu Nguyen Download at Boykma.Com
Contents Acknowledgments Changes (Cupcake Updates) P1.5—July 21 . . . . . . . . . . . . . . . . . . . . . . . . . . . . P1.4—July 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . P1.3—June 22 . . . . . . . . . . . . . . . . . . . . . . . . . . . . P1.2—June 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . P1.1—May 26 . . . . . . . . . . . . . . . . . . . . . . . . . . . . TODO in future releases . . . . . . . . . . . . . . . . . . . . . . Preface What Makes Android Special? . . . . . . . . . . . . . . . . . . . Who Should Read This Book? . . . . . . . . . . . . . . . . . . . What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . What’s New for Cupcake? . . . . . . . . . . . . . . . . . . . . . Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . . . . . I Introducing Android 1 Quick Start 1.1 1.2 1.3 1.4 1.5 Installing the Tools . . . . . . . . . . . . . . . . . . . . . Creating Your First Program . . . . . . . . . . . . . . . . Running on the Emulator . . . . . . . . . . . . . . . . . Running on a Real Phone . . . . . . . . . . . . . . . . . Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 2 Key Concepts 2.1 2.2 2.3 2.4 The Big Picture . . . . . . . . . . . . . . . . . . . . . . . It’s Alive! . . . . . . . . . . . . . . . . . . . . . . . . . . . Building Blocks . . . . . . . . . . . . . . . . . . . . . . . Using Resources . . . . . . . . . . . . . . . . . . . . . . . 10 11 11 11 12 12 12 13 14 14 15 16 16 17 17 19 20 20 24 24 29 29 30 30 35 39 40 Prepared exclusively for Trieu Nguyen Download at Boykma.Com
2.5 2.6 Safe and Secure . . . . . . . . . . . . . . . . . . . . . . . Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 41 42 CONTENTS 6 Prepared exclusively for Trieu Nguyen this copy is (P1.5 printing, July 21, 2009) Report erratum Download at Boykma.Com
CONTENTS 7 II Android Basics 3 Designing the User Interface Introducing the Sudoku Example . . . . . . . . . . . . . 3.1 Designing by Declaration . . . . . . . . . . . . . . . . . . 3.2 Creating the Opening Screen . . . . . . . . . . . . . . . 3.3 Using Alternate Resources . . . . . . . . . . . . . . . . . 3.4 Implementing an About Box . . . . . . . . . . . . . . . . 3.5 Applying a Theme . . . . . . . . . . . . . . . . . . . . . . 3.6 Adding a Menu . . . . . . . . . . . . . . . . . . . . . . . 3.7 Adding Settings . . . . . . . . . . . . . . . . . . . . . . . 3.8 3.9 Starting a New Game . . . . . . . . . . . . . . . . . . . . 3.10 Debugging with Log Messages . . . . . . . . . . . . . . . 3.11 Debugging with the Debugger . . . . . . . . . . . . . . . 3.12 Exiting the Game . . . . . . . . . . . . . . . . . . . . . . 3.13 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 43 44 44 45 46 54 58 62 63 66 68 70 71 71 72 4 Exploring 2D Graphics Learning the Basics . . . . . . . . . . . . . . . . . . . . . Adding Graphics to Sudoku . . . . . . . . . . . . . . . . Handling Input . . . . . . . . . . . . . . . . . . . . . . . The Rest of the Story . . . . . . . . . . . . . . . . . . . . 73 73 4.1 78 4.2 87 4.3 93 4.4 4.5 Making More Improvements . . . . . . . . . . . . . . . . 102 4.6 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 103 5 Multimedia 104 Playing Audio . . . . . . . . . . . . . . . . . . . . . . . . 104 Playing Video . . . . . . . . . . . . . . . . . . . . . . . . . 110 Adding Sounds to Sudoku . . . . . . . . . . . . . . . . . 115 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 118 5.1 5.2 5.3 5.4 6.1 6.2 6.3 6.4 6.5 6.6 6 Storing Local Data 119 Adding Options to Sudoku . . . . . . . . . . . . . . . . . 119 Continuing an Old Game . . . . . . . . . . . . . . . . . . 121 Remembering the Current Position . . . . . . . . . . . . 123 Accessing the Internal File System . . . . . . . . . . . . 125 Accessing SD Cards . . . . . . . . . . . . . . . . . . . . . 126 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 127 Prepared exclusively for Trieu Nguyen this copy is (P1.5 printing, July 21, 2009) Report erratum Download at Boykma.Com
III Beyond the Basics 128 CONTENTS 8 7 The Connected World Browsing by Intent 129 7.1 . . . . . . . . . . . . . . . . . . . . . 130 7.2 Web with a View . . . . . . . . . . . . . . . . . . . . . . . 134 From JavaScript to Java and Back . . . . . . . . . . . . 139 7.3 7.4 Using Web Services . . . . . . . . . . . . . . . . . . . . . 146 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 156 7.5 8 Locating and Sensing 158 Location, Location, Location . . . . . . . . . . . . . . . . 158 Set Sensors to Maximum . . . . . . . . . . . . . . . . . . 164 Bird’s-Eye View . . . . . . . . . . . . . . . . . . . . . . . 168 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 173 8.1 8.2 8.3 8.4 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9 Putting SQL to Work 175 Introducing SQLite . . . . . . . . . . . . . . . . . . . . . 175 SQL 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Hello, Database . . . . . . . . . . . . . . . . . . . . . . . 178 Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . 186 Using a ContentProvider . . . . . . . . . . . . . . . . . . 189 Implementing a ContentProvider . . . . . . . . . . . . . 192 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 193 10 3D Graphics in OpenGL 195 10.1 Understanding 3D Graphics . . . . . . . . . . . . . . . . 195 10.2 Introducing OpenGL . . . . . . . . . . . . . . . . . . . . 196 10.3 Building an OpenGL Program . . . . . . . . . . . . . . . 197 . . . . . . . . . . . . . . . . . . . . . 199 10.4 Managing Threads 10.5 Building a Model . . . . . . . . . . . . . . . . . . . . . . 205 10.6 Lights, Camera, ... . . . . . . . . . . . . . . . . . . . . . . 208 10.7 Action! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 10.8 Applying Texture . . . . . . . . . . . . . . . . . . . . . . 213 10.9 Peekaboo . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 10.10 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 217 Prepared exclusively for Trieu Nguyen this copy is (P1.5 printing, July 21, 2009) Report erratum Download at Boykma.Com
分享到:
收藏