Android Cookbook

所需积分/C币:10 2017-07-03 19:56:52 19.34MB PDF
收藏 收藏
举报

If you're ready to jump in and build a working Android app, this book has all of the practical recipes you need to get the job done. You'll work with the user interface, multitouch, location-aware apps, web services, device features-such as the camera, accelerometer, and GPS-and a lot more, includin
Android Cookbook lan f. darwin O REILLY Beijing· Cambridge· Farnham·Koln· Sebastopol· Tokyo Android cookbook by lan F. Darwin Copyright@ 2012 O'Reilly Media, Inc.. All rights reserved Printed in the United States of america Published by o reilly Media, Inc, 1005 Gravenstein Highway North, Sebastopol, CA 95472 O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions arealsoavailableformosttitles(http://my.safaribooksonline.com).Formoreinformationcontactour corporate/institutionalsalesdepartment:(800)998-9938orcorporate@oreilly.com Editors: Mike Loukides and Courtney Nash Indexer: Lucie haskins Production Editor Teresa Elsey Cover designer Karen montgomery Copyeditor Audrey doyle Interior Designer: David Futato Proofreader: Stacie arellano Illustrators: robert romano and Rebecca demarest April 2012 First edition Revision History for the First Edition: 201204-05 clease Seehttporeillycom/catalog/errata.cspisbn=9781449388416forreleasedetails Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. Android Cookbook, the image of a marine iguana, and related trade dress are trade marks of O'Reilly Media, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as rademarks. Where those designations appear in this book, and O Reilly Media, Inc, was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con tained herein ISBN:978-1-449-38841-6 1333645094 To Dennis m. ritchie(1941-2011, language pioneer and co-inventor of Unix, who showed us all where the braces go, and so much more Table of contents Preface XIl 1. Getting Started 1.1 Introduction: Getting Started 1.2 ng the Java Langi 1.3 Creating a"Hello, World"Application from the Command Line 3 1.4 Creating a"Hello, World application in eclipse 1.5 Setting Up an IDE on Windows to Develop for Android 1.6 Understanding the android Life cycle 20 1.7 Installing. apk Files onto an Emulator via the adB 1.8 Installing Apps onto an Emulator via SlideMe 1.9 Sharing Java Classes from Another Eclipse Project 23 1.10 Referencing libraries to Implement External Functionality 26 1.11 Using SDK Samples to Help Avoid Head Scratching 1.12 Keeping the Android SDK Updated 32 1.13 Taking a Screenshot from the Emulator/ Android device 39 1.14 Program: A Simple CountDown Timer Example 41 1.15 Program: Tipster, a Tip calculator for the android OS 44 2. Designing a Successful Application.............. 2. 1 Introduction: Designing a Successful Android Application 63 2.2 Exception Handling 66 2.3 Accessing Android's Application Object as a"Singleton 69 2.4 Keeping Data When the User Rotates the device 2.5 Monitoring the Battery Level of an Android Device 74 2.6 Creating Splash Screens in Android 75 2.7 Designing a Conference/Camp/Hackathon/Institution App 2.8 Using Google Analytics in an Android Application 2.9 A Simple Torch/ Flashlight 83 2.10 Adapting an Android Phone application to Be Used on a tablet 2.11 Setting First-Run Preferences 2.12 Formatting the Time and Date for display 2. 13 Controlling Input with Keyl 91 2. 14 Backing Up Android Application Data 95 2.15 USing Hints Instead T 101 3. Testing 3.1 Introd Testing 103 3.2 Doing Test-Driven Development(TDD)in Android 103 3.3 Setting Up an Android Virtual Device(AvD) for App Testing 104 3.4 Testing on a Huge Range of Devices with Cloud-based Testing 113 3.5 Creating and using a Test project 114 3.6 Troubleshooting Application Crashes 118 3.7 Debugging Using Log d and Log Cat 122 3.8 Getting Bug Reports from Users Automatically with Bug Sense 123 3.9 Using a Local Runtime application Log for Analysis of Field Errors or situations 3.10 Reproducing Activity Life-Cycle Scenarios for Testing 129 3. 11 Keeping Your App Snappy with Strict Mode 134 3. 12 Running the Monkey Program 135 3. 13 Sending Text Messages and Placing calls Between AVDs 137 4. Inter-/Intra-Process Communication 141 4.1 Introduction: Inter-/Intra-Process Communication 141 4.2 Opening a Web Page, Phone Number, or Anything Else with an Intent 142 4.3 Emailing Text from a view 143 4.4 Sending an Email with Attachments 146 4.5 Pushing String Values Using Intent. put Extrao 147 4.6 Retrieving Data from a Subactivity back to Your main activity 149 4.7 Keeping a Service Running While Other apps are on Display 151 4.8 Sending/Receiving a broadcast Message 153 4.9 Starting a Service After Device Reboot 154 4.10 Creating a Responsive application Using Threads 155 4.11 Using AsyncTask to Do Background Processing 157 4. 12 Sending Messages Between Threads Using an Activity Thread Queue and Handler 165 4.13 Creating an Android Epoch HTML/JavaScript Calendar 167 5.〔 ontent providers∴ 5.1 Introduction: Content Providers 173 5.2 Retrieving Data from a Content Provider 173 5.3 Writing a Content Provider 175 5.4 Writing an Android Remote Service 177 ⅵ i Table of Contents 6. Graphics∴ ,,18 6.1 Introduction: Graphics 183 6.2 USing a Custom Font 183 6.3 Drawing a Spinning Cube with OpenGL ES 186 6.4 Adding Controls to the OpengL Spinning Cube 190 6.5 Freehand Drawing Smooth Curves 193 6. Taking a Picture Using an Intent 199 6.7 Taking a Picture Using android. media. Camera 201 6.8 Scanning a Barcode or QR Code with the Google ZXing Barcode Scanner 204 6.9 Using AndroidPlot to Display Charts and Graphs 208 6.10 Using Inkscape to Create an Android Launcher Icon 210 6.11 Creating Easy Launcher Icons from Open ClipArt. org Using Paint. NET 217 6.12 Using Nine Patch Files 24 6.13 Creating HTML5 Charts with Android RGrapl 227 6. 14 Adding a Simple raster Animation 231 6.15 Using Pi inch to Z oom 234 7. Graphical User Interface 239 7.1 Introduction GUI 239 7.2 Understanding and Following User Interface Guidelines 240 7.3 Handling Configuration Changes by Decoupling the View from the Model 241 7.4 Creating a Button and Its click Event Listener 244 7.5 Wiring Up an Event Listener in Five Different Ways 245 7.6 Using CheckBoxes and Radio Buttons 250 7.7 Enhancing UI Design Using Image Buttons 253 7.8 Offering a Drop-Down Chooser via the Spinner class 256 7.9 Handling Long-Press/Long-Click Events 258 7. 10 Displaying text Fields with Text view and editText y ng 7. 11 Constraining EditText Values with Attributes and the Text Watcher Interface 260 7. 12 Implementing Auto Complete Text View 263 7.13 Feeding Auto Complete Text View Using an SQLite Database Query 265 7. 14 Turning edit Fields into Password Fields 267 7.15 Changing the Enter Key to"Next"on the Soft Keyboard 268 7.16 Processing Key-Press Events in an Activity 270 7. 17 Let Them See Stars: USing Rating Bar 272 7. 18 Making a View Shake 276 7. 19 Providing Haptic Feedback 277 7.20 Navigating Different Activities Within a Tabview 281 7.21 Creating a Custom Title Bar 283 Table of contents|ⅶi 7.22 Formatting Numbers 285 7.23 Formatting with Correct Plurals 289 7. 24 Starting a Second Screen from the First 292 7.25 Creating a Loading Screen That Will Appear Between Two Activities 301 7.26 Using Sliding Drawer to Overlap Other Components 303 7.27 Customizing the Sliding Drawer Component to Animate Transition from the Top down 305 7.28 Adding a border with rounded corners to a layout 307 7.29 Detecting Gestures in Android 309 7.30 Building a UI Using Android 3.0 Fragments in Android 1.6 and Later 316 7.31 Using the Android 3.0 Photo galle 321 7.32 Creating a Simple app Widget 324 8. GUI Alerts: Menus, Dialogs, Toasts, and Notifications............ 329 8.1 Introduction: GUI Alerts 329 8.2 Creating and Displaying a Menu 330 8.3 Handling Choice Selection in a Menu 331 8. Creating a Submenu 8.5 Creating a Pop-up/Alert Dialog 336 8.6 USing a Timepicker Widget 338 8.7 Creating an iPhone-like Wheel Picker for Selection 340 8.8 Creating a Tabbed Dialog 343 8.9 Creating a PI rogress Dialog 346 8.10 Creating a Custom Dialog with Buttons, Images, and Text 347 8.11 Creating a Reusable about Box Class 349 8.12 Customizing the appearance of a Toast 353 8.13 Creating a Notification in the Status bar 354 9.GU: ListⅰeW∴361 9. 1 Introduction: List view 361 9.2 Building List-Based Applications with ListView 361 9.3 Creating a“ No Data” View for List view 366 9.4 Creating an Advanced List View with Images and Text 367 9.5 USing Section Headers in List Views 372 9.6 Keeping the list View with the User's Focus 376 9.7 Writing a Custom List Adapter 377 9. 8 Handling Orientation Changes: From List View Data values to Landscape Charting 10. Multimedia 387 10.1 Introduction: Multimedia 387 ⅶ ii Table of Contents

...展开详情
试读 127P Android Cookbook
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    抢沙发
    一个资源只可评论一次,评论内容不能少于5个字
    上传资源赚积分,得勋章
    最新推荐
    Android Cookbook 10积分/C币 立即下载
    1/127
    Android Cookbook第1页
    Android Cookbook第2页
    Android Cookbook第3页
    Android Cookbook第4页
    Android Cookbook第5页
    Android Cookbook第6页
    Android Cookbook第7页
    Android Cookbook第8页
    Android Cookbook第9页
    Android Cookbook第10页
    Android Cookbook第11页
    Android Cookbook第12页
    Android Cookbook第13页
    Android Cookbook第14页
    Android Cookbook第15页
    Android Cookbook第16页
    Android Cookbook第17页
    Android Cookbook第18页
    Android Cookbook第19页
    Android Cookbook第20页

    试读已结束,剩余107页未读...

    10积分/C币 立即下载 >