737
Android 2 Covers Google’s Android 2 Platform including advanced topics such as OpenGL, Widgets, Text to Speech, Multi-Touch, and Titanium Mobile Sayed Hashimi | Satya Komatineni | Dave MacLean Pro Android 2

Pro android 2

Embed Size (px)

DESCRIPTION

 

Citation preview

  • 1. Covers Googles Android 2 Platform including advanced topics such as OpenGL, Widgets, Text to Speech,Multi-Touch, and Titanium MobileProAndroid 2Sayed Hashimi | Satya Komatineni | Dave MacLean

2. This book was purchased by [email protected] 3. Pro Android 2Sayed Y. HashimiSatya KomatineniDave MacLean i 4. Pro Android 2 Copyright 2010 by Sayed Y. Hashimi, Satya Komatineni, and Dave MacLean 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-2659-8 ISBN-13 (electronic): 978-1-4302-2660-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. President and Publisher: Paul Manning Lead Editor: Steve Anglin Development Editor: Douglas Pundick Technical Reviewer: Vikram Goyal Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Fran Parnell Copy Editor: Elizabeth Berry Compositor: MacPS, LLC Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko 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 orders- [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], 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 SaleseBook 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. You will need to answer questions pertaining to this book in order to successfully download the code.ii 5. To my son, Sayed-Adieb. Sayed Y. HashimiTo my beautiful wife, AnnMarie, for her spirit; to Ashley, for her undaunting hope; to Nikolas, forhis kindness; to Kavitha, for being smart, witty, and fabulous; to Narayan, for sheer cuteness; and to all my extended family in India and the USA for their love. Satya Komatineni To my wife, Rosie, and my son, Mike, for their support; I couldnt have done this without them.And to Max, for spending so much time at my feet keeping me company.Dave MacLeaniii 6. Contents at a Glance Contents at a Glance ...................................................................................................iv Contents.......................................................................................................................v About the Authors.....................................................................................................xiii About the Technical Reviewer ..................................................................................xiv Acknowledgments .....................................................................................................xv Foreword...................................................................................................................xvi Chapter 1: Introducing the Android Computing Platform ........................................... 1 Chapter 2: Getting Your Feet Wet.............................................................................. 25 Chapter 3: Using Resources, Content Providers, and Intents ................................... 57 Chapter 4: Building User Interfaces and Using Controls......................................... 123 Chapter 5: Working with Menus and Dialogs.......................................................... 171 Chapter 6: Unveiling 2D Animation ......................................................................... 217 Chapter 7: Exploring Security and Location-Based Services.................................. 243 Chapter 8: Building and Consuming Services......................................................... 289 Chapter 9: Using the Media Framework and Telephony APIs................................. 327 Chapter 10: Programming 3D Graphics with OpenGL ............................................. 363 Chapter 11: Managing and Organizing Preferences ............................................... 421 Chapter 12: Exploring Live Folders ......................................................................... 439 Chapter 13: Home Screen Widgets ......................................................................... 457 Chapter 14: Android Search.................................................................................... 491 Chapter 15: Exploring Text to Speech and Translate APIs...................................... 563 Chapter 16: Touchscreens ...................................................................................... 591 Chapter 17: Titanium Mobile: A WebKit-Based Approach to AndroidDevelopment ....................................................................................... 627 Chapter 18: Working with Android Market ............................................................. 661 Chapter 19: Outlook and Resources ....................................................................... 675 Index ....................................................................................................................... 687iv 7. ContentsContents at a Glance....................................................................................... ivContents .......................................................................................................... vAbout the Authors ........................................................................................ xiiiAbout the Technical Reviewer.......................................................................xivAcknowledgments..........................................................................................xvForeword .......................................................................................................xviChapter 1: Introducing the Android Computing Platform................................ 1 A New Platform for a New Personal Computer .......................................................................................................1 History of Android ...................................................................................................................................................3 Delving into the Dalvik VM ......................................................................................................................................5 Comparing Android and Java ME............................................................................................................................7 Understanding the Android Software Stack..........................................................................................................10 Developing an End-User Application with the Android SDK..................................................................................11Android Emulator .............................................................................................................................................11The Android UI .................................................................................................................................................12The Android Foundational Components ...........................................................................................................13Advanced UI Concepts .....................................................................................................................................14Android Service Components...........................................................................................................................16Android Media and Telephony Components ....................................................................................................16Android Java Packages....................................................................................................................................18 Taking Advantage of Android Source Code...........................................................................................................23 Summary ..............................................................................................................................................................24Chapter 2: Getting Your Feet Wet .................................................................. 25 Setting Up Your Environment................................................................................................................................25Downloading JDK 6..........................................................................................................................................26Downloading Eclipse 3.5..................................................................................................................................26Downloading the Android SDK .........................................................................................................................27v 8. CONTENTSInstalling Android Development Tools (ADT)....................................................................................................28 Learning the Fundamental Components...............................................................................................................31View .................................................................................................................................................................31Activity .............................................................................................................................................................31Intent................................................................................................................................................................31Content Provider ..............................................................................................................................................32Service .............................................................................................................................................................32AndroidManifest.xml........................................................................................................................................32Android Virtual Devices....................................................................................................................................32 Hello World! ..........................................................................................................................................................33 Android Virtual Devices.........................................................................................................................................38 Exploring the Structure of an Android Application................................................................................................40 Analyzing the Notepad Application .......................................................................................................................42Loading and Running the Notepad Application................................................................................................43Dissecting the Application ...............................................................................................................................44 Examining the Application Lifecycle .....................................................................................................................51 Debugging Your App .............................................................................................................................................54 Summary ..............................................................................................................................................................55Chapter 3: Using Resources, Content Providers, and Intents........................ 57 Understanding Resources.....................................................................................................................................58String Resources..............................................................................................................................................59Layout Resources ............................................................................................................................................60Resource-Reference Syntax ............................................................................................................................62Defining Your Own Resource IDs for Later Use................................................................................................63Compiled and Noncompiled Android Resources..............................................................................................64Enumerating Key Android Resources...............................................................................................................65Working with Arbitrary XML Resource Files ....................................................................................................73Working with Raw Resources ..........................................................................................................................74Working with Assets ........................................................................................................................................75Reviewing the Resources Directory Structure .................................................................................................75 Understanding Content Providers .........................................................................................................................76Exploring Androids Built-in Providers .............................................................................................................77Architecture of Content Providers....................................................................................................................83Implementing Content Providers .....................................................................................................................95 Understanding Intents.........................................................................................................................................106Available Intents in Android ...........................................................................................................................107Intents and Data URIs ....................................................................................................................................109Generic Actions..............................................................................................................................................110Using Extra Information .................................................................................................................................111Using Components to Directly Invoke an Activity ..........................................................................................113Best Practice for Component Designers ........................................................................................................114Understanding Intent Categories ...................................................................................................................114The Rules for Resolving Intents to Their Components ...................................................................................117Exercising the ACTION_PICK ..........................................................................................................................117Exercising the GET_CONTENT Action.............................................................................................................119 Further Resources for This Chapter....................................................................................................................121 Summary ............................................................................................................................................................121vi 9. CONTENTSChapter 4: Building User Interfaces and Using Controls ............................. 123UI Development in Android .................................................................................................................................123Understanding Androids Common Controls .......................................................................................................129 Text Controls..................................................................................................................................................129 Button Controls ..............................................................................................................................................133 List Controls ...................................................................................................................................................139 Grid Controls ..................................................................................................................................................143 Date and Time Controls .................................................................................................................................145Other Interesting Controls in Android..................................................................................................................147 The MapView Control.....................................................................................................................................148 The Gallery Control.........................................................................................................................................148 The Spinner Control .......................................................................................................................................148Understanding Layout Managers ........................................................................................................................149 The LinearLayout Layout Manager.................................................................................................................149 The TableLayout Layout Manager..................................................................................................................153 The RelativeLayout Layout Manager..............................................................................................................157 The FrameLayout Layout Manager ................................................................................................................159 Customizing Layout for Various Device Configurations .................................................................................162Understanding Adapters .....................................................................................................................................164 Getting to Know SimpleCursorAdapter ..........................................................................................................165 Getting to Know ArrayAdapter .......................................................................................................................165 Creating Custom Adapters .............................................................................................................................166Debugging and Optimizing Layouts with the Hierarchy Viewer..........................................................................167Summary ............................................................................................................................................................170Chapter 5: Working with Menus and Dialogs .............................................. 171Understanding Android Menus ...........................................................................................................................171 Creating a Menu.............................................................................................................................................173 Working with Menu Groups ...........................................................................................................................174 Responding to Menu Items ............................................................................................................................175 Creating a Test Harness for Testing Menus...................................................................................................176Working with Other Menu Types.........................................................................................................................183 Expanded Menus ...........................................................................................................................................183 Working with Icon Menus ..............................................................................................................................183 Working with Submenus................................................................................................................................184 Provisioning for System Menus .....................................................................................................................185 Working with Context Menus.........................................................................................................................185 Working with Alternative Menus....................................................................................................................188 Working with Menus in Response to Changing Data .....................................................................................192Loading Menus Through XML Files.....................................................................................................................192 Structure of an XML Menu Resource File ......................................................................................................193 Inflating XML Menu Resource Files ...............................................................................................................193 Responding to XML-Based Menu Items.........................................................................................................194 A Brief Introduction to Additional XML Menu Tags ........................................................................................195Using Dialogs in Android.....................................................................................................................................196 Designing an Alert Dialog ..............................................................................................................................197 Designing a Prompt Dialog ............................................................................................................................199 The Nature of Dialogs in Android ...................................................................................................................204 vii 10. CONTENTS Rearchitecting the Prompt Dialog ..................................................................................................................205 Working with Managed Dialogs ..........................................................................................................................206 Understanding the Managed-Dialog Protocol ................................................................................................206 Recasting the Non-Managed Dialog As a Managed Dialog............................................................................206 Simplifying the Managed-Dialog Protocol .....................................................................................................208 Summary ............................................................................................................................................................215Chapter 6: Unveiling 2D Animation.............................................................. 217 Frame-by-Frame Animation................................................................................................................................218Planning for Frame-by-Frame Animation ......................................................................................................218Creating the Activity.......................................................................................................................................219Adding Animation to the Activity....................................................................................................................220 Layout Animation ................................................................................................................................................223Basic Tweening Animation Types ..................................................................................................................224Planning the Layout-Animation Test Harness................................................................................................225Creating the Activity and the ListView ...........................................................................................................226Animating the ListView ..................................................................................................................................228Using Interpolators.........................................................................................................................................231 View Animation ...................................................................................................................................................233Understanding View Animation......................................................................................................................233Adding Animation...........................................................................................................................................236Using Camera to Provide Depth Perception in 2D..........................................................................................239Exploring the AnimationListener Class ..........................................................................................................240Some Notes on Transformation Matrices ......................................................................................................241 Summary ............................................................................................................................................................242Chapter 7: Exploring Security and Location-Based Services ...................... 243 Understanding the Android Security Model ........................................................................................................243Overview of Security Concepts ......................................................................................................................244Signing Applications for Deployment.............................................................................................................244 Performing Runtime Security Checks .................................................................................................................249Understanding Security at the Process Boundary .........................................................................................249Declaring and Using Permissions ..................................................................................................................250Understanding and Using Custom Permissions .............................................................................................252Understanding and Using URI Permissions....................................................................................................258 Working with Location-Based Services ..............................................................................................................258Understanding the Mapping Package............................................................................................................259Understanding the Location Package ............................................................................................................270 Summary ............................................................................................................................................................287Chapter 8: Building and Consuming Services ............................................. 289 Consuming HTTP Services ..................................................................................................................................289Using the HttpClient for HTTP GET Requests .................................................................................................290Using the HttpClient for HTTP POST Requests ...............................................................................................291Dealing with Exceptions.................................................................................................................................295Addressing Multithreading Issues .................................................................................................................297 Doing Interprocess Communication....................................................................................................................301Creating a Simple Service..............................................................................................................................301Understanding Services in Android................................................................................................................302Understanding Local Services .......................................................................................................................303viii 11. CONTENTSUnderstanding AIDL Services.........................................................................................................................307Defining a Service Interface in AIDL ..............................................................................................................308Implementing an AIDL Interface ....................................................................................................................310Calling the Service from a Client Application.................................................................................................312Passing Complex Types to Services ..............................................................................................................316Summary ............................................................................................................................................................326Chapter 9: Using the Media Framework and Telephony APIs ..................... 327Using the Media APIs ..........................................................................................................................................327 Playing Audio Content....................................................................................................................................331 Understanding the setDataSource Method ....................................................................................................335 Playing Video Content ....................................................................................................................................336 Understanding the MediaPlayer Oddities.......................................................................................................338 Exploring Audio Recording.............................................................................................................................339 Exploring Video Recording .............................................................................................................................343 Exploring the MediaStore Class .....................................................................................................................348 Adding Media Content to the Media Store .....................................................................................................352Using the Telephony APIs ...................................................................................................................................354 Working with SMS .........................................................................................................................................354 Working with the Telephony Manager ...........................................................................................................361Summary ............................................................................................................................................................362Chapter 10: Programming 3D Graphics with OpenGL.................................. 363Understanding the History and Background of OpenGL......................................................................................364 OpenGL ES .....................................................................................................................................................365 OpenGL ES and Java ME................................................................................................................................366 M3G: Another Java ME 3D Graphics Standard...............................................................................................367Fundamentals of OpenGL....................................................................................................................................367 Essential Drawing with OpenGL ES................................................................................................................368 Understanding OpenGL Camera and Coordinates..........................................................................................374Interfacing OpenGL ES with Android...................................................................................................................378 Using GLSurfaceView and Related Classes ...................................................................................................379 Simple Test Harness That Draws a Triangle..................................................................................................380 Changing Camera Settings ............................................................................................................................384 Using Indices to Add Another Triangle...........................................................................................................386 Animating the Simple OpenGL Triangle .........................................................................................................387Braving OpenGL: Shapes and Textures...............................................................................................................390 A Simple Menu Trick for Your Demos ............................................................................................................391 Drawing a Rectangle......................................................................................................................................395 Working with Shapes.....................................................................................................................................397 Working with Textures...................................................................................................................................410 Drawing Multiple Figures...............................................................................................................................415 OpenGL Resources.........................................................................................................................................419Summary ............................................................................................................................................................419Chapter 11: Managing and Organizing Preferences.................................... 421Exploring the Preferences Framework ...............................................................................................................421 Understanding ListPreference .......................................................................................................................422 Manipulating Preferences Programmatically.................................................................................................429 Understanding CheckBoxPreference .............................................................................................................430ix 12. CONTENTS Understanding EditTextPreference ................................................................................................................432 Understanding RingtonePreference...............................................................................................................433Organizing Preferences ......................................................................................................................................435Summary ............................................................................................................................................................438 Chapter 12: Exploring Live Folders.............................................................. 439Exploring Live Folders.........................................................................................................................................439 How a User Experiences Live Folders............................................................................................................440 Building a Live Folder ....................................................................................................................................445Summary ............................................................................................................................................................456 Chapter 13: Home Screen Widgets .............................................................. 457Architecture of Home Screen Widgets................................................................................................................458 What Are Home Screen Widgets? ..................................................................................................................458 User Experience with Home Screen Widgets.................................................................................................459 Lifecycle of a Widget......................................................................................................................................462A Sample Widget Application..............................................................................................................................468 Defining the Widget Provider .........................................................................................................................470 Defining Widget Size......................................................................................................................................471This book was purchased by [email protected] Widget Layout-Related Files ..........................................................................................................................472 Implementing a Widget Provider....................................................................................................................474 Implementing Widget Models ........................................................................................................................476 Implementing Widget Configuration Activity..................................................................................................483Widget Limitations and Extensions.....................................................................................................................487Resources ...........................................................................................................................................................488Summary ............................................................................................................................................................489 Chapter 14: Android Search ........................................................................ 491Android Search Experience.................................................................................................................................492 Exploring Android Global Search ...................................................................................................................492 Enabling Suggestion Providers for Global Search..........................................................................................497 QSB and Suggestions Provider Interaction ....................................................................................................500Activities and Search Key Interaction .................................................................................................................502 Behavior of Search Key on a Regular Activity................................................................................................503 Behavior of an Activity That Disables Search ................................................................................................510 Invoking Search Through a Menu ..................................................................................................................511 Understanding Local Search and Related Activities ......................................................................................514 Enabling Type-to-Search ...............................................................................................................................519Implementing a Simple Suggestion Provider......................................................................................................520 Planning the Simple Suggestions Provider....................................................................................................520 Simple Suggestions Provider Implementation Files ......................................................................................521 Implementing the SimpleSuggestionProvider class ......................................................................................521 Understanding Simple Suggestions Provider Search Activity........................................................................525 Search Invoker Activity ..................................................................................................................................529 Simple Suggestion Provider User Experience................................................................................................531Implementing a Custom Suggestion Provider.....................................................................................................535 Planning the Custom Suggestion Provider.....................................................................................................535 SuggestURLProvider Project Implementation Files........................................................................................536 Implementing the SuggestUrlProvider Class .................................................................................................536 Implementing a Search Activity for a Custom Suggestion Provider ..............................................................545 x 13. CONTENTS Custom Suggestions Provider Manifest File ..................................................................................................551 Custom Suggestion User Experience.............................................................................................................552Using Action Keys and Application-Specific Search Data...................................................................................556 Using Action Keys in Android Search.............................................................................................................557 Working with Application-Specific Search Context .......................................................................................559Resources ...........................................................................................................................................................561Summary ............................................................................................................................................................562Chapter 15: Exploring Text to Speech and Translate APIs .......................... 563The Basics of Text to Speech in Android ............................................................................................................563Using Utterances to Keep Track of Our Speech ..................................................................................................568Using Audio Files for Your Voice .........................................................................................................................569Advanced Features of the TTS Engine ................................................................................................................576 Setting Audio Streams ...................................................................................................................................576 Using Earcons ................................................................................................................................................577 Playing Silence ..............................................................................................................................................577 Using Language Methods ..............................................................................................................................578Translating Text to a Different Language............................................................................................................579Summary ............................................................................................................................................................588Chapter 16: Touchscreens........................................................................... 591Understanding MotionEvents ..............................................................................................................................591 Using VelocityTracker ....................................................................................................................................603 Exploring Drag and Drop................................................................................................................................605Multi-Touch.........................................................................................................................................................608Touches with Maps.............................................................................................................................................615Gestures..............................................................................................................................................................618Summary ............................................................................................................................................................625Chapter 17: Titanium Mobile: A WebKit-Based Approach to Android Development .......................................................... 627Titanium Mobile Overview ..................................................................................................................................628Architecture ...................................................................................................................................................629The Titanium Ecosystem................................................................................................................................632Downloading and Installing Titanium Developer ...........................................................................................633Getting to Know the Ropes: The First Project .....................................................................................................640Creating a Titanium Mobile Project................................................................................................................640Crafting Hello World ...................................................................................................................................642Provisioning the Application for Debugging...................................................................................................644Packaging the Application .............................................................................................................................647Installing the .apk File on Your Own Emulator...............................................................................................649Planning for Real-World Applications .................................................................................................................650Essential Primer on JQuery............................................................................................................................651Essential Primer on Advanced JavaScript .....................................................................................................653Understanding the Microtemplating Engine ..................................................................................................656Additional Titanium Mobile APIs ....................................................................................................................659Summary ............................................................................................................................................................660Chapter 18: Working with Android Market.................................................. 661Becoming a Publisher .........................................................................................................................................661Following the Rules .......................................................................................................................................662xi 14. CONTENTSDeveloper Console .........................................................................................................................................665 Preparing Your Application for Sale....................................................................................................................666Testing for Different Devices .........................................................................................................................666Supporting Different Screen Sizes.................................................................................................................666Preparing AndroidManifest.xml for Uploading ...............................................................................................667Localizing Your Application............................................................................................................................667Preparing Your Application Icon.....................................................................................................................668Considerations for Paid Apps.........................................................................................................................668Directing Users Back to the Market ...............................................................................................................669Preparing Your .apk File for Uploading ..........................................................................................................669 Uploading Your Application.................................................................................................................................670 User Experience on Android Market ...................................................................................................................672 Summary ............................................................................................................................................................674Chapter 19: Outlook and Resources ............................................................ 675 Current State of Android .....................................................................................................................................675Android Based Mobile Device Manufacturers................................................................................................676Android Application Stores ............................................................................................................................677 Outlook For Android ............................................................................................................................................679Quick Summary of Mobile Operating Systems ..............................................................................................679Contrasting Android with other Mobile OSs...................................................................................................681Support for HTML 5 and What it Reveals .......................................................................................................682 Android Resources..............................................................................................................................................683Core Android Resources ................................................................................................................................683Android News Related Resources..................................................................................................................684 Summary ............................................................................................................................................................685Index............................................................................................................ 687xii 15. About the AuthorsSayed Y. Hashimi was born in Afghanistan and now resides in Jacksonville,Florida. His expertise spans the fields of health care, financials, logistics, andservice-oriented architecture. In his professional career, Sayed has developedlarge-scale distributed applications with a variety of programming languagesand platforms, including C/C++, MFC, J2EE, and .NET. He has publishedarticles in major software journals and has written several other popularApress titles. Sayed holds a masters degree in engineering from theUniversity of Florida. You can reach Sayed by visiting www.sayedhashimi.com. Satya Komatineni (www.satyakomatineni.com) has over 20 years of programming experience working with small and large corporations. Satya has published over 30 articles around web development using Java, .NET, and database technologies. He is a frequent speaker at industry conferences on innovative technologies and a regular contributor to the weblogs on java.net. He is the author of AspireWeb (www.activeintellect.com/aspire), a simplified open source tool for Java web development, and the creator of Aspire Knowledge Central (www.knowledgefolders.com), an open source personal Web OS with a focus on individual productivity and publishing. Satya is also a contributing member to a number of Small BusinessInnovation Research Programs (SBIR). He received a bachelors degree in Electrical Engineeringfrom Andhra University, Visakhapatnam, and a masters degree in Electrical Engineering fromthe Indian Institute of Technology, New Delhi.Dave MacLean is a software engineer and architect currently living andworking in Jacksonville, Florida. Since 1980, he has programmed in manylanguages, developing systems ranging from robot automation systems todata warehousing, web self-service applications to EDI transactionprocessors. Dave has worked for Sun Microsystems, IBM, TrimbleNavigation, General Motors, and several small companies. He graduatedfrom the University of Waterloo in Canada with a degree in Systems DesignEngineering. Please visit us at our website http://www.androidbook.com. xiii 16. About the TechnicalReviewerVikram Goyal is a software developer living in Brisbane, Australia who hastaken some time off to enjoy life with his kids. You can contact him [email protected] 17. AcknowledgmentsWriting this book took effort not only on the part of the authors, but also from some of the verytalented staff at Apress, as well as the technical reviewer. Therefore, we would like to thank SteveAnglin, Douglas Pundick, Fran Parnell, Elizabeth Berry, and Brigid Duffy from Apress. We wouldalso like to extend our appreciation to the technical reviewer, Vikram Goyal, for the work he didon the book. His commentary and corrections were invaluable. Finally, the authors are deeplygrateful to their families for accommodating prolonged irresponsibility. xv 18. ForewordThink. Code. Write. Rinse and repeat ad infinitum. This is the mantra of a technical writer.Technology changes so quickly that by the time an author has finished the last sentence, it is timeto rewrite it. As a technical reader, you are probably well aware of this fact, and yet you have takenthe time to purchase this book and read it. Not only that, but you are even taking the time to readthis foreword. This means you are not just a fly-by-night coder, but somebody who wants toknow the technology behind the technology. Well done, and congratulations on making thisinvestment. Let me validate your decision to buy this book.This is the best book on the market for learning about Android. It has so many chapters crammedwith Android goodness that you will thank yourself many times over for making the decision tobuy it. I am the technical reviewer of this book and, frankly, I wish there had been more for me toeditthe authors did such a good job, I was left with hardly anything to correct. (I did, however,curse them several times for the volume of content they managed to fit in a single book, whichincreased my workload several times over, right up to the last minute.) But my loss is your gain:this book covers everything you could possibly need to know about Android. Just take a look atthe table of contents.Tradition requires that I talk a little about Android itself, the subject of this book. Of course youprobably already know something about Androidthe operating system from Google that Googlehopes will rival iPhone for market dominationwhich is why you are holding this book in yourhands. Android, as a technology, has matured beyond its initial stab in the dark and now, with therecent announcement of NexusOne, the Android-based phone from Google, it is a force tocontend with. The year 2010 will be the year of the dogfight between Google and Apple for mobilephone domination. There is room for both technologies to co-exist, but with Googles massivepresence on the Web, people at Apple will be on edge.With the massive market for Android in mind, you have taken the first two steps: a) You havechosen to develop for Android, and b) You have chosen the best book on the market to learnabout Android. Now take the final step: turn the page and begin to cram your mind full ofAndroid goodness. Vikram Goyal [email protected] January 2010Brisbane, Australiaxvi 19. 1 Chapter1Introducing the AndroidComputing PlatformComputing continues to become more personal, increasingly accessible anytime,anywhere. At the forefront of this development are handheld devices that aretransforming into computing platforms. Mobile phones are no longer just for talkingthey have been capable of carrying data and video for some time. Significantly, themobile device is becoming so capable of general-purpose computing that its destinedto become the next PC (Personal Computer). It is also anticipated that even a number oftraditional PC manufacturers such as ASUS, HP, and Dell will be producing devices ofvarious form factors based on the Android OS. The battle lines between operatingsystems, computing platforms, programming languages, and development frameworksare being shifted and reapplied to mobile devices.We are also expecting a surge in mobile programming in the IT industry as more andmore IT applications start to offer mobile counterparts. To help you profit from this trend,well show you how to use Java to write programs for devices that run on GooglesAndroid Platform (http://developer.android.com/index.html), an open source platformfor mobile development. We are excited about Android because it is an advancedplatform that introduces a number of new paradigms in framework design (even with thelimitations of a mobile platform).In this chapter, well provide an overview of Android and its SDK, give a brief overview ofkey packages, introduce what we are going to cover in each chapter briefly, show youhow to take advantage of Android source code, and highlight the benefits ofprogramming for the Android Platform.A New Platform for a New Personal ComputerThe fact that hitherto dedicated devices such as mobile phones can now countthemselves among other venerable general-computing platforms is great news forprogrammers (see Figure 11). This new trend makes mobile devices accessible through 1 20. 2 CHAPTER 1: Introducing the Android Computing Platformgeneral-purpose computing languages, which increases the range and market share formobile applications.The General Purpose Computing ClubMainframeServerWorkstation LaptopNew Kid on theBlockFigure 11. Handheld is the new PC.The Android Platform embraces the idea of general-purpose computing for handhelddevices. It is a comprehensive platform that features a Linux-based operating systemstack for managing devices, memory, and processes. Androids libraries covertelephony, video, graphics, UI programming, and a number of other aspects of thedevice. NOTE: Although built for mobile devices, the Android platform exhibits the characteristics of a full-featured desktop framework. Google makes this framework available to Java programmers through a Software Development Kit (SDK) called the Android SDK. When you are working with the Android SDK, you rarely feel that you are writing to a mobile device because you have access to most of the class libraries that you use on a desktop or a serverincluding a relational database.The Android SDK supports most of the Java Platform, Standard Edition (Java SE) exceptfor the Abstract Window Toolkit (AWT) and Swing. In place of AWT and Swing, AndroidSDK has its own extensive modern UI framework. Because youre programming yourapplications in Java, you could expect that you need a Java Virtual Machine (JVM) thatis responsible for interpreting the runtime Java byte code. A JVM typically provides thenecessary optimization to help Java reach performance levels comparable to compiledlanguages such as C and C++. Android offers its own optimized JVM to run thecompiled Java class files in order to counter the handheld device limitations such asmemory, processor speed, and power. This virtual machine is called the Dalvik VM,which well explore in a later section Delving into the Dalvik VM.The familiarity and simplicity of the Java programming language coupled with Androidsextensive class library makes Android a compelling platform to write programs for. 21. CHAPTER 1: Introducing the Android Computing Platform 3Figure 12 provides an overview of the Android software stack. (Well provide furtherdetails in the section Understanding the Android Software Stack.)User ApplicationsJava LibrariesActivities/Services UI/Graphics/ViewsResources/Content ProvidersTelephone/CameraMultimedia SQLite Database Http/Connectivity Java SE/Java Apache Dalvik VMCore C Libraries LinuxFigure 12. High-level view of the Android software stackHistory of AndroidLet us look at how Android arrived on the Mobile OS landscape. Mobile phones use avariety of operating systems such as Symbian OS, Microsofts Windows Mobile, MobileLinux, iPhone OS (based on Mac OS X), Moblin (from Intel), and many other proprietaryOSs. So far no single OS has become the de facto standard. The available APIs andenvironments for developing mobile applications are too restrictive and seem to fallbehind when compared to desktop frameworks. This is where Google comes in. TheAndroid platform promised openness, affordability, open source code, and a high-enddevelopment framework.Google acquired the startup company Android Inc. in 2005 to start the development ofthe Android Platform (see Figure 13). The key players at Android Inc. included AndyRubin, Rich Miner, Nick Sears, and Chris White. 22. 4 CHAPTER 1: Introducing the Android Computing Platform20082008 20082008 T-Mobile G1 AnnouncedSDK 1.0 Released Android Open Sourced 2007 20072007 OHA Announced Early Look SDK200520052005 Google Buys Android Inc.Work on Dalvik VM Starts Figure 13. Android timeline In late 2007, a group of industry leaders came together around the Android Platform to form the Open Handset Alliance (http://www.openhandsetalliance.com). Some of the alliances prominent members are as follows: Sprint Nextel T-MobileThis book was purchased by [email protected] Motorola Samsung Sony Ericsson Toshiba Vodafone Google Intel Texas Instruments Part of the alliances goal is to innovate rapidly and respond better to consumer needs, and its first key outcome was the Android Platform. Android was designed to serve the needs of mobile operators, handset manufacturers, and application developers. The members have committed to release significant intellectual property through the open source Apache License, Version 2.0.NOTE: Handset manufacturers do not need to pay any licensing fees to load Android on theirhandsets or devices. The Android SDK was first issued as an early look release in November 2007. In September 2008, T-Mobile announced the availability of T-Mobile G1, the first smartphone based on the Android platform. A few days after that, Google announced the availability of Android SDK Release Candidate 1.0. In October 2008, Google made the source code of the Android platform available under Apaches open source license. 23. CHAPTER 1: Introducing the Android Computing Platform 5When Android was released, one of its key architectural goals was to allow applicationsto interact with one another and reuse components from one another. This reuse notonly applies to services, but also to data and the user interface (UI). As a result, theAndroid platform has a number of architectural features that keep this openness areality. Well delve into some of these features in Chapter 3.Android has also attracted an early following because of its fully developed features toexploit the cloud-computing model offered by web resources and to enhance thatexperience with local data stores on the handset itself. Androids support for a relationaldatabase on the handset also played a part in early adoption.In late 2008 Google released a handheld device called Android Dev Phone 1 that wascapable of running Android applications without being tied to any cell phone providernetwork. The goal of this device (at an approximate cost of $400.00) was to allowdevelopers to experiment with a real device that could run the Android OS without anycontracts. At around the same time, Google also released a bug fix, version 1.1 of theOS, that is solely based on version 1.0. In releases 1.0 and 1.1 Android did not supportsoft keyboards, requiring the devices to carry physical keys. Android fixed this issue byreleasing the 1.5 SDK in April 2009, along with a number of other features, such asadvanced media-recording capabilities, widgets, and live folders. (We cover live foldersin Chapter 12 and widgets in Chapter 13.)In September 2009 came release 1.6 of the Android OS and, within a month, Android 2.0followed, facilitating a flood of Android devices in time for the 2009 Christmas season.This release has introduced advanced search capabilities and text to speech. (We covertext to speech in Chapter 15. We cover Android search in Chapter 14.) This release hasalso introduced gestures and multi-touch. These topics are covered in Chapter 16.With support for HTML 5, Android 2.0 introduces interesting possibilities for usingHTML. These new programming possibilities are covered in Chapter 17, where wediscuss Titanium Mobile. More and more Android-based applications are introducedevery day, as well as new types of independent online application stores. Theseapplication stores, along with the Google-operated online Android Market, are coveredin Chapter 18. In Chapter 19 we will analyze how well-positioned Android is in themobile space.Delving into the Dalvik VMAs part of Android, Google has spent a lot of time thinking about optimizing designs forlow-powered handheld devices. Handheld devices lag behind their desktopcounterparts in memory and speed by eight to ten years. They also have limited powerfor computation; a handheld devices total RAM might be as little as 64MB, and itsavailable space for applications might be as little as 20MB. 24. 6 CHAPTER 1: Introducing the Android Computing Platform NOTE: The T-Mobile G1 phone, released in late 2008, comes with 192MB of RAM, a 1GB SD card, and a 528 MHz Qualcomm MSM7201A processor. Motorola Droid, released in late 2009, comes with 256MB of RAM, a 16GB microSD card, and a 550 MHz Arm Cortex Processor. Compare that to the lowest-priced Dell laptop, which comes with a 2.1 GHz dual-core processor and 4GB of RAM.The performance requirements on handsets are severe as a result, requiring handsetdesigners to optimize everything. If you look at the list of packages in Android, youll seethat they are full-featured and extensive. According to Google, these system librariesmight use as much as 10 to 20MB, even with their optimized JVM.These issues led Google to revisit the standard JVM implementation in many respects.(The key figure in Googles implementation of this JVM is Dan Bornstein, who wrote theDalvik VMDalvik is the name of a town in Iceland.) First, the Dalvik VM takes thegenerated Java class files and combines them into one or more Dalvik Executable (.dex)files. It reuses duplicate information from multiple class files, effectively reducing thespace requirement (uncompressed) by half from a traditional .jar file. For example, the.dex file of the web browser app in Android is about 200K, whereas the equivalentuncompressed .jar version is about 500K. The .dex file of the alarm clock app is about50K, and roughly twice that size in its . jar version.Second, Google has fine-tuned the garbage collection in the Dalvik VM, but it haschosen to omit a just-in-time (JIT) compiler, in early releases. The 2.0 codebase seem tohave the necessary sources for a JIT compiler but is not enabled in the final release. It isanticipated that it will be part of future releases. The company can justify this choicebecause many of Androids core libraries, including the graphics libraries, areimplemented in C and C++. For example, the Java graphics APIs are actually thinwrapper classes around the native code using the Java Native Interface (JNI). Similarly,Android provides an optimized C-based native library to access the SQLite database,but this library is encapsulated in a higher-level Java API. Because most of the corecode is in C and C++, Google reasoned that the impact of JIT compilation would not besignificant.Finally, the Dalvik VM uses a different kind of assembly-code generation, in which it usesregisters as the primary units of data storage instead of the stack. Google is hoping toaccomplish 30 percent fewer instructions as a result. We should point out that the finalexecutable code in Android, as a result of the Dalvik VM, is based not on Java byte codebut on .dex files instead. This means you cannot directly execute Java byte code; youhave to start with Java class files and then convert them to linkable .dex files.This performance paranoia extends into the rest of the Android SDK. For example, theAndroid SDK uses XML extensively to define UI layouts. However, all of this XML iscompiled to binary files before these binary files become resident on the devices.Android provides special mechanisms to use this XML data. While we are on the subjectof Androids design considerations, we should answer this question: How would onecompare and contrast Android to Java Platform, Micro Edition (Java ME)? 25. CHAPTER 1: Introducing the Android Computing Platform 7Comparing Android and Java MEAs you have already seen, Android has taken a comprehensive, dedicated, and focusedapproach to its mobile platform efforts that go beyond a simple JVM-based solution.The Android Platform comes with everything you need in a single package: the OS,device drivers, core libraries, JNI, optimized Dalvik VM, and the Java developmentenvironment. Developers can be assured that when they develop new applications, allkey libraries will be available on the device.This comprehensive approach differs from other mobile efforts such as Java ME. Let usoffer a brief overview of Java ME before comparing the two approaches. Figure 14shows the availability of Java for various computing configurations. Java Platform,Standard Edition (Java SE) is suitable for desktop and workstation configurations. JavaPlatform, Enterprise Edition (Java EE) is designed for server configurations. Java Computing Configurations Mainframe ServerWorkstationLaptop Connected PDA/ Infrequently Phone/Connected Multimedia Consumer DeviceJava EEJava SE Java MEConnected Java ME(CDC)Connected(Limited) (CLDC)Figure 14. Java computing configurationsJava Platform, Micro Edition (Java ME) is an edition of Java that is pared down forsmaller devices. Two configuration sets are available for Java ME. The first configurationis called the Connected Device Configuration (CDC). Java ME for CDC involves a pared-down version of Java SE with fewer packages, fewer classes within those packages,and even fewer fields and methods within those classes. For appliances and devicesthat are further constrained, Java defines a configuration called Connected LimitedDevice Configuration (CLDC). The available APIs for various Java configurations arecontrasted in Figure 15. 26. 8 CHAPTER 1: Introducing the Android Computing PlatformAny optional packages that are installed on top of the base CDC and CLDC APIs aretreated as profiles that are standardized using the JSR process. Each defined profilemakes an additional set of APIs available to the developer. CAUTION: Both CLDC and CDC might support some Java APIs outside Java SE, and their classes might not start with the java.* namespace. As a consequence, if you have a Java program that runs on your desktop, there are no guarantees that it will run on devices supporting only micro editions.Java EEJava SEJavax.microedition.*;Java MECDC Java MECLDCFigure 15. Java API availabilityThe CLDC Java platform is hosted on a specialized and greatly reduced JVM called theK Virtual Machine (KVM), which is capable of running on devices whose memory is aslow as 128K. (The K in KVM stands for kilobytes.) CLDC can run additional APIs underMIDP (Mobile Information Device Profile) 2.0. This API includes a number of packagesunder javax.microedition.*. The key packages are MIDlets (simple applications), a UIpackage called LCDUI, gaming, and media.The CDC configuration APIs include the java.awt API, the java.net API, and moresecurity APIs, in addition to the CLDC configuration APIs. The additional profilesavailable on top of CDC make the javax.microedition.xlet API available to applicationprogrammers (Xlets represent applications in the CDC configuration). On top of a CDCconfiguration youll find about ten more optional packages that you can run, includingBluetooth, Media API, OpenGL for Embedded Systems (OpenGL ES), Java API for XMLProcessing (JAXP), JAXP-RPC, Java 2D, Swing, Java Remote Method Invocation (Java 27. CHAPTER 1: Introducing the Android Computing Platform 9RMI), Java Database Connectivity (JDBC), and Java API. Overall, the Java MEspecification includes more than 20 JSRs. It is also expected that JavaFX(http://javafx.com) will play an increasing role in the mobile space for Java.NOTE: JavaFX is a new user interface effort from Sun to dramatically improve applet-likefunctionality in browsers. It offers a declarative UI programming model that is also friendlier todesigners.Now that you have a background on Java ME, lets look at how it compares to Android. Multiple device configurations: Java ME addresses two classes of micro devices and offers standardized and distinct solutions for each. Android, on the other hand, applies to just one model. It wont run on low-end devices unless or until the configurations of those devices improve. Ease of understanding: Because Android is geared toward only one device model, its easier to understand than Java ME. Java ME has multiple UI models for each configuration, depending on the features supported by the device: MIDlets, Xlets, the AWT, and Swing. The JSRs for each Java ME specification are harder to follow. They take longer to mature, and finding implementations for them can be difficult. Responsiveness: The Dalvik VM is expected to be more optimized and more responsive compared to the standard JVM supported on a similarly configured device. You can compare the Dalvik VM to the KVM, but the KVM addresses a lower-level device with much less memory. Java compatibility: Because of the Dalvik VM, Android runs .dex byte code instead of Java byte code. This should not be a major concern as long as Java is compiled to standard Java class files. Only runtime interpretation of Java byte code is not possible. Adoption: There is widespread support for Java ME on mobile devices because most mobile phones support it. But the uniformity, cost, and ease of development in Android are compelling reasons for Java developers to program for it. Java SE support: Compared to the support for Java SE in CDC, the Android support for Java SE is a bit more complete, except for the AWT and Swing. As we mentioned earlier, Android has its own UI approach instead. In fact, Androids declarative UI resembles more advanced UI platforms such as Microsoft Silverlight and Suns JavaFX. 28. 10 CHAPTER 1: Introducing the Android Computing Platform Understanding the Android Software Stack So far weve covered Androids history and its optimization features including the Dalvik VM, and weve hinted at the Java programming stack available. In this section, we would like to cover the development aspect of Android. Figure 16 is a good place to start this discussion.Applications Java SDKActivities AnimationOpenGLViewsTelephonyCameraResources Content Providers SQLite Native Libraries Android RuntimeMedia SQLite Dalvik VM OpenGL WebKitFreeTypeGraphicsLinux Kernel Device Drivers Figure 16. Detailed Android SDK software stack At the core of the Android Platform is Linux kernel version 2.6.29, responsible for device drivers, resource access, power management, and other OS duties. The supplied device drivers include Display, Camera, Keypad, WiFi, Flash Memory, Audio, and IPC (inter- process communication). Although the core is Linux, the majorityif not allof the applications on an Android device such as the T-Mobile G1 or Motorola Droid are developed in Java and run through the Dalvik VM. Sitting at the next level, on top of the kernel, are a number of C/C++ libraries such as OpenGL, WebKit, FreeType, Secure Sockets Layer (SSL), the C runtime library (libc), SQLite, and Media. The system C library based on Berkeley Software Distribution (BSD) is tuned (to roughly half its original size) for embedded Linux-based devices. The media libraries are based on PacketVideos (http://www.packetvideo.com/) OpenCORE. These libraries are responsible for recording and playback of audio and video formats. A library called Surface Manager controls access to the display system and supports 2D and 3D. 29. CHAPTER 1: Introducing the Android Computing Platform 11The WebKit library is responsible for browser support; it is the same library that supportsGoogle Chrome and Apples Safari. The FreeType library is responsible for font support.SQLite (http://www.sqlite.org/) is a relational database that is available on the deviceitself. SQLite is also an independent open source effort for relational databases and notdirectly tied to Android. You can acquire and use tools meant for SQLite for Androiddatabases as well.Most of the application framework accesses these core libraries through the Dalvik VM,the gateway to the Android Platform. As we indicated in the previous sections, Dalvik isoptimized to run multiple instances of VMs. As Java applications access these corelibraries, each application gets its own VM instance.The Android Java APIs main libraries include telephony, resources, locations, UI,content providers (data), and package managers (installation, security, and so on).Programmers develop end-user applications on top of this Java API. Some examples ofend-user applications on the device include Home, Contacts, Phone, Browser, and soon.Android also supports a custom Google 2D graphics library called Skia, which is writtenin C and C++. Skia also forms the core of the Google Chrome browser. The 3D APIs inAndroid, however, are based on an implementation of OpenGL ES from the Khronosgroup (http://www.khronos.org). OpenGL ES contains subsets of OpenGL that aretargeted toward embedded systems.From a media perspective, the Android Platform supports the most common formats foraudio, video, and images. From a wireless perspective, Android has APIs to supportBluetooth, EDGE, 3G, WiFi, and Global System for Mobile Communication (GSM)telephony, depending on the hardware.Developing an End-User Application with theAndroid SDKIn this section, well introduce you to the high-level Android Java APIs that youll use todevelop end-user applications on Android. We will briefly talk about the Androidemulator, Android foundational components, UI programming, services, media,telephony, animation, and OpenGL. We will also show you some code snippets.Android EmulatorAndroid SDK ships with an Eclipse plug-in called Android Development Tools (ADT). Youwill use this Integrated Development Environment (IDE) tool for developing, debugging,and testing your Java applications. (Well cover ADT in depth in Chapter 2.) You can alsouse the Android SDK without using ADT; youd use command-line tools instead. Bothapproaches support an emulator that you can use to run, debug, and test yourapplications. You will not even need the real device for 90 percent of your applicationdevelopment. The full-featured Android emulator mimics most of the device features. 30. 12 CHAPTER 1: Introducing the Android Computing Platform The emulator limitations include USB connections, camera and video capture, headphones, battery simulation, and Bluetooth. The Android emulator accomplishes its work through an open source processor emulator technology called QEMU (http://bellard.org/qemu/) developed by Fabrice Bellard. This is the same technology that allows emulation of one operating system on top of another, irrespective of the processor. QEMU allows emulation at the CPU level. With the Android emulator, the processor is based on ARM (Advanced RISC Machine). ARM is a 32-bit microprocessor architecture based on RISC (Reduced Instruction Set Computer), in which design simplicity and speed is achieved through a reduced number of instructions in an instruction set. The emulator runs the Android version of Linux on this simulated processor.NOTE: Many high-end graphics and scientific workstations from HP and Sun are based onadvanced RISC processors. ARM is widely used in handhelds and other embedded electronics where lower power consumption is important. Much of the mobile market uses processors based on this architecture. For example, Apple Newton was based on the ARM6 processor. Devices such as the iPod, Nintendo DS, and Game Boy Advance run on ARM architecture version 4 with approximately 30,000 transistors. Compared to that, the Pentium classic contains 3,200,000 (3. 2 million) transistors. You can find more details about the emulator in the Android SDK documentation at http://developer.android.com/guide/developing/tools/emulator.html. The Android UI Android uses a UI framework that resembles other desktop-based, full-featured UI frameworks. In fact, its more modern and more asynchronous in nature. The Android UI is essentially a fourth-generation UI framework, if you consider the traditional C-based Microsoft Windows API the first generation and the C++-based MFC (Microsoft Foundation Classes) the second generation. The Java-based Swing UI framework would be the third generation, introducing design flexibility far beyond that offered by MFC. The Android UI, JavaFX, Microsoft Silverlight, and Mozilla XML User Interface Language (XUL) fall under this new type of fourth-generation UI framework, in which the UI is declarative and independently themed.NOTE: In Android, you program using a modern user interface paradigm even though the deviceyoure programming for happens to be a handheld. Programming in the Android UI involves declaring the interface in XML files. You then load these XML view definitions as windows in your UI application. Even menus in your application are loaded from XML files. Screens or windows in Android are often referred 31. CHAPTER 1: Introducing the Android Computing Platform 13to as activities, which comprise multiple views that a user needs in order to accomplisha logical unit of action. Views are Androids basic UI building blocks, and you can furthercombine them to form composite views called view groups. Views internally use thefamiliar concepts of canvases, painting, and user interaction. An activity hosting thesecomposite views, which include views and view groups, is the logical replaceable UIcomponent in Android.One of the Android frameworks key concepts is the lifecycle management of activitywindows. Protocols are put in place so that Android can manage state as users hide,restore, stop, and close activity windows. You will get a feel for these basic ideas inChapter 2, along with an introduction to setting up the Android developmentenvironment.The Android Foundational ComponentsThe Android UI framework, along with other parts of Android, relies on a new conceptcalled an intent. An intent is an amalgamation of ideas such as windowing messages,actions, publish-and-subscribe models, inter-process communications, and applicationregistries. Here is an example of using the Intent class to invoke or start a web browser:public static void invokeWebBrowser(Activity activity){Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://www.google.com"));activity.startActivity(intent);}In this example, through an intent, we are asking Android to start a suitable window todisplay the content of a web site. Depending on the list of browsers that are installed onthe device, Android will choose a suitable one to display the site. You will learn moreabout intents in Chapter 3.Android also has extensive support for resources, which include familiar elements andfiles such as strings and bitmaps, as well as some not-so-familiar items such as XML-based view definitions. The framework makes use of resources in a novel way to maketheir usage easy, intuitive, and convenient. Here is an example where resource IDs areautomatically generated for resources defined in XML files:public final class R {public static final class attr { }public static final class drawable {public static final int myanimation=0x7f020001;public static final int numbers19=0x7f02000e;}public static final class id {public static final int textViewId1=0x7f080003;}public static final class layout {public static final int frame_animations_layout=0x7f030001;public static final int main=0x7f030002;} 32. 14 CHAPTER 1: Int