Contents

About the Authors xv

About the Technical Reviewer xvii

Acknowledgments xix

Introduction xxi chapter 1 Introducing the Android Computing Platform 1

History of Android 3

Delving into the Dalvik VM 4

Comparing Android and Java ME 5

Understanding the Android Software Stack 8

Developing an End-User Application with the Android SDK 9

The Android Emulator 9

The Android UI 10

The Android Foundational Components 11

Advanced UI Concepts 12

Android Service Components 13

Android Media and Telephony Components 14

Android Java Packages 15

Taking Advantage of Android Source Code 18

Summary 19

chapter 2 Getting Your Feet Wet 21

Setting Up Your Environment 21

Downloading JDK 6 and Eclipse 3.4 21

Downloading the Android SDK 22

Installing Android Development Tools (ADT) 22

Learning the Fundamental Components 24

View 24

Activity 24

Intent 24

Content Provider 25

Service 25

AndroidManifest.xml 25

Hello World! 25

Exploring the Structure of an Android Application 28

Analyzing the Notepad Application 30

Loading and Running the Notepad Application 31

Dissecting the Application 31

Examining the Application Lifecycle 38

Debugging Your App 41

Summary 42

chapter 3 Using Resources, Content Providers, and Intents 43

Understanding Resources 43

String Resources 43

Layout Resources 45

Resource-Reference Syntax 47

Defining Your Own Resource IDs for Later Use 48

Compiled and Noncompiled Android Resources 48

Enumerating Key Android Resources 49

Working with Arbitrary XML Resource Files 57

Working with Raw Resources 58

Working with Assets 59

Reviewing the Resources Directory Structure 60

Understanding Content Providers 60

Exploring Android's Built-in Providers 61

Architecture of Content Providers 67

Implementing Content Providers 79

Understanding Intents 91

Available Intents in Android 92

Intents and Data URIs 94

Generic Actions 95

Using Extra Information 96

Using Components to Directly Invoke an Activity 97

Best Practice for Component Designers 99

Understanding Intent Categories 99

The Rules for Resolving Intents to Their Components 102

Exercising the ACTION_PICK 102

Exercising the GET_CONTENT Action 104

Summary 106

chapter 4 Building User Interfaces and Using Controls 107

UI Development in Android 107

Understanding Android's Common Controls 113

Text Controls 113

Button Controls 117

List Controls 122

Grid Controls 126

Date and Time Controls 128

Other Interesting Controls in Android 130

The MapView Control 130

The Gallery Control 130

Understanding Layout Managers 131

The LinearLayout Layout Manager 131

The TableLayout Layout Manager 134

The RelativeLayout Layout Manager 139

The AbsoluteLayout Layout Manager 141

The FrameLayout Layout Manager 143

Customizing Layout for Various Screen Configurations 145

Understanding Adapters 146

Getting to Know SimpleCursorAdapter 146

Getting to Know ArrayAdapter 147

Creating Custom Adapters 148

Debugging and Optimizing Layouts with the Hierarchy Viewer 149

Summary 150

chapter 5 Working with Menus and Dialogs 151

Understanding Android Menus 151

Creating a Menu 153

Responding to Menu Items 154

Creating a Test Harness for Testing Menus 156

Working with Other Menu Types 163

Expanded Menus 163

Working with Icon Menus 163

Working with Submenus 164

Provisioning for System Menus 165

Working with Context Menus 165

Working with Alternative Menus 168

Working with Menus in Response to Changing Data 172

Loading Menus Through XML Files 172

Structure of an XML Menu Resource File 172

Inflating XML Menu Resource Files 173

Responding to XML-Based Menu Items 174

A Brief Introduction to Additional XML Menu Tags 175

Using Dialogs in Android 176

Designing an Alert Dialog 177

Designing a Prompt Dialog 179

Nature of Dialogs in Android 184

Rearchitecting the Prompt Dialog 185

Working with Managed Dialogs 186

Understanding the Managed-Dialog Protocol 186

Recasting the Nonmanaged Dialog as a Managed Dialog 186

Simplifying the Managed-Dialog Protocol 188

Summary 196

chapter 6 Unveiling 2D Animation 197

Frame-by-Frame Animation 198

Planning for Frame-by-Frame Animation 198

Creating the Activity 199

Adding Animation to the Activity 201

Layout Animation 204

Basic Tweening Animation Types 204

Planning the Layout-Animation Test Harness 205

Creating the Activity and the ListView 206

Animating the ListView 209

Using Interpolators 212

View Animation 213

Understanding View Animation 214

Adding Animation 216

Using Camera to Provide Depth Perception in 2D 220

Exploring the AnimationListener Class 221

Some Notes on Transformation Matrices 222

Summary 223

chapter 7 Exploring Security and Location-Based Services 225

Understanding the Android Security Model 225

Overview of Security Concepts 226

Signing Applications for Deployment 226

Performing Runtime Security Checks 229

Understanding Security at the Process Boundary 229

Declaring and Using Permissions 230

Understanding and Using Custom Permissions 232

Working with Location-Based Services 238

Understanding the Mapping Package 238

Understanding the Location Package 249

Summary 262

chapter 8 Building and Consuming Services 263

Consuming HTTP Services 263

Using the HttpClient for HTTP GET Requests 264

Using the HttpClient for HTTP POST Requests 266

Dealing with Exceptions 269

Addressing Multithreading Issues 272

Doing Interprocess Communication 276

Creating a Simple Service 276

Understanding Services in Android 277

Understanding Local Services 278

Understanding AIDL Services 282

Defining a Service Interface in AIDL 283

Implementing an AIDL Interface 286

Calling the Service from a Client Application 288

Passing Complex Types to Services 292

Summary 300

chapter 9 Using the Media Framework and Telephony APIs 301

Using the Media APIs 301

Understanding the setDataSource Method 305

Playing Video Content 307

Understanding the MediaPlayer Oddities 311

Exploring Audio Recording 311

Using the Telephony APIs 316

Working with SMS 316

Working with the Telephony Manager 323

Summary 324

chapter 10 Programming 3D Graphics with OpenGL 325

Understanding OpenGL 326

OpenGL ES 327

OpenGL ES and Java ME 327

M3G: Another Java ME 3D Graphics Standard 328

Using OpenGL ES 328

Essential Drawing with OpenGL ES 329

Understanding the Camera and Coordinates 334

Interfacing OpenGL ES with Android 338

Creating and Using the OpenGL Test Harness 342

Designing the Test Harness 343

OpenGLTestHarnessActivity.java 345

OpenGLTestHarness.java 346

OpenGLDrawingThread.java 348

EglHelper.java 352

Renderer.java 354

AbstractRenderer.java 354

SimpleTriangleRenderer.java 355

Changing Camera Settings 358

Using Indices to Add Another Triangle 360

Summary 362

chapter 11 Managing and Organizing Preferences 363

Exploring the Preferences Framework 363

Understanding CheckBoxPreference 367

Understanding EditTextPreference 370

Understanding RingtonePreference 371

Organizing Preferences 373

Summary 376

chapter 12 Coming to Grips with 1.5 377

Installing the ADT Plug-in for Android 1.5 Development 377

Getting Started with Android 1.5 379

Creating an Android Virtual Device 383

Exploring Improvements to the Media Framework 384

Using the MediaRecorder Class for Video Capture 385

Exploring the MediaStore Class 386

Scanning the Media Store for Media Content 390

Exploring Voice Recognition 392

Introducing the Input-Method Framework 394

Summary 394

chapter 13 Simplifying OpenGL and Exploring Live Folders 395

Simplifying OpenGL 396

Reimplementing the Simple Triangle OpenGL Drawing 398

OpenGL Animation Example 401

Exploring Live Folders 404

How a User Experiences Live Folders 405

Building a Live Folder 410

The Future of Android and the 1.5 SDK 421

Key Online Resources for the 1.5 SDK 423

Summary 424

INDEX 425

0 0

Post a comment