所需积分/C币:10 2011-12-20 00:13:12 10.22MB PDF
收藏 收藏

Beginning Android 2 Mark L. Murphy apress Beginning Android 2 Copyright o 2010 by Mark L. Murphy 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-13pbk:978-1-4302-2629-1 ISBN-13( electronic):978-1-4302-2630-7 Printed and bound in the united states of america 987654321 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 ofinfringement of the trademark JavaTM and all Java-based marks are trademarks or registered trademarks of Sun Microsystems Inc, in the US and other countries. Apress, Inc, is not affiliated with Sun Microsystems, Inc, and this book was written without endorsement from Sun Microsystems, Inc President and Publisher: Paul manning Lead Editor: Steve anglin Development Editor: Matthew Moodie 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 Wels Coordinating Editor: Fran Parnell Copy Editor: Marilyn S. Smith Compositor: MacPS, LlC Indexer: John Collin 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,, 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-e Book Licensing web page at The information in this book is distributed on an"as is"basis, without warranty. Although ever 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 infornation contained in this work Contents at a Glance Contents at a glance Contents " About the author Acknowledgments mmemeeeeeeeI Preface Chapter 1: The Big Picture aameaaaea Chapter 2: Projects and Targets Chapter 3: Creating a skeleton Application Chapter 4: Using xML-Based layouts.aataaa Chapter 5: Employing Basic Widgets 29 Chapter 6: Working with Containers 39 Chapter 7: Using Selection Widget Chapter 8: Getting Fancy with lists.BaeeaasBaBBsBBRIBSeBaRISEEeRaD 75 Chapter 9: Employing Fancy Widgets and Chapter 10: The Input Method Framework Chapter 11: Applying Menus. Chapter 12: Fonts. Chapter 13: Embedding the Webkit Browseramena Chapter 14: Showing Pop-Up Messages 12g Chapter 15: Dealing with Threads emaBIaBBaIa Chapter 16: Handling Activity Life Cycle Events am aataemeaamaaaaananman anmaInma. 167 Chapter 17: Creating Intent Filters eBmmmaean Chapter 18: Launching Activities and Subactivities Chapter 19: Handling Rotation maan 65 Chapter 20: Working with Resources maemeemmamemtmanane 197 Chapter 21: Using 2i3 Chapter 22: Managing and Accessing Local Databases naaa Chapter 23: Accessing Files.aaaasf Chapter 24: Leveraging Java libraries aaaaaa 245 Chapter 25: Communicating via the Internet. 253 Chapter 26: Using a content Provider. 25g Chapter 27: Building a content Provider 265 Chapter 28: Requesting and Requiring Permissions maa. 75 a27 Chapter 29: Creating a z79 Chapter 30: Invoking a Service.n: Chapter 31: Alerting Users via Notifications Chapter 32: Accessing Location-Based Services. Chapter 33: Mapping with Map view and MapActivity asaemaeaasat 亚 Chapter 34: Handling Telephone Calls Chapter 35: Development Tools 35 Chapter 36: Handling Multiple screen Sizes 31 Chapter 37: Dealing with devices.. Chapter 38: Handling Platform Changes.mmemmmm IBaB IEB a B IImEmaImnama 359 Chapter 39: Where do We Go from Here?.neee.s.. 37 Index…aa3339 Contents Contents at a glance ■■■■■■■■■ Contents ■■■■■■■■■■■■■■■■■■■■a■■■■■a■口■■■口 v About the author∴nXTi Acknowledgments m BsIBIBBIRIBSIS RIEIRRIBEBBIBIBS BBI RIRIBSIRIRIIBaBBIIIRIEIan XiV tace umax Chapter 1: The Big Picture BR IB aIBIB BIBIBBBBBBBBIBBIRIBIR Challenges of Smartphone Programming What Androids are made of Stuff at your disposal 11-2-3-5 Chapter 2: Projects and targets ma Pieces and parts Creating a project… 1,11着1面1面1 Project Structure….… Root contents The Sweat off your brow And Now, the rest of the 5-5-6-6677-7-8-8 What you get out of it Inside the manifest In the Beginning, There Was the Root, And It Was Good Permissions, Instrumentations, and Applications(OhMy!)…………… Your Application Does Something, Right? Achieving the Minimum Version= Control… Emulators and Targets........... 12 virtually There Aiming at a target . CONTENTS Chapter 3: Creating a Skeleton Application 17 Begin at the beginning..... 17 Dissecting the activity…… Building and Running the Activity Chapter 4: Using XML-Based Layouts Em IBERIRIRRIRRBR IERERERRIR IRERRRIEER IREEER 23 What Is an XML-Based Layout?.... Why Use XML-Based Layouts? 1重 OK So What does it look like? What's with the Signs?. And how do we attach these to the Java? The Rest of the Story…, Chapter 5: Employing Basic Widgets ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■D■■ 2222239四 Assigning labels Button Button Who's got the button? Fleeting Images Fields of green or other colors Just another box to check Turn the Radio Up It's Quite a view Useful Properties............ a准准主准主 Useful methods Colors Chapter 6: Working with containers ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■口■■■■ Thinking Linearly........ LinearLayout Concepts and Properties 道1 LinearLayout Example........ 1着 899426 All Things Are Relative.... Relative layout Concepts and Properties Relative Layout Example. 重,11 n111重 Tabula rasa Tablelayout concepts and Properties TableLayout Example Scrollwork Chapter7: Using Selection Widgets…,.,.,,,,…,…,.59 Adapting to the circumstances........ Lists of Naughty and Nice... Spin Control… 906 Grid Your Lions (or Something Like That 1;道1a道: Fields: Now with 35% Less typing Galleries give or take the art Chapter 8: Getting Fancy with Lists 6825 Getting to First Bas A Dynamic Presentation Better. Stronger. Faster Using convertView 780 Using the holder pattern CONTENTS Making a list... m And Checking It Twice............ 89 Adapting other Adapters Chapter 9: Employing Fancy Widgets and containers amaa ■■■■■■■■■■■■■■■国■■■■■■■■ Pick and choose …95 Time Keeps flowing like a River a1国1道道 99 Making Progress 1道1:道1道 Seeking Resolution Put it or 102 The pieces n重 道1a1道1道道1a 103 The idiosyncrasies Wiring it Togeth Adding Them Up 1,11着1面1面1 Intents and views 11 Flipping them0-.…. Manual Flipping . 110 Adding Contents on the ,12 Automatic Flipping…,,,,… 113 Getting in Someone's Drawer 114 Other good stuff 16 Chapter 10: The Input Method Framework.mmim ■■■■■■■■■■口■■■■■■■■■■■■■■■■■ Keyboards, Hard and soft.…,… 17 Tailored to your needs :国1主自自主主 118 Tell android where it can go 121 Fitting In 123 Unleash your inner dvorak 124 Chapter 11: Applying Menus mm ■■■■■■■ 125 Menus of options 125 Creating an Options Menu 125 Adding Menu Choices and Submenus....... 126 Menus in context 127 Yet more inflation Menu xml structure Menu Options and XML. 134 Inflating the menu 1 Chapter 12: Fonts Love the one youre with 主主主 137 More Fonts Here a Glyph, There a glyph ..140 Chapter 13: Embedding the Webkit Browser ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■ 141 A Browser, writ small 141 Loading It Up Navigating the Waters Entertaining the client ..145 Settings, Preferences, and Options(oh My!) 147 CONTENTS Chapter 14: Showing Pop-Up Messages. IBIBRIBIREBIBERIRIBREIRRIB REIIEIEI. 149 Raising Toasts a“ 1000000 A|er!AerL!…,150 Checking Them Out 151 Chapter 15: Dealing with Threads s IamIRIIRIBRIBaIsaIsIaaIBRIIaIan 155 Getting Through the Handlers Messages 1道,1a 主谁 Running in Place 159 Where Oh Where Has My UI Thread Gone?. ,159 Asyncing Feeling The Theory… 重,11 n111重 159 AsyncTask, Generics, and varargs The Stages of Async Task A Sample Task 161 And now, the caveats… 164 Chapter 16: Handling Activity Life Cycle Events ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Schroedinger's Activity ife, Death, and Your Activity on Create( and on(.a.... on Start, onRestartO, and on Stop 1· 169 onPause0 and onResumeo 169 The grace of state Chapter 17: Creating Intent Filters t ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■圆■■■■■■■■■■ What's your Intent? 171 Pieces of intents n172 ntent Routing…., 172 Stating Your Intent(ions) Narrow receive The pause caveat Chapter 18: Launching Activities and Subactivities ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■a■■■■ 177 Peers and subs 177 Start 'Em Up 1道1里1面1里1里111,道1 78 Make an Intent 178 Make the call 178 Tabbed browsing Sort Of . Chapter 19: Handling Rotation RBIRBIBIBIBIBIBBBIBBIBIBBRIBBIEIBRIBIBBIBIIEIIRI 185 A Philosophy of Destruction.. 重道国1重n1日道重 185 s All the same, Just Different Now with more s 189 DIY Rotation 191 Forcing the Issue....... 1国 193 Making Sense of It All…… 195 Chapter 20: Working with Resources ■■■■■■■■■■■■■口■■■■■■■■■口■■■■■■■【口■ ■■■■■■■■■■■■■■■ 197 The Resource Lineup…… String Theory.,,…,…, …198

立即下载 低至0.43元/次 身份认证VIP会员低至7折
    关注 私信 TA的资源