1. Trang chủ
  2. » Công Nghệ Thông Tin

Beginning Android Tablet Programming potx

288 264 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 288
Dung lượng 4,89 MB

Nội dung

www.it-ebooks.info Beginning Android Tablet Programming Starting with Android Honeycomb for Tablets               Robbie Matthews www.it-ebooks.info Beginning Android Tablet Programming: Starting with Android Honeycomb for Tablets Copyright © 2011 by Robbie Matthews 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-3783-9 ISBN-13 (electronic): 978-1-4302-3784-6 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Steve Anglin and Tom Welsh Technical Reviewer: Stephen Bull and Peter Brownlow Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Morgan Engel, Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh Coordinating Editor: Anita Castro Copy Editor: Mary Ann Fugate Compositor: Bytheway Publishing Services Indexer: SPI Global Artist: SPI Global Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 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/bulk-sales. 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. www.it-ebooks.info I dedicate this book to my family. Without your support and occasional nagging this book would never have been finished. Robbie Matthews www.it-ebooks.info iv Contents at a Glance  About the Author xiv  About the Technical Reviewer xv  Acknowledgments xvi  Some Notes on Using the Downloaded Code xvii  Chapter 1: Getting Started 1  Chapter 2: How Android Works 27  Chapter 3: What Can You Do with an Android Tablet? 53  Chapter 4: Beyond Java: Programming in Python and Friends 79  Chapter 5: Project 1: Media Player 105  Chapter 6: Explorer 123  Chapter 7: Contact Manager 151  Chapter 8: Dude, Where’s My Car? 175  Chapter 10: Remind Me 221  Chapter 11: Everything Else 243  Index 269 www.it-ebooks.info v Contents  About the Author xiv  About the Technical Reviewer xv  Acknowledgments xvi  Some Notes on Using the Downloaded Code xvii  Chapter 1: Getting Started 1 A Short, Personal History of Portable Programming 1 The Advent of Android 3 Preparing Your Computer 4 Installing Your Development Environment 4 Creating an Emulator Instance 5 Setting Your Path 6 Your First Android Program 6 Oh, No! Java! 9 A Quick Guide to Java 10 Structure 11 Primitives 12 Flow Control 12 Objects 13 Constructors, Initializers, and Overloading 17 Where’s “Free”? 19 String Handling 20 www.it-ebooks.info  CONTENTS vi Packages 21 Lists and Maps 22 Generics 23 Inheritance and Interfaces 24 Annotations 25 And Many More 26 Summary 26  Chapter 2: How Android Works 27 Basic Structure of Android Programs 27 Lifecycle 38 Intents: What, Where, Why, and Are They Honorable? 42 Intent Filters 47 Common Intents 48 Finally 48 Secretly Linux 49 Summary 51  Chapter 3: What Can You Do with an Android Tablet? 53 More Sensors Than the CIA 54 Lights, Camera, Action 63 Browsing for Fun and Profit 64 Managing Your Assets 66 Getting Fancy 67 My Little Black Book—Managing Contacts 69 Accessing Contacts 69 A Quick Side Trip into Lists 72 Different Things to Access 74 www.it-ebooks.info  CONTENTS vii Share My Stuff (Sending and Receiving, Well, Everything) 75 Bonus Stuff—Menu Options 75 Sending E-mail 76 Sound and Fury (Managing Media Files) 77 Summary 78  Chapter 4: Beyond Java: Programming in Python and Friends 79 Why Use Another Language? 80 Getting Started 80 Script Management 80 Help! I Need Somebody 82 Python Help 82 What’s a Facade? 82 Intents (Again) 83 Different Ways of Using the Intent Methods 84 User Interaction 86 Events 89 Media Files 91 Controlling Your Phone 94 Where Am I? 95 Battery 97 Keeping the Device Awake 99 Editing Tips 100 Contacts and Phone Numbers 102 SQL 103 More Stuff 104 Summary 104 www.it-ebooks.info  CONTENTS viii  Chapter 5: Project 1: Media Player 105 Fragments 105 What’s a Fragment? 105 Examining the Example 106 The ActionBar 109 FragmentManager 111 Media Player Application 112 Displaying a List from a Cursor 114 Querying Media Files 115 Responding to Clicks 115 Some More on the ActionBar 115 Menu 116 Getting a Media URI 116 Playing Media 117 Different Media Sources 118 Dialog Boxes 118 Changing a List Cursor 120 Advanced Media Playing 120 Displaying Our Progress 121 Controlling Our Progress 122 Summary 122  Chapter 6: Explorer 123 Anatomy of a File Explorer 123 ListActivity for Fun and Profit 124 A Note on Resources 125 Build Your Own List Adapter 126 Inflation 128 Populating the List 128 www.it-ebooks.info  CONTENTS ix Finding Out About Your File 130 Learning to Mime 133 Dating Your File 133 Going Native 133 State Your Preference 137 Reading Your Preferences 139 Sorting Techniques 141 The Actual Activity 141 Reacting to a List Selection 142 Creation at Last 143 A Different Menu 144 Reacting to a Context Menu 144 Dialogs 145 A Few Last Bits 148 Making It Better 149 Summary 149  Chapter 7: Contact Manager 151 And Now for Something Completely Different 152 The Application 152 Anatomy of a Signpost 152 Knowing When the View Is Available 156 Room for Improvement 156 Backward Compatibility 157 List Handling 158 Saving the List 158 Reusing Your Libraries 159 Import and Export 159 A Last Note on Dialogs 160 www.it-ebooks.info [...]... the Android SDK: a b Browse to where you installed the Android SDK (i.e., c:\program files \android\ android-sdk for windows, or /Developer /android- sdkmac_x86) c 8 Window ➤ Preferences ➤ Android Apply ➤ OK Load the platforms a Window ➤ Android SKD and AVD Manager b Click Available Packages There’s no real reason not to just download everything under Android Repository, but as a minimum you’ll want the Android. .. www.it-ebooks.info CHAPTER 1   GETTING STARTED Preparing Your Computer You’ll need a programming environment to start programming your Android tablet This will involve downloading the Java Development Kit (JDK), the Eclipse IDE (Integrated Development Environment), and the Android Software Development Kit (SDK) The Android SDK is written primarily in Java, although it does have a few native code extensions... to the world of programming the Android tablet In this chapter, I’ll introduce you to the basics of setting up your programming environment I’ll walk you through your first Android program, and we’ll even take a run through the world’s quickest introduction to Java But first: a slightly self-indulgent history of the world of handheld computing A Short, Personal History of Portable Programming Handheld... actual paths will depend on where you installed your Android SDK Your First Android Program Let’s get down to business our first actual Android program Fire up Eclipse, and we’ll create our first Android Hello World program This is going to be pretty easy File ➤ New ➤ Android Project should look something like Figure 1-2 Figure 1-2 Creating a new Android project in Eclipse 6 www.it-ebooks.info CHAPTER... Android development files To set this up, right-click BA3TPUtils, and then go to the following: Build Path Ê Add External Archive Navigate to the following: /platforms/ /android. jar For example, on my Windows computer, that is as follows: xvii www.it-ebooks.info   SOME NOTES ON USING THE DOWNLOADED CODE C:\Program Files (x86) \Android\ android-sdk\platforms \android- 11 \android. jar... a personal data assistant, or PDA And this is an important thing to remember about programming for a mobile device Keep it simple, avoid bloat, and concentrate on usability Pay attention, because this will appear on the snap quiz later 1 I was, and still am, a geek And proud of it! R Matthews, Beginning Android Tablet Programming © Robbie Matthews 2011 www.it-ebooks.info 1 CHAPTER 1   GETTING STARTED... some powerful tools that come with the Android SDK The one you are most likely to be using is adb, which is a command line tool Make sure platform-tools is in your path before you try using it— for example: Windows: PATH=%PATH%;C:\Program Files \Android\ Android-SDK\platform-tools Linux: export PATH=$PATH:~ /android- sdk/platform-tools Mac: export PATH=$PATH:~/Developer /android- sdk-mac_x86/platform-tools Your... only with the release of Android 3.0 (Honeycomb) that we have a version that takes full advantage of the expanded capabilities of a full-sized tablet Which brings us to the whole point of this book Figure 1-1 Programming tablets used to be much more difficult Let’s get straight down to brass tacks By the time you finish this chapter, you should be running your first genuine Android program 3 www.it-ebooks.info... http://developer .android. com/sdk/installing.html 2 Follow instructions 3 Start programming! Actually, it is almost as simple as that, and, given the rate at which Android is being updated, you should take that as the definitive version However, while this is pretty simple, there are a few traps and tricks for young players, so I will expand 1 Make sure your computer is up to spec See http://developer .android. com/... the Android SDK from http://developer .android. com/sdk/index.html 5 Start Eclipse If you’ve done this in the right order, Eclipse should be able to find the JDK for itself If not, you may have to tell Eclipse where to find it manually 6 Install the ADT (Android Developer Tools) a In Eclipse, go to Help ➤ Install New Software ➤ Add b Enter ADT Plugin as the Name field c Enter https://dl-ssl.google.com /android/ eclipse/ . www.it-ebooks.info Beginning Android Tablet Programming Starting with Android Honeycomb for Tablets               Robbie.  Robbie Matthews www.it-ebooks.info Beginning Android Tablet Programming: Starting with Android Honeycomb for Tablets Copyright © 2011 by Robbie Matthews

Ngày đăng: 17/03/2014, 19:20

TỪ KHÓA LIÊN QUAN