apress pro android 2 (2010)

737 832 0
apress pro android 2 (2010)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Hashimi Komatineni MacLean Android 2 Pro Companion eBook Available 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 Trim: 7.5 x 9.25 spine = 1.375" 736 page count COMPANION eBOOK SEE LAST PAGE FOR DETAILS ON $10 eBOOK VERSION US $49.99 Shelve in Mobile Computing User level: Intermediate-Advanced www.apress.com SOURCE CODE ONLINE BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® ISBN 978-1-4302-2659-8 9 781430 226598 5 49 9 9 this print for content only—size & color not accurate CYAN MAGENTA YELLOW BLACK PANTONE 123 C SPOT MATTE A ndroid, Google’s open-source platform for mobile development, has the momentum to become the leading mobile platform. Pro Android 2 shows you how to build real-world mobile apps using Google’s Android SDK. Android is easy to learn yet comprehensive, and is rich in functionality. The absence of licensing fees for Android OS has borne fruit already with many distinct device manufacturers and a multiplicity of models and carriers. Indi- vidual developers have a great opportunity to publish mobile applications on the Android Market; in only ve months’ time the number of applications has doubled, with over 20,000 available today. And the widespread use of Android has increased demand for corporate developers as companies are looking for a mobile presence. You can be part of this. With real-world source code in hand, Pro Android 2 covers mobile application development for the Android platform from basic concepts such as Android Resources, Intents, and Content Providers to OpenGL, Text to Speech, Multi- touch, Home Screen Widgets, and Titanium Mobile. We teach you how to build Android applications by taking you through Android APIs, from basic to ad- vanced, one step at a time. Android makes mobile programming far more accessible than any other mobile platforms available today. At no cost to you, you can download the Eclipse IDE and the Android SDK, and you will have everything you need to start writing great applications for Android mobile devices. You will not even need a physical device—the Android SDK provides an emulator that you can run on your desktop. Pro Android 2 is the result of over two years of eort to bring together in one place everything you need—both basic and advanced—to be an Android developer. So what are you waiting for? s i Pro Android 2 ■ ■ ■ Sayed Y. Hashimi Satya Komatineni Dave MacLean ii 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- ny@springer-sbm.com , or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. iii To my son, Sayed-Adieb. —Sayed Y. Hashimi To my beautiful wife, AnnMarie, for her spirit; to Ashley, for her undaunting hope; to Nikolas, for his 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 couldn't have done this without them. And to Max, for spending so much time at my feet keeping me company. —Dave MacLean iv 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 Android Development 627 ■Chapter 18: Working with Android Market 661 ■Chapter 19: Outlook and Resources 675 ■Index 687 v Contents ■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 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 11 Android Emulator 11 The Android UI 12 The Android Foundational Components 13 Advanced UI Concepts 14 Android Service Components 16 Android Media and Telephony Components 16 Android Java Packages 18 Taking Advantage of Android Source Code 23 Summary 24 ■Chapter 2: Getting Your Feet Wet 25 Setting Up Your Environment 25 Downloading JDK 6 26 Downloading Eclipse 3.5 26 Downloading the Android SDK 27  ■ CONTENTS vi Installing Android Development Tools (ADT) 28 Learning the Fundamental Components 31 View 31 Activity 31 Intent 31 Content Provider 32 Service 32 AndroidManifest.xml 32 Android Virtual Devices 32 Hello World! 33 Android Virtual Devices 38 Exploring the Structure of an Android Application 40 Analyzing the Notepad Application 42 Loading and Running the Notepad Application 43 Dissecting the Application 44 Examining the Application Lifecycle 51 Debugging Your App 54 Summary 55 ■Chapter 3: Using Resources, Content Providers, and Intents 57 Understanding Resources 58 String Resources 59 Layout Resources 60 Resource-Reference Syntax 62 Defining Your Own Resource IDs for Later Use 63 Compiled and Noncompiled Android Resources 64 Enumerating Key Android Resources 65 Working with Arbitrary XML Resource Files 73 Working with Raw Resources 74 Working with Assets 75 Reviewing the Resources Directory Structure 75 Understanding Content Providers 76 Exploring Android’s Built-in Providers 77 Architecture of Content Providers 83 Implementing Content Providers 95 Understanding Intents 106 Available Intents in Android 107 Intents and Data URIs 109 Generic Actions 110 Using Extra Information 111 Using Components to Directly Invoke an Activity 113 Best Practice for Component Designers 114 Understanding Intent Categories 114 The Rules for Resolving Intents to Their Components 117 Exercising the ACTION_PICK 117 Exercising the GET_CONTENT Action 119 Further Resources for This Chapter 121 Summary 121 ■ CONTENTS vii ■Chapter 4: Building User Interfaces and Using Controls 123 UI Development in Android 123 Understanding Android’s Common Controls 129 Text Controls 129 Button Controls 133 List Controls 139 Grid Controls 143 Date and Time Controls 145 Other Interesting Controls in Android 147 The MapView Control 148 The Gallery Control 148 The Spinner Control 148 Understanding 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 162 Understanding Adapters 164 Getting to Know SimpleCursorAdapter 165 Getting to Know ArrayAdapter 165 Creating Custom Adapters 166 Debugging and Optimizing Layouts with the Hierarchy Viewer 167 Summary 170 ■Chapter 5: Working with Menus and Dialogs 171 Understanding Android Menus 171 Creating a Menu 173 Working with Menu Groups 174 Responding to Menu Items 175 Creating a Test Harness for Testing Menus 176 Working 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 192 Loading 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 195 Using Dialogs in Android 196 Designing an Alert Dialog 197 Designing a Prompt Dialog 199 The Nature of Dialogs in Android 204 ■ CONTENTS viii 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 215 ■Chapter 6: Unveiling 2D Animation 217 Frame-by-Frame Animation 218 Planning for Frame-by-Frame Animation 218 Creating the Activity 219 Adding Animation to the Activity 220 Layout Animation 223 Basic Tweening Animation Types 224 Planning the Layout-Animation Test Harness 225 Creating the Activity and the ListView 226 Animating the ListView 228 Using Interpolators 231 View Animation 233 Understanding View Animation 233 Adding Animation 236 Using Camera to Provide Depth Perception in 2D 239 Exploring the AnimationListener Class 240 Some Notes on Transformation Matrices 241 Summary 242 ■Chapter 7: Exploring Security and Location-Based Services 243 Understanding the Android Security Model 243 Overview of Security Concepts 244 Signing Applications for Deployment 244 Performing Runtime Security Checks 249 Understanding Security at the Process Boundary 249 Declaring and Using Permissions 250 Understanding and Using Custom Permissions 252 Understanding and Using URI Permissions 258 Working with Location-Based Services 258 Understanding the Mapping Package 259 Understanding the Location Package 270 Summary 287 ■Chapter 8: Building and Consuming Services 289 Consuming HTTP Services 289 Using the HttpClient for HTTP GET Requests 290 Using the HttpClient for HTTP POST Requests 291 Dealing with Exceptions 295 Addressing Multithreading Issues 297 Doing Interprocess Communication 301 Creating a Simple Service 301 Understanding Services in Android 302 Understanding Local Services 303 [...]... T-Mobile G1 Announced 20 08 20 07 OHA Announced 20 07 20 05 20 05 Google Buys Android Inc 20 08 SDK 1.0 Released 20 08 Android Open Sourced 20 07 Early Look SDK 20 05 Work on Dalvik VM Starts Figure 1–3 Android timeline In late 20 07, a group of industry leaders came together around the Android Platform to form the Open Handset Alliance (http://www.openhandsetalliance.com) Some of the alliance’s prominent members... Implementing 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 ... 1: Introducing the Android Computing Platform NOTE: The T-Mobile G1 phone, released in late 20 08, comes with 192MB of RAM, a 1GB SD card, and a 528 MHz Qualcomm MSM 720 1A processor Motorola Droid, released in late 20 09, comes with 25 6MB 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... 625 ■Chapter 17: Titanium Mobile: A WebKit-Based Approach to Android Development 627 Titanium Mobile Overview 628 Architecture 629 The Titanium Ecosystem 6 32 Downloading and Installing Titanium Developer 633 Getting to Know the Ropes: The First Project .640 Creating a Titanium Mobile Project ... Android SDK In this section, we’ll introduce you to the high-level Android Java APIs that you’ll use to develop end-user applications on Android We will briefly talk about the Android emulator, Android foundational components, UI programming, services, media, telephony, animation, and OpenGL We will also show you some code snippets Android Emulator Android SDK ships with an Eclipse plug-in called Android. .. xmlns :android= "http://schemas .android. com/apk/res /android" > Although Android supports dialogs, all dialogs in Android are asynchronous These asynchronous dialogs present... android: versionName="1.0.0"> The Android manifest file is where activities... November 20 07 In September 20 08, 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 20 08, Google made the source code of the Android platform available under Apache’s open source license CHAPTER 1: Introducing the Android Computing Platform When Android. .. 488 Summary 489 ■Chapter 14: Android Search 491 Android Search Experience .4 92 Exploring Android Global Search 4 92 Enabling Suggestion Providers for Global Search 497 QSB and Suggestions Provider Interaction 500 Activities and Search Key Interaction 5 02 Behavior of Search Key on a Regular Activity ... such as memory, processor speed, and power This virtual machine is called the Dalvik VM, which we’ll explore in a later section “Delving into the Dalvik VM.” The familiarity and simplicity of the Java programming language coupled with Android s extensive class library makes Android a compelling platform to write programs for CHAPTER 1: Introducing the Android Computing Platform Figure 1 2 provides an . Animation Types 22 4 Planning the Layout-Animation Test Harness 22 5 Creating the Activity and the ListView 22 6 Animating the ListView 22 8 Using Interpolators 23 1 View Animation 23 3 Understanding. Animation 23 3 Adding Animation 23 6 Using Camera to Provide Depth Perception in 2D 23 9 Exploring the AnimationListener Class 24 0 Some Notes on Transformation Matrices 24 1 Summary 24 2 ■Chapter. Chapter 121  Summary 121  ■ CONTENTS vii ■Chapter 4: Building User Interfaces and Using Controls 123  UI Development in Android 123  Understanding Android s Common Controls 129  Text Controls 129  Button

Ngày đăng: 31/03/2014, 16:35

Từ khóa liên quan

Mục lục

  • COVER

  • Contents at a Glance

  • Contents

    • Chapter 1: Introducing the Android Computing Platform

    • Chapter 2: Getting Your Feet Wet

    • Chapter 3: Using Resources, Content Providers, and Intents

    • Chapter 4: Building User Interfaces and Using Controls

    • Chapter 5: Working with Menus and Dialogs

    • Chapter 6: Unveiling 2D Animation

    • Chapter 7: Exploring Security and Location-Based Services

    • Chapter 8: Building and Consuming Services

    • Chapter 9: Using the Media Framework and Telephony APIs

    • Chapter 10: Programming 3D Graphics with OpenGL

    • Chapter 11: Managing and Organizing Preferences

    • Chapter 12: Exploring Live Folders

    • Chapter 13: Home Screen Widgets

    • Chapter 14: Android Search

    • Chapter 15: Exploring Text to Speech and Translate APIs

    • Chapter 16: Touchscreens

    • Chapter 17: Titanium Mobile

    • Chapter 18: Working with Android Market

Tài liệu cùng người dùng

Tài liệu liên quan