Beginning Android Tablet Programming Starting with Android Honeycomb for Tablets Robbie Matthews CuuDuongThanCong.com 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@springersbm.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 CuuDuongThanCong.com 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 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 iv CuuDuongThanCong.com Contents About the Author xiv About the Technical Reviewer xv Acknowledgments xvi Some Notes on Using the Downloaded Code xvii Chapter 1: Getting Started A Short, Personal History of Portable Programming The Advent of Android .3 Preparing Your Computer Installing Your Development Environment Creating an Emulator Instance Setting Your Path 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 v CuuDuongThanCong.com CONTENTS 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 vi CuuDuongThanCong.com CONTENTS 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 vii CuuDuongThanCong.com CONTENTS 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 viii CuuDuongThanCong.com CONTENTS 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 ix CuuDuongThanCong.com CONTENTS Managing Contacts 161 Loaders 162 Starting a Loader 163 How a Loader Works 163 Why a Loader? 163 The Search Bar 164 Contact Details 166 Editing Data 169 Adding a Phone Number 170 Changing Types 171 And Deleting 172 Summary .173 Chapter 8: Dude, Where’s My Car? .175 Location Manager 175 Location Providers 176 BAT3PGps 176 A Class to Handle the Location Manager 177 Location 181 The Application 183 The Compass 183 Bearing and Distance 185 Are We There Yet? 186 Wakeup Calls 186 Services 187 Notifications 188 Proximity Alerts 190 Proximity Alert Pros and Cons 192 x CuuDuongThanCong.com CONTENTS Lists of Targets 193 Where Was That Again? 197 Where to Go from Here? 198 Summary .198 Chapter 9: Let the Games Begin! 199 Threads 199 Java Threads 200 Android Threads 203 Floater 203 SurfaceView 204 Using Your SurfaceHolder 207 Handlers 207 Using the Handler 208 Running the Game 208 Handling Input 208 Custom Fonts 209 So What’s an Asset? 210 Font Example 212 Menus: A Different Approach 212 Into the Third Dimension! 214 It’s a Box 214 More Interprocess Communication Options 219 Summary .220 Chapter 10: Remind Me 221 Alarms 221 Pending Intents 222 Stopping an Alarm 222 xi CuuDuongThanCong.com CHAPTER 11 EVERYTHING ELSE Figure 11-4 The Download Manager screen Animations Android supports a frankly astonishing number of types of animations, whether it be cartoon-style sprites or complex transformations These can be used to give your interface more sparkle, or just because you like pretty things I’ve included a simple example of a “tweening” animation, which will rotate and scale a single image Listing 11-14 shows the animation activity in its entirety Listing 11-14 Using Animation public class extends S v implements o s o @ protected void super C (s s C (R e( s e ) s e) e) 259 CuuDuongThanCong.com CHAPTER 11 EVERYTHING ELSE ( S g e ) z z s t (this (this R s st t void ese () // s s c X( s c Y( s s ( @ public void o if ( s s s else if e ( ck v) t z ); ( o z X( Y( o { { ) // s z ( F ) s G @ public void o ) E) ( v public void ) y S k c c s r(this); (this) o public void c r s t ) st rt s S k ) ( { Defining an Animation There are a number of predefined Android animations you can use These include , , , and s It’s probably more fun to define your own, and the easy way to , which will be placed in Ê n These animation files that is to create a X Ê offer considerable flexibility Listing 11-15 shows one I prepared earlier Listing 11-15 An Animation Definition s < x /s s 260 CuuDuongThanCong.com s x " " ?> CHAPTER 11 EVERYTHING ELSE e e s " " e s " " v v X Y % " /> < @ s s v v < / " X Y s " " s " " % % " /> > This is more complex than it needs to be, but I got excited A set contains a number of transformations, which can be applied either simultaneously or sequentially depending on your settings What this does is describe an animation that will scale the original item by starting at and going up to 10 times its original size v X and describe the position to scale from—in this case, the center of the image—and o tells it how long to take (in milliseconds) At the same time, and over the same period, the first rotate transformation will be rotating the image 180 degrees The second kicks in after a time delay of 2,000 milliseconds (as defined by s a s ) and applies a counter-rotation back to the right side up Interpolating in Public, No Less Note the o o s I used The transformation command tells the animation what to to the object it is animating, and how long to take The default behavior is to smoothly and evenly proceed from one state to the next, but that can look boring An interpolator describes the rate at which the transformation proceeds The c starts slow and speeds up There’s a c too gets quickly to the end of the transformation, and then bounces back a few times Very pretty Loading Your Animation There is, fortunately, a utility class to make loading your animation easy 261 CuuDuongThanCong.com CHAPTER 11 EVERYTHING ELSE S z (this s s ) This translates your animation file into an animation class Note that if you’ve made an error, this is where it will find it Applying the animation is very simple indeed: s ( S o ) And the animation will start playing Something to bear in mind: when the has finished playing, the in question will pop back to its original state If this is not what you want, you need to detect that the has finished, and something with your image to make it match the new state This is done by adding an s to the : z se s this) In this case, when the animation is done, I use s S and s Y to make the match the scaled image But we’re not done! I decided that just spinning, scaling, and bouncing weren’t enough, so as soon as the first animation ends, I kick off a new one Listing 11-16 shows a different animation, e Listing 11-16 A Fade Animation < < x : c h ?> // e n / p / e / n > s s > v s new < s null s s z ( > k : ( ) { new S () v c c s (k ) ( v c () ") ( y v c s ) s z ( ) 263 CuuDuongThanCong.com CHAPTER 11 EVERYTHING ELSE for (int < e v e s ( for int s " ce v s j < C ( (j) s c o ) \ ") s " if ( () ce( ) e { ") ( ); () c () v c if ( o null) try s s s s C s if Co s Co s() else o Co ( ) { v c ( ) ( ) ( ( s catch ( xc s ( c ) true)) { { else s ( v s o ) Listing 11-18 shows the guts of the program This gets a list of attached devices by calling e e v s () This will return a list of s c s, or if none are attached Each s v c has one or more s c s, and each sb n c has one or more s s Now, the main part of this loop is building a list to be displayed to the user However, I decided that just listing the devices was boring If you look, you can see the code looking for a specific vendor and product These are hardwired at present It may make more sense to make them configurable, but I’ll leave that as an exercise for the reader Setting up a connection to a USB means you need to locate a specific b n In the case of my test device, it has only one interface, and only one sb n p Having located the device you want, and worked out which interface you want, the following lines of code will establish a connection Co if ( o o 264 CuuDuongThanCong.com e c ( ( s v c ) true) CHAPTER 11 EVERYTHING ELSE e returns if it succeeds, at which point you can start talking to the device k s At this point, there are a couple of different ways of transferring data I chose to use But since that is a blocking call, it should be carried out in a separate Listing 11-19 Using a private void c s s s ( class C e s( new to Read from the USB Port { (new s implements C s( ) { @ public void ( { byte new byte // while C null) { int o k s e ( s s if ( > ) s new for(int < ) ( o t(" final S s s s (new R k x s z s v c s ) / « ); x ) () () { @ public void () { o x ( ) ) that listens to the incoming data Now, I also hard-coded the Listing 11-19 shows the incoming buffer size to It would make more sense to use the result from s xP c () Still, it does allow me to keep things clear The roll-up piano has a very basic interface It just streams the state of all the pressed keys in an 8byte bitmap This means I’m only ever really interested in the latest data, so that’s all I display (as a hex string) Responding to USB Events It’s all very well talking to USB devices, but you also need to know when they are plugged in and removed It turns out that responding to an unplugged device is quite easy (see Listing 11-20) 265 CuuDuongThanCong.com CHAPTER 11 EVERYTHING ELSE Listing 11-20 Knowing If Your USB Has Been Unplugged s e e class e e e ( C e new C extends s e public void v s xt(co x c os Co ) ck (null) / e ( ) e e x x oS ) { ) o s ) s ) s As shown in Listing 11-20, it’s just a matter of listening out for a C C C broadcast You’d think you could the same thing with a s C S C C message, but it turns out to be a little more complex You need to have something like Listing 11-21 in s x Listing 11-21 Responding to a USB Device Being Plugged In < v < > > < us « C Listing 11-22 A Simple Device Filter s/x / v v s v /> You will also need an XML file like Listing 11-22 to define the filter I’ve set this to specifically look for my vendor and product ID, but you can set it for general classes, and you could put in a range of IDs This has the advantage of automatically starting the c v when you plug it in It gives you the ability to write and distribute a specific driving application The final result looks like Figure 11-5 266 CuuDuongThanCong.com CHAPTER 11 EVERYTHING ELSE Figure 11-5 The USB example in action That row of numbers down at the bottom corresponds to the map of the pressed keys So, given Android’s media capabilities, it would not take terribly long at all to turn this into a rather cool portable piano app Summary This last chapter has been very much a grab bag of random techniques, things that turned up or were mentioned in other chapters but it didn’t make sense to put there Lots of it had to with s and other multi-processing functions We played with s, using them for timers and many other useful things We looked at the very useful background task manager, s c s , and how to use the We dipped our toes in the turbulent waters of animation And finally, for the mad hackers among you all, we played with the brand new, shiny USB interface And Finally It’s been an interesting trip I learned a lot writing this book, and I certainly hope you learned at least something reading it There’s a lot more stuff you can with Android, but I hope this will have given you a nice solid grounding to move on with Hope to see you again some other book Android: onward and upward! The End 267 CuuDuongThanCong.com Index Numbers and Symbols /sdcard/SL4A/scripts, 100 @+id/editText1, 39 @Override, 24 @string/hello, 9, 32 /platform-tools, 102 A ActionBar, 109–111 ACTION_VIEW, 83–84 Activity, 29 activity android:name, 45 addJavaScriptInterface, 69 Address book See Contacts Alarms AlarmManager object, 222 matching PendingIntent, 222–223 Pending Intents, 222 repeating Alarms, 221 stopping an Alarm, 222 AlertDialog, 119 Alerts, 186 ALTER TABLE, 228 Android program API, 28 application settings, code name, 28 in Eclipse, Hello World program, INI file, 42 layout editor, structure, 27 applications, 35 class definition, 33 computer, 28 Eclipse Package Navigator, 29–30 emulator performance, 36 layout editor, 31–32 lifecycle, 38–41 package name, 32 properties in Java, 38 Save, Run, 34 TextView control, 37 version, 28, 29 Android tablets, 53 creating emulator, development environment installation, 4–5 Linux kernel, setting path, Android Threads, 203 android.app.Activity, 33 android.intent.category.DEFAULT, 48 android.intent.category.LAUNCHER, 45 AndroidManifest.xml file, 48 android.permission.READ_CONTACTS, 70 androidTest.showToast(), 69 Animations definition, 260–261 interpolators, 261 loading, 262 using, 259–260 AnotherClass, 24 ArrayList, 22 AsyncTask accessing main Thread, 252 display a dialog and wait for the result, 253– 254 Future interface, 252–253 method to override, 247 overridden, 249–251 sequence of calls, 248 Strings, 251 using, 248–249 B BA3TPCamera, 63 BA3TPMediaPlayer, 112 Bearing and Distance, 185 269 CuuDuongThanCong.com INDEX block, 11 Bonus Stuff, 75, 76 BroadcastReceiver, 224 Browser assets file, 66, 67 Intent, 64 loading WebView, 65, 66 WebView, 67–69 WebView Control, 65 Build.VERSION, 84 C Camera, 63–64 Canvas.rotate method, 185 classVariable, 15–17 com.android.browser.BrowserActivity, 47 com.apress.ba3tp.hello, 21 com.apress.ba3tp.testintents.ActivityOne, 45 Comparator, 141 Compass, 183–185 Contact manager, 151 adding a phone number, 170–171 application, 162 changing phone types, 171–172 contact details, 166–169 deleting data, 172–173 editing data, 169–170 loaders, 162–164 search bar, 164–166 Contacts accessing, 69–71 accessing information from query, 74–75 displaying of lists, 72–74 Contacts.CONTENT_URI, 74 ContactsContract class, 166 ContentFragment, 117 ContentResolver, 70 CountDownLatch, 253 CREATE TABLE, 228 D Dalvik virtual machine, Delete, 240 2D and 3D graphical game techniques, 199 doInterface, 25 Download Manager, 254 in action, 255 270 CuuDuongThanCong.com query columns returned from, 257 possible values of Status, 258 Query object, 257 view downloads, 258 screen, 259 start downloading using, 255, 256 E EditText mEditText1, 41 E-mail, 76–77 explicit Intent, 44 Explorer, 123 in action, 124 ActionBar, 142 Activity OnCreate Code, 143 array into a list, 129 behaviors, 148 Context menu, 144 dating your file, 133 dialogs, 145 Paste dialog, 147 Prompt dialog, 147 selection of, 145 error handling, 129 file permissions, 133–137 finding information about your file, 130–132 Inflation service, 128 ListActivity, 124, 125 ListAdapter, 126, 128 MIME types, 133 populating list of files, 128, 129 preference PreferenceScreen, 137–139 reading, 139–140 resources, 125–126 responding to a Context menu, 145 responding to a list selection, 142 sorting techniques, 141 F Fade Animation, 262 File Ỉ New ỈProject ỈAndroid Project on Mac, Floater in action, 204 asset, 210–211 custom fonts, 209–210 INDEX font example, 212 Handlers, 207–208 handling input, 208 Menus, 212–213 running game, 208 SurfaceView, 204–207 FontMetrics, 184 Fragment ActionBar, 109–111 basic layout, 106 code, 108–109 definition, 105 FragmentManager, 111 layout in portrait mode, 107 onCreate method, 109 simple layout, 107–108 fred, 17 Future interface, 253 G Games 2D and 3D graphics, 199 Floater See Floater graphics See Three dimensional graphics running the, 208 Threads See Threads GameSurface, 205–207 GameSurfaceGl, 219 Genma backward compatibility, 157 concept, 152 dialogs, 160–161 gravity property, 153–154 import and export mechanism, 159–160 Layout File, 153 list handling, 158 resizing text, 154–155 reusing your libraries, 159 saving the list, 158–159 Signboards, 152 Window Focus Event, 156 Geocoder, 180 getCacheDir(), 211 getDefaultSharedPreferences, 41 GlSurfaceView, 216–219 Goldfish 3-axis Accelerometer (1) 3.0mA, 58 GPS, 175 Bearing and Distance, 185 Compass, 183–185 Lists of Targets See Target Location Manager See Location Manager maps, 197–198 Notifications, 188 Proximity Alerts See Proximity Alerts Services, 187 Wakeup Calls, 186 GroupMembership, 169 H HashTable and HashMap, 21 HAS_PHONE_NUMBER, 74 hello.ba3tp.apress.com, 21 Hello2Main.java, 30, 32 Hello Universe, Honeycomb emulator, I IdentityHashMap, 23 implicit Intents, 42–43 Intent Activities, 44–47 common intents, 48 explicit, 42 filters, 47–48 implicit, 42 view PDF file, 43 Intent.ACTION_VIEW, 43, 64 Intent.addCategory, 47 Intent.FLAG_ACTIVITY_NEW_TASK, 86 interpolators, 261 J, K Java, annotation, 25 constructors and initializers, 17–18 escape codes, 57 file handling, 26 flow control, 12–13 generics, 23–24 Hello World program, 10–11 inheritance, 24 interface, 25 Java IDEs, 10 lists and maps, 22, 23 object-oriented (OO) language, 10 271 CuuDuongThanCong.com INDEX Java (cont.) objects, 13–17 overloading, 19 packages, 21 primitives, 12 streams and readers, 50–51 string handling, 20 structure, 11–12 synchronization, 26 varargs, 248 Java Threads example, 200–202 stopping darn things, 203 synchronizing threads, 202 Javathread handling, 26 playing media, 117 querying media files, 115 responding to clicks, 115 MediaStore.ACTION_VIDEO_CAPTURE, 64 MediaStore.Audio.Media.EXTERNAL_CONTENT _URI, 115 mEditText, 147 mSqlDateFmt, 235 mymethod, 19 MyThread, 202 L O LinearLayout, 32 LinkedList, 22 Linux, 49–51 ListAdapter, 72 LocationHandler, 178–180 Location Manager BAT3PGps, 176 context, 175 Location, 181, 182 LocationHandler class, 178–180 Location Providers, 176 properties of Location Provider, 180 Logcat, 36 Object-oriented programming (OOP), 13 onBackPressed, 73 onClick method, 25 onPageLoaded, 69 onPrepareDialog, 119 onPressClick, 31 onResume, 41 OnTouchListener, 209 OO language, 14 Open Handset Alliance, M package com.apress.ba3tp.hello2, 40 PackageManager, 132 PendingIntent, 189, 192 Portable programming, 1–2 Proximity Alerts adding, 190 Pros and Cons, 192–193 ProximityIntentReceiver Class, 191 ProximityIntentReceiver, 192 public static final field, 17 Purge, 240 Python, 79 See also Script management PythonMain Activity, 48 Maps, 197–198 Math.toDegrees(), 62 mCount, 46 Media files, 77 Media player, 105 ActionBar, 115, 116 advanced media playing, 120 changing a list cursor, 120 control media files, 122 dialog box, 118, 119 displaying list, 114 displaying playing media, 121 in action, 113 ListFragment, 113, 114 media sources, 118 Media URI, 116, 117 272 CuuDuongThanCong.com N NewClass, 24 Notifications, 188–190 P, Q R RatingBar, 111 rawQuery, 230 INDEX Reflection, 133, 137 remapCoordinateSystem, 62 Remind Me, 221 Alarms List Manager, 237, 238 manipulating Alarms Table, 239 contacts, 233, 234 enhancing the application, 241 main screen, 231, 232 onscreen keyboard, 232, 233 responding to Alarm, 235–237 setting Reminder Alarm, 234, 235 testing TTS, 240, 241 Runnable, 244 S savedInstanceState, 33 scaledDensity, 155 Scripting Layer for Android (SL4A), 79, 80 See also Script management Script management, 80 battery management, 97–99 contacts and phone numbers, 102– 103 control phone settings, 94–95 editing, 100–101 events, 89–90 Facades, 82–83 hello_world script, 81 Intent, 83–86 location function, 95–97 media files, 91–94 Prompt, and Help, 82 Python help system, 82 sample programs, 81 SQL, 103 user interaction, 86–88 WakeLock commands, 99–100 SeekBar, 121, 122 SENSOR_DELAY_NORMAL, 59 Sensors accessing SensorManager, 56 Button Click Events, 60 getting orientation, 61–62 onListClick Event, 56 Portrait Mode, 61 screen layout, 54–55 SensorEventListener, 58 testing, 55 types, 54 Values, 60–61 Services, 187–188 Share My Stuff, 75–77 SharedPreferences, 41 shouldOverrideUrlLoading, 69 SimpleCursorAdapter, 114 SMS receiving, 224 sending, 223–224 SmsManager, 223 SmsReceiver, 225 SQLite creating database, 228 definition, 227 getting database, 229 using database, 229, 230 SQLite3, 104 SQLiteOpenHelper, 228 startActivityForResult, 64 static member, 14, 15 staticVariable, 15, 17 StringBuffer and StringBuilder, 21 SurfaceHolder, 121, 204–207 swapCursor, 120 T Target code for ManageList, 195–196 edit dialog, 196–197 TableLayout, 194–195 Target class, 193–194 target editor, 196 TextPaint, 155 Text To Speech (TTS) queues, 227 SMSReceiveService Class, 225–226 TextView, 32 Threads Android Threads, 203 concepts of, 199 Java Threads, 200–203 Three dimensional graphics BA3TPOpenGl, 214 GLSurfaceView implementation, 215 initializing 3D environment, 216, 217 interprocess communication, 219, 220 273 CuuDuongThanCong.com INDEX Three dimensional graphics (cont.) MainActivity for 3D demo, 216 MainActivity onCreate event, 219 onDrawFrame event, 218 onSurfaceChanged event, 218 onSurfaceCreated event, 217 spinning box, 214 TickerText, 188 Timers, 243 Handler, 244 Handler.postAtTime with token, 246 Handler.PostDelayed, 245 implementing real-time clock, 245, 246 stopping gracefully, 246 Toast, 34 toString(), 24 Touch Events, 209 TreeMap IdentityHashMap, 22 Tricorder, 54 274 CuuDuongThanCong.com U Uri.withAppendedPath, 117 USB, 262 device filter, 266 in action, 267 list of devices, 263–264 responding to a plugged device, 266 responding to an unplugged device, 265–266 simple activity, 263 Thread to read from, 265 V varargs, 248 W, X, Y, Z Wakeup Calls, 186 WeakHashMap, 23 ... written permission of the copyright owner and the publisher ISBN-13 (pbk): 97 8-1 -4 30 2-3 78 3-9 ISBN-13 (electronic): 97 8-1 -4 30 2-3 78 4-6 Trademarked names, logos, and images may appear in this book... [201 1-0 4-0 3 00:35:19 - BA3TPHello2] New emulator found: emulator-5554 [201 1-0 4-0 3 00:35:19 - BA3TPHello2] Waiting for HOME ('android.process.acore') to be launched [201 1-0 4-0 3 00:36:28 - BA3TPHello2]... something like the following: [201 1-0 4-0 3 00:35:11 - BA3TPHello2] Android Launch! [201 1-0 4-0 3 00:35:11 - BA3TPHello2] adb is running normally [201 1-0 4-0 3 00:35:11 - BA3TPHello2] Performing com.apress.ba3tp.hello2.Hello2Main