ebook img

Pro Android PDF

461 Pages·2010·3.25 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Pro Android

Pro Android Sayed Y. Hashimi and Satya Komatineni Pro Android Copyright © 2009 by Sayed Y. Hashimi and Satya Komatineni 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-1596-7 ISBN-13 (electronic): 978-1-4302-1597-4 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Java™ and all Java™-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement from Sun Microsystems, Inc. Lead Editor: Steve Anglin Development Editor: Douglas Pundick Technical Reviewer: Vikram Goyal Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Richard Dal Porto Copy Editor: Nina Goldschlager Perry Associate Production Director: Kari Brooks-Copony Production Editor: Candace English Compositor: Patrick Cunningham Proofreader: Lisa Hamilton Indexer: Ron Strauss Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail (cid:107)(cid:110)(cid:96)(cid:97)(cid:110)(cid:111)(cid:41)(cid:106)(cid:117)(cid:60)(cid:111)(cid:108)(cid:110)(cid:101)(cid:106)(cid:99)(cid:97)(cid:110)(cid:41)(cid:111)(cid:94)(cid:105)(cid:42)(cid:95)(cid:107)(cid:105), or visit (cid:100)(cid:112)(cid:112)(cid:108)(cid:54)(cid:43)(cid:43)(cid:115)(cid:115)(cid:115)(cid:42)(cid:111)(cid:108)(cid:110)(cid:101)(cid:106)(cid:99)(cid:97)(cid:110)(cid:107)(cid:106)(cid:104)(cid:101)(cid:106)(cid:97)(cid:42)(cid:95)(cid:107)(cid:105). For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail (cid:101)(cid:106)(cid:98)(cid:107)(cid:60)(cid:93)(cid:108)(cid:110)(cid:97)(cid:111)(cid:111)(cid:42)(cid:95)(cid:107)(cid:105), or visit (cid:100)(cid:112)(cid:112)(cid:108)(cid:54)(cid:43)(cid:43)(cid:115)(cid:115)(cid:115)(cid:42) (cid:93)(cid:108)(cid:110)(cid:97)(cid:111)(cid:111)(cid:42)(cid:95)(cid:107)(cid:105). 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 (cid:100)(cid:112)(cid:112)(cid:108)(cid:54)(cid:43)(cid:43)(cid:115)(cid:115)(cid:115)(cid:42)(cid:93)(cid:108)(cid:110)(cid:97)(cid:111)(cid:111)(cid:42)(cid:95)(cid:107)(cid:105)(cid:43)(cid:101)(cid:106)(cid:98)(cid:107)(cid:43)(cid:94)(cid:113)(cid:104)(cid:103)(cid:111)(cid:93)(cid:104)(cid:97)(cid:111). The information in this book is distributed on an “as is” basis, without warranty. Although every precau- tion 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 indi- rectly by the information contained in this work. The source code for this book is available to readers at (cid:100)(cid:112)(cid:112)(cid:108)(cid:54)(cid:43)(cid:43)(cid:115)(cid:115)(cid:115)(cid:42)(cid:93)(cid:108)(cid:110)(cid:97)(cid:111)(cid:111)(cid:42)(cid:95)(cid:107)(cid:105). To my son: Sayed-Adieb —Sayed Y. Hashimi To my family: Narayan Komatineni, Kavitha Komatineni, Nikolas Perez, Ashley Perez, and AnnMarie Komatineni —Satya Komatineni “This page left intentionally blank.” Contents at a Glance About the Authors ................................................................ xv About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Acknowledgments ................................................................xix Introduction .....................................................................xxi CHAPTER 1 Introducing the Android Computing Platform ......................1 CHAPTER 2 Getting Your Feet Wet ..........................................21 CHAPTER 3 Using Resources, Content Providers, and Intents .................43 CHAPTER 4 Building User Interfaces and Using Controls ....................107 CHAPTER 5 Working with Menus and Dialogs ..............................151 CHAPTER 6 Unveiling 2D Animation .......................................197 CHAPTER 7 Exploring Security and Location-Based Services ................225 CHAPTER 8 Building and Consuming Services ..............................263 CHAPTER 9 Using the Media Framework and Telephony APIs ...............301 CHAPTER 10 Programming 3D Graphics with OpenGL ........................325 CHAPTER 11 Managing and Organizing Preferences .........................363 CHAPTER 12 Coming to Grips with 1.5 ......................................377 CHAPTER 13 Simplifying OpenGL and Exploring Live Folders .................395 INDEX .......................................................................425 v “This page left intentionally blank.” Contents About the Authors ................................................................ xv About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Acknowledgments ................................................................xix Introduction .....................................................................xxi CHAPTER 1 Introducing the Android Computing Platform ..............1 History of Android ................................................3 Delving into the Dalvik VM .........................................4 Comparing Android and Java ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Understanding the Android Software Stack ..........................8 Developing an End-User Application with the Android SDK .............9 The Android Emulator ........................................9 The Android UI .............................................10 The Android Foundational Components ........................11 Advanced UI Concepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 Android Service Components .................................13 Android Media and Telephony Components ....................14 Android Java Packages ......................................15 Taking Advantage of Android Source Code ..........................18 Summary .......................................................19 CHAPTER 2 Getting Your Feet Wet .......................................21 Setting Up Your Environment ......................................21 Downloading JDK 6 and Eclipse 3.4 ...........................21 Downloading the Android SDK ................................22 Installing Android Development Tools (ADT) ....................22 Learning the Fundamental Components ............................24 View ......................................................24 Activity ....................................................24 Intent .....................................................24 Content Provider ............................................25 Service ....................................................25 AndroidManifest.xml ........................................25 vii viii (cid:78)CONTENTS Hello World! ....................................................25 Exploring the Structure of an Android Application ....................28 Analyzing the Notepad Application .................................30 Loading and Running the Notepad Application ..................31 Dissecting the Application ...................................31 Examining the Application Lifecycle ................................38 Debugging Your App .............................................41 Summary .......................................................42 CHAPTER 3 Using Resources, Content Providers, and Intents ........43 Understanding Resources ........................................43 String Resources ...........................................43 Layout Resources ...........................................45 Resource-Reference Syntax ..................................47 Defining Your Own Resource IDs for Later Use. . . . . . . . . . . . . . . . . .48 Compiled and Noncompiled Android Resources .................48 Enumerating Key Android Resources ..........................49 Working with Arbitrary XML Resource Files ....................57 Working with Raw Resources ................................58 Working with Assets ........................................59 Reviewing the Resources Directory Structure ...................60 Understanding Content Providers ..................................60 Exploring Android’s Built-in Providers .........................61 Architecture of Content Providers .............................67 Implementing Content Providers ..............................79 Understanding Intents ............................................91 Available Intents in Android ..................................92 Intents and Data URIs .......................................94 Generic Actions ............................................95 Using Extra Information ......................................96 Using Components to Directly Invoke an Activity ................97 Best Practice for Component Designers .......................99 Understanding Intent Categories ..............................99 The Rules for Resolving Intents to Their Components ...........102 Exercising the ACTION_PICK ................................102 Exercising the GET_CONTENT Action .........................104 Summary ......................................................106 (cid:78)CONTENTS ix CHAPTER 4 Building User Interfaces and Using Controls .............107 UI Development in Android .......................................107 Understanding Android’s Common Controls ........................113 Text Controls ..............................................113 Button Controls ............................................117 List Controls ..............................................122 Grid Controls ..............................................126 Date and Time Controls ....................................128 Other Interesting Controls in Android ..............................130 The MapView Control ......................................130 The Gallery Control ........................................130 Understanding Layout Managers .................................131 The LinearLayout Layout Manager ...........................131 The TableLayout Layout Manager ............................134 The RelativeLayout Layout Manager ..........................139 The AbsoluteLayout Layout Manager .........................141 The FrameLayout Layout Manager ...........................143 Customizing Layout for Various Screen Configurations ..........145 Understanding Adapters .........................................146 Getting to Know SimpleCursorAdapter ........................146 Getting to Know ArrayAdapter ...............................147 Creating Custom Adapters ..................................148 Debugging and Optimizing Layouts with the Hierarchy Viewer ........149 Summary ......................................................150 CHAPTER 5 Working with Menus and Dialogs .........................151 Understanding Android Menus ...................................151 Creating a Menu ..........................................153 Responding to Menu Items ..................................154 Creating a Test Harness for Testing Menus ...................156 Working with Other Menu Types ..................................163 Expanded Menus ..........................................163 Working with Icon Menus ...................................163 Working with Submenus ....................................164 Provisioning for System Menus .............................165 Working with Context Menus ................................165 Working with Alternative Menus .............................168 Working with Menus in Response to Changing Data ............172

Description:
Pro Android is the first book to include coverage of Google Android 1.5 SDK (including the branch formerly called Cupcake). This essential book covers the fundamentals of building applications for embedded devices thru through to advanced concepts, such as custom 3D components. Takes a pragmatic ap
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.