Apress Android Recipes, A Problem-Solution Approach (2011).pdf
(
8330 KB
)
Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Android Recipes
A Problem-Solution Approach
■ ■ ■
Dave Smith
Jeff Friesen
i
Android Recipes: A Problem-Solution Approach
Copyright © 2011 by Dave Smith and Jeff Friesen
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN-13 (pbk): 978-1-4302-3413-5
ISBN-13 (electronic): 978-1-4302-3414-2
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
President and Publisher: Paul Manning
Lead Editor: Tom Welsh
Technical Reviewer: Paul Connolly
Editorial Board:
Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan
Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Jeff Olson, Jeffrey
Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic
Shakeshaft, Matt Wade, Tom Welsh
Coordinating Editor: Corbin Collins
Copy Editor: Tracy Brown
Compositor: MacPS, LLC
Indexer: BIM Indexing & Proofreading Services
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com
, or visit
www.springeronline.com
.
For information on translations, please e-mail
rights@apress.com
, or visit
www.apress.com
.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/info/bulksales
.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at
www.apress.com
.
Contents
■
Chapter 1: Getting Started with Android ......................................................... 1
What Is Android?.......................................................................................................................................................1
History of Android .....................................................................................................................................................2
Android Architecture .................................................................................................................................................3
App Architecture .......................................................................................................................................................7
Components .........................................................................................................................................................7
Intents ..................................................................................................................................................................9
Manifest .............................................................................................................................................................11
App Package ......................................................................................................................................................13
Activities in Depth ...................................................................................................................................................13
Services in Depth ....................................................................................................................................................19
Broadcast Receivers in Depth. ...............................................................................................................................25
Content Providers in Depth . ...................................................................................................................................26
1–1. Installing the Android SDK . .......................................................................................................................27
1–2. Installing an Android Platform . .................................................................................................................30
1–3. Creating an Android Virtual Device . ..........................................................................................................34
1–4. Starting the AVD. .......................................................................................................................................36
1–5. Introducing UC . .........................................................................................................................................41
1–6. Creating UC ................................................................................................................................................53
1–7. Installing and Running UC. ........................................................................................................................55
1–8. Preparing UC for Publishing. .....................................................................................................................59
1–9. Migrating to Eclipse . .................................................................................................................................63
1–10. Developing UC with Eclipse . ...................................................................................................................66
Summary ................................................................................................................................................................72
■
Chapter 2: User Interface Recipes ................................................................. 75
2–1. Customizing the Window ......................................................................................................................... 75
2–2. Creating and Displaying Views ................................................................................................................ 83
2–3. Monitoring Click Actions .......................................................................................................................... 85
2–4. Resolution-Independent Assets ............................................................................................................... 86
2–5. Locking Activity Orientation ..................................................................................................................... 88
2–6. Dynamic Orientation Locking................................................................................................................... 89
2–7. Manually Handling Rotation ..................................................................................................................... 91
2–8. Creating Pop-Up Menu Actions ................................................................................................................ 93
2–9. Customizing Options Menu ...................................................................................................................... 98
2–10. Customizing Back Button..................................................................................................................... 101
2–11. Emulating the Home Button ................................................................................................................. 102
2–12. Monitoring TextView Changes ............................................................................................................. 103
2–13. Scrolling TextView Ticker .................................................................................................................... 106
2–14. Animating a View ................................................................................................................................. 107
2–15. Creating Drawables as Backgrounds................................................................................................... 115
2–16. Creating Custom State Drawables ....................................................................................................... 119
2–17. Applying Masks to Images................................................................................................................... 121
2–18. Creating Dialogs that Persist ............................................................................................................... 125
2–19. Implementing Situation-Specific Layouts ............................................................................................ 127
2–20. Customizing Keyboard Actions ............................................................................................................ 132
2–21. Dismissing Soft Keyboard.................................................................................................................... 135
2–22. Customizing AdapterView Empty Views .............................................................................................. 136
2–23. Customizing ListView Rows ................................................................................................................. 138
2–24. Making ListView Section Headers ....................................................................................................... 142
2–25. Creating Compound Controls ............................................................................................................... 145
Useful Tools to Know: DroidDraw ....................................................................................................................... 148
Obtaining and Launching DroidDraw ............................................................................................................. 149
Exploring DroidDraw’s User Interface............................................................................................................ 150
Creating a Simple Screen .............................................................................................................................. 151
Summary ............................................................................................................................................................ 153
Chapter 3: Communications and Networking.............................................. 155
3–1. Displaying Web Information................................................................................................................... 155
3–2. Intercepting WebView Events ................................................................................................................ 159
3–3. Accessing WebView with JavaScript ..................................................................................................... 161
3–4. Downloading an Image File ................................................................................................................... 163
3–5. Downloading Completely in the Background ......................................................................................... 166
3–6. Accessing a REST API ............................................................................................................................ 170
3–7. Parsing JSON ......................................................................................................................................... 176
3–8. Parsing XML........................................................................................................................................... 180
3–8. Receiving SMS ....................................................................................................................................... 184
3–9. Sending an SMS Message ..................................................................................................................... 186
3–10. Communicating over Bluetooth ........................................................................................................... 188
3–11. Querying Network Reachability ........................................................................................................... 197
Summary ............................................................................................................................................................ 198
■
■
Chapter 4: Interacting with Device Hardware and Media ........................... 201
4–1. Integrating Device Location ................................................................................................................... 201
4–2. Mapping Locations................................................................................................................................. 205
4–3. Annotating Maps.................................................................................................................................... 209
4–4. Capturing Images and Video .................................................................................................................. 216
4–5. Making a Custom Camera Overlay......................................................................................................... 221
4–6. Recording Audio..................................................................................................................................... 227
4–7. Adding Speech Recognition ................................................................................................................... 229
4–8. Playing Back Audio/Video ...................................................................................................................... 231
4–9. Creating a Tilt Monitor ........................................................................................................................... 240
4–10. Monitoring Compass Orientation ......................................................................................................... 243
Useful Tools to Know: SensorSimulator .............................................................................................................. 247
Obtaining Sensor Simulator ........................................................................................................................... 248
Launching Sensor Simulator Settings and Sensor Simulator ........................................................................ 248
Accessing Sensor Simulator from Your Apps ................................................................................................ 253
Summary ............................................................................................................................................................ 255
Chapter 5: Persisting Data .......................................................................... 257
5–1. Making a Preference Screen ................................................................................................................. 257
5–2. Persisting Simple Data .......................................................................................................................... 262
5–3. Reading and Writing Files ...................................................................................................................... 266
5–4. Using Files as Resources ....................................................................................................................... 271
5–5. Managing a Database ............................................................................................................................ 274
5–6. Querying a Database.............................................................................................................................. 279
5–7. Backing Up Data .................................................................................................................................... 281
5–8. Sharing Your Database .......................................................................................................................... 286
5–9. Sharing Your Other Data ........................................................................................................................ 292
Useful Tools to Know: SQLite3 ............................................................................................................................ 298
SQLite3 and UC .............................................................................................................................................. 300
Summary ............................................................................................................................................................ 308
■
Chapter 6: Interacting with the System ...................................................... 309
6–1. Notifying from the Background.............................................................................................................. 309
6–2. Creating Timed and Periodic Tasks ....................................................................................................... 313
6–3. Scheduling a Periodic Task ................................................................................................................... 315
6–4. Creating Sticky Operations .................................................................................................................... 319
6–5. Running Persistent Background Operations .......................................................................................... 324
6–6. Launching Other Applications ................................................................................................................ 330
6–7. Launching System Applications ............................................................................................................. 333
6–8. Letting Other Applications Launch Yours............................................................................................... 338
6–9. Interacting with Contacts....................................................................................................................... 340
6–10. Picking Device Media........................................................................................................................... 347
6–11. Saving to the MediaStore .................................................................................................................... 349
Summary ............................................................................................................................................................ 352
■
Chapter 7: Working with Libraries .............................................................. 353
7–1. Creating Java Library JARs.................................................................................................................... 353
7–2. Using Java Library JARs ........................................................................................................................ 356
7–3. Creating Android Library Projects .......................................................................................................... 359
7–4. Using Android Library Projects .............................................................................................................. 363
■
Plik z chomika:
krupix.one
Inne pliki z tego folderu:
Wei-Meng Lee-Android application development cookbook_ 93 recipes for building winning apps-Wrox (2013).pdf
(32748 KB)
Apress Android Apps for Absolute Beginners (2011).pdf
(69762 KB)
Apress Android Tablets Made Simple, For Motorola XOOM Samsung Galaxy Tab Asus Toshiba and Other Tablets (2011).pdf
(75353 KB)
Addison-Wesley Introduction to Android App Development for the Kindle Fire (2012).pdf
(13997 KB)
Addison-Wesley Learning Android Application Programming for the Kindle Fire (2012).pdf
(17766 KB)
Inne foldery tego chomika:
Android Application Development Video Guide Poradnik
Apple iOS 5 and 6 Development eBooks Collection [PDF]
ASP.NET eBooks Collection [PDF]
books
Complete IT Books Pack
Zgłoś jeśli
naruszono regulamin