did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9781118026434

Professional Android Programming with Mono for Android and . NET/C#

by ; ; ; ;
  • ISBN13:

    9781118026434

  • ISBN10:

    1118026438

  • Format: Paperback
  • Copyright: 2012-04-03
  • Publisher: Wrox
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $44.99

Summary

Using the proven Wrox Professional format, Professional#xA0;Android Programming with MonoDroid#xA0;and .NET/C# provides experienced .NET and C# developers with the knowledge the need to become#xA0;successful#xA0;Android application developers without having to learn another language. Professional Android Programming with MonoDroid and .NET/C# covers : MonoDroid and MonoDevelop Screen controls, UI development Data controls, windows, and controllers Working with data, REST, SOAP, XML, and JSON Tables and layouts Maps, Geolocation, Geocoding, and MonoDroid Device feature support for networking, battery, accelerometer, orientation, and proximity Multimedia, pictures, video, and audio recording and playback Communicating with other applications Internationalization and Localization Deploying apps, and making money #xA0;

Author Biography

Wallace B. McClure is a Microsoft MVP, ASPInsider, and member of the national INETA Speaker's Bureau, and has a popular blog and podcast.

Nathan Blevins is an ASPInsider, a public speaker, and blogs at http://nathanblevins.com.

John J. Croft IV is an author, developer, and senior technical manager for Turner Broadcasting System in Atlanta.

Jonathan Dick develops mobile applications, maintains and contributes to several open source projects for mobile, and blogs about it all at http://redth.info.

Chris Hardy, a Microsoft ASPInsider, is a .NET consultant focusing on MonoTouch and Mono for Android development and tweets @chrisntr.

Table of Contents

FOREWORD xxiii

INTRODUCTION xxv

CHAPTER 1: INTRODUCTION TO ANDROID, MOBILE DEVICES, AND THE MARKETPLACE 1

Product Comparison 2

The .NET Framework 2

Mono 3

Mono for Android 4

Mono for Android Components 5

Development Tools 6

Mobile Development 6

Getting Around Support Issues 7

Design Issues 7

Android 8

History of Android 8

Writing Web-Based Applications for Android 9

Writing Native Applications for Android 9

Android Development Issues 9

Android SDK Tools 10

Android Development Costs 11

Cross-Platform Alternatives 12

Other Cross-Platform Tools 12

Considerations for Selecting a Cross-Platform Tool 12

How Does the Tool Allow You to Author Your Application? 13

What Device Features Does the Tool Support? 13

What Platforms Does the Tool Support? 14

What Skill Sets Does the Tool Require? 14

What Tools Exist to Support Development? 14

How Active Are the Development Community and Support Channels? 14

What Are the Successful Application Deployments for This Tool? 14

Summary 15

CHAPTER 2: INTRODUCTION TO MONO FOR ANDROID 17

Before You Begin Developing 17

What Is Mono? 17

Mono Implementation Goals 18

Mono Standards 18

What Is Mono for Android? 18

Why Do I Need Mono for Android? 18

Familiar Development Environment 19

Familiar API and Library Structure 19

What Are the Trade-Off s of Working with Mono for Android? 21

Waiting for Improvements 21

Taking a Potential Performance Hit 21

Memory Management 21

What Do I Need for the Mono for Android Development Environment? 22

Java SDK 22

Android SDK 22

Visual Studio 24

Visual Studio Development with Mono for Android 25

General Setup 25

Building Hello Android 26

Logging 28

Debugging 30

Testing 30

Deploying 31

Mono for Android Development with MonoDevelop 31

General Setup 31

Building Hello Android 32

Logging 34

Debugging 34

Testing 34

Deploying 35

Summary 35

CHAPTER 3: UNDERSTANDING ANDROID/MONO FOR ANDROID APPLICATIONS 37

What Is an Android Application? 38

The Building Blocks of an Android Application 39

Activities 39

Services 44

Content Providers 44

Broadcast Receivers 47

Communicating between Components: Android Intents 49

Binding the Components: The Android Manifest 50

Android Manifest Basics 51

Editing the Manifest for Mono for Android via Visual Studio 54

Summary 56

CHAPTER 4: PLANNING AND BUILDING YOUR APPLICATION’S USER INTERFACE 59

Guidelines for a Successful Mobile UI 59

Building an Android UI 60

Views 60

Design Surface 61

Choosing a Control Layout 61

AbsoluteLayout 62

FrameLayout 63

LinearLayout 63

RelativeLayout 65

TableLayout 67

Optimizing Layouts 68

Designing Your User Interface Controls 69

TextView 70

EditText 70

AutoCompleteTextView 71

Spinner 71

Button 73

Check Box 73

Radio Buttons and Groups 73

Clocks 76

Pickers 77

Images 79

ImageView 80

ImageButton 80

Gallery 80

Virtual Keyboards 84

Selecting Your Virtual Keyboard 86

Removing the Keyboard 86

Controlling Your Menus 87

Introducing the Menu System 87

Menus 87

Submenus 90

Context Menus 90

Defi ning Menus as a Resource 92

Menus 93

Context Menus 94

Resolution-Independent UI 95

Supporting Various Screen Resources 95

Supporting Screen Sizes 95

Supporting Pixel Densities 96

Using Android Market Support 97

Multiple Screen Resolution Best Practices 97

Constructing a User Interface: A Phone and Tablet Example 98

Summary 104

CHAPTER 5: WORKING WITH DATA 105

Working with SQLite 105

Setting Up a Database 106

Setting Up Tables 107

Using SQL Statements 108

Using Read/Select to Read Data 108

Using SQL Statements to Insert Data 110

Upgrading Strategies 110

Upgrading in Place 111

Copying Data 111

Android-Specific Database Options 111

SQLiteOpenHelper 111

Storing Data Remotely 113

Working with Remote Data 113

Accessing Enterprise Services 114

Using SOAP 115

Working with ASMX Web Services 115

Working with Windows Communication Foundation (WCF) 116

Using REST-Based Web Services 119

Using JavaScript Object Notation (JSON) 120

Posting Data with POST 124

Retrieving Data Using LINQ and XML 125

Using Asynchronous Data Retrieval 127

Using Web Services Responsibly 128

Working with Remote SQL Server Databases 128

Summary 130

CHAPTER 6: BINDING DATA TO CONTROLS 131

Databinding in Mono for Android 132

What Is a Data Adapter? 133

What Is an Adapter View? 133

How Do These Items Relate to One Another? 134

Working with Adapter Views and Large Data Sets 134

Exploring Adapters in Depth 137

Using Native Adapters 137

Exploring Adapter Views in Depth 138

Using Native Adapter Views 138

Working with Cursors 139

Using a Cursor to Populate a Spinner 139

Setting Up the Spinner and Data Source 140

Using a Spinner Adapter 143

Adding a Listener Event for a Spinner 144

Using a Cursor with a Gallery 147

Setting Up the Project 148

Adding the Cursor 150

Completing the Custom Adapter 152

Working with Lists 154

Displaying Simple Data in a List 155

Working with Android’s ListAdapters 158

Customizing ListView with a Custom List Adapter 160

Handling ListView Events 166

Preferences Screen 168

Nested Navigation 171

Grouped Lists 173

Displaying Data in a Grid 177

Summary 182

CHAPTER 7: WORKING WITH THE FILE SYSTEM AND APPLICATION PREFERENCES 183

Working with the File System 184

File System Type and Structure 184

QuickEdit Sample Program: Working with a File Storage Example 189

Working with Application Preferences 195

Application Preference Types 195

Creating Your Own Application Preferences 196

Preferences Program 197

Listening for Preference Changes 202

Processing XML 204

Summary 205

CHAPTER 8: PROGRAMMING WITH THE DEVICE HARDWARE 207

Working with Sensors 208

Referencing the Sensor Manager 208

Sensor Support 208

Accessing Sensors 209

Using Sensors 209

Understanding the Sensor Type Values 211

Responding to Acceleration 212

Using the XYZ Coordinate System 213

Coding with the Accelerometer 213

Building a Compass 214

Vibration 218

Networking Connectivity 219

ConnectivityManager 219

Checking User Communication Preferences 219

Checking for Changes to BackgroundDataSetting 220

Checking Current Network Configuration 221

Creating Network Connectivity Notifications 221

Wifi Manager 221

WiFi States 224

WiFi Changes 225

Bluetooth Manager 225

Working with Bluetooth State 226

Enabling Voice Recognition in Your App 227

Getting Turn-by-Turn Directions 229

Summary 235

CHAPTER 9: USING MULTIMEDIA — AUDIO, VIDEO, AND THE CAMERA 237

Android Media Classes 238

Playing Audio and Video 239

Media Player Supported Formats 239

Programming Audio Playback 240

Programming Video Playback 244

Controlling Playback 247

Managing Playback Output 247

Recording Audio and Video 247

Using Intents to Record Video 248

Using the Media Recorder 251

Confi guring Video Recording 251

Previewing Video Recording 252

Audio Recording 253

Images and Using the Camera 254

Using Intents to Take Pictures 254

Controlling the Camera 257

Managing Camera Settings and Picture Options 257

Monitoring Autofocus 259

Using the Camera Preview 260

Taking a Picture 261

Reading and Writing JPEG Exif Values 262

Adding New Media to the Media Store 263

Using the Media Scanner 263

Adding New Media to the Store 264

Speech Recognition 265

Summary 266

CHAPTER 10: TALKING TO OTHER APPLICATIONS AND LIBRARIES 269

Android Application Integration 269

Opening the Browser 269

Opening E-mail 272

Making a Telephone Call 273

Sending a Text/SMS Message 274

Opening a Location in the Maps Application 276

Opening a YouTube Video 276

Opening the Market 277

Application Integration 278

Simple Integration with HootSuite and Other Twitter Applications 279

Configuring Your Intent Filters 279

Handling Incoming Intent Requests 280

Integrating with Contacts 280

Displaying Contact Details 283

Picking a Contact 284

Creating a New Contact 285

Creating a New Contact or Adding to an Existing Contact 286

Summary 287

CHAPTER 11: DEVELOPING BACKGROUND SERVICES AND ASYNCHRONOUS CODE 289

The Life Cycle of a Service 290

Creating Your First Service 290

Prioritizing Services 293

Using Threads for Asynchronous Processing 294

Threading Manually 295

Utilizing System.Threading.Tasks 297

Implicit Threading with the IntentService 298

Communicating with the UI 299

Using the Binder and Service Connection Method 299

Using the Broadcast Receiver Method 303

Using the Static Event Method 305

Notifying the User with Notifications 308

Scheduling Intents with Alarms and the IntentService 310

Push Notifi cations Using Cloud to Device Messaging (C2DM) 312

Listening for C2DM in Your Application 313

Sending a C2DM Message from Your Server 317

Summary 321

CHAPTER 12: CANVAS AND DRAWABLES: BUILDING CUSTOM ANDROID GRAPHICS 323

Working with Graphics in Mono for Android 324

Using the Canvas Object 325

Graphics Primitives 326

The Canvas Object 327

The Paint Object 328

The Bitmap Object 329

Bringing It All Together 330

A Path Primer 330

Case 1: Creating a Custom Graphic 331

Case 2: Responding to Events 336

Case 3: Animating Custom Graphics 342

Case 4: Improving Performance Using SurfaceView 347

Selecting the Best Approach 351

The 2D Graphics Library 352

Using Drawables 352

Drawables as XML Resources 353

Simple and Compound Drawables 354

Drawables in Action 354

Case 1: Using Default Drawables 354

Case 2: Adding Polish with the Shape Drawable 356

Case 3: Using the Gradient Drawable 360

Case 4: Using the Compound Drawable 362

Case 5: Interacting with a Custom Drawable 366

Summary 369

CHAPTER 13: WORKING WITH LOCATION INFORMATION 371

Understanding Location Basics 372

Determining Location 373

Location-Based Data Interruptions 373

Using Location-Based Services 374

Confi guring Location-Based Applications on the Emulator 374

Selecting a Location Provider 377

Determining Which Providers Are Available 377

Finding Location Providers with Criteria 377

Geocoding 379

Forward Geocoding 379

Reverse Geocoding 380

Constructing Proximity Alerts 382

Using Google Maps 384

Getting Your Development/Debugging MD5 Fingerprint 385

Getting Your Production/Release MD5 Fingerprint 386

Creating the Maps-Based Activity 386

Creating a Map in a Layout File 387

Using the MapView Controller with an Overlay 388

Summary 391

CHAPTER 14: INTERNATIONALIZATION AND LOCALIZATION 393

Selecting a Localization Strategy 395

Updating Language and Regional Settings 396

Understanding the Mechanics of Android Localization 398

Setting Up Default Resources 398

Adding Localization Support 399

Resource Selection in Detail 399

Supporting Multiple Languages 400

Utilizing the Strings.xml File 400

Translating Text 401

Translating Control Text 404

Localizing Other Resources 406

Localizing the Menu Icon and Application Name 409

Advanced Usage of Strings.xml 410

String Array 410

Plurals 410

String Replacements 411

Working with Format Conversions 414

Formatting Dates 414

Formatting Numbers and Currency 414

Summary 415

CHAPTER 15: SHARING CODE BETWEEN MONO FOR ANDROID, MONOTOUCH, AND WINDOWS PHONE 7 417

Overview of the Three Platforms 417

Mono for Android 418

MonoTouch 418

Windows Phone 7 419

Using Class Libraries to Separate the Code 420

Using Preprocessor Directives 420

Mono for Android 421

Windows Phone 7 421

MonoTouch 422

Assemblies Available on Each Platform 422

One Class Library to Rule Them All 425

Mono for Android 426

MonoTouch 428

Windows Phone 7 429

Putting It All Together: Creating a Cross-Platform Application 431

Summary 443

CHAPTER 16: PREPARING AND PUBLISHING YOUR APPLICATION TO THE MARKET 445

Preparing Your Application 446

Testing Your Application 446

Hitting the Key Testing Areas 447

Tools for the Testing Trade 449

Unit Testing 449

DDMS 449

The Emulator 452

Traceviews 453

Stress Testing via the Application Exerciser Monkey 455

UI Testing via the Monkeyrunner 456

Involving Peers and Users in the Testing Process 456

Publishing Your Application to the Android Market 457

Versioning Your Application 457

Creating the Final Build 459

Signing Your Application 461

Creating a Private Key 461

Creating a Self-Signed Certificate 464

Aligning the Final Package 464

Uploading to the Android Market 465

Summary 466

CHAPTER 17: ANDROID TABLETS 469

Examining the Android Tablet Marketplace 469

Designing a Tablet UI 470

Using the Action Bar 472

Removing the Action Bar 473

Adding Items to the Action Bar 473

Using the Application Icon 477

Navigating “Up” the Stack 477

Adding and Using Action Items 478

Creating a Tabbed Interface 479

Partial Screen Control Using Fragments 480

Creating Fragments 481

More Fragments 486

Summary 494

APPENDIX A: TIPS FOR DEVELOPERS AND THE FUTURE OF MONO AND ANDROID 495

Best Practices, Hints, Tips, and Gotchas 495

Android Honeycomb (3.0) and Ice Cream Sandwich (4.0) 499

Fragments for All! 502

Android Version and Device Fragmentation 503

What’s Next for Mono for Android? 504

Using Xamarin.Mobile for Cross-Platform Mobile Functionality 505

INDEX 507

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Rewards Program