Contents

About the Authors

About the Technical Reviewer

Acknowledgments

Foreword

Introduction

image Chapter 1: Hello Android

Prerequisites for Android Development

Setting Up Your Eclipse Environment

Downloading JDK 6

Downloading Eclipse 4.2

Downloading the Android SDK

The Tools Window

Installing ADT

Setting Up Your Android Studio Environment

Java requirements for Android Studio

Downloading and Installing Android Studio

Learning Android’s Fundamental Components

View

Activity

Fragment

Intent

Content Provider

Service

AndroidManifest.xml

AVDs

Hello World!

AVDs

Running on a Real Device

Exploring the Structure of an Android Application

Examining the Application Life Cycle

Simple Debugging

Launching the Emulator

References

Summary

image Chapter 2: Introduction to Android Application Architecture

Exploring a Simple Android Application

Defining UI through Layout Files

Specifying Comments in Layout Files

Adding Views and View Groups in Layout Files

Specifying Control Properties in Layout Files

Indicating ViewGroup Properties

Controlling Width and Height of a Control

Introducing Resources and Backgrounds

Working with Text Controls in the Layout File

Working with Autogenerated IDs for Controls

Implementing Programming Logic

Loading the Layout File into an Activity

Gathering Controls

Setting Up Buttons

Responding to Button Clicks: Tying It All Together

Updating the AndroidManifest.XML

Placing the Files in the Android Project

Testing the Calculator App on a Real Device

Android Activity Life Cycle

void onCreate(Bundle savedInstanceState)

void onStart()

void onRestoreInstanceState(Bundle savedInstanceState)

void onResume()

void onPause()

void onStop()

void onSaveInstanceState(Bundle saveStateBundle)

void onRestart()

Object onRetainNonConfigurationInstance()

void onDestroy()

General Notes on Activity Callbacks

More on Resources

Directory Structure of Resources

Reading Resources from Java Code

Runtime Behavior of Drawable Resources

Using Arbitrary XML Files as Resources

Working with Raw Resource Files

Reading Files from the Assets Directory

Reading Resources and Assets Without an Activity Reference

Understanding Resource Directories, Language, and Locale

More on Intents

Starting Activities for Results

Exercising the GET_CONTENT Action

Relating Intents and Activities

Understanding Explicit and Implicit Intents

Saving State in Android

Roadmap for Learning Android and the Rest of the Book

Track 1: UI Essentials for Your Android Applications

Track 2: Saving State

Track 3: Preparing/Taking Your Application to the Market

Track 4: Making Your Application Robust

Track 5: Bringing Finesse to Your Apps

Track 6: Integrating with Other Devices and the Cloud

Final Track: Getting a Helping Hand from Expert Android

As We Leave You Now with the Rest of the Book

References

Summary

image Chapter 3: Building Basic User Interfaces and Using Controls

UI Development in Android

Building a UI Completely in Code

Building a UI Completely in XML

Building a UI in XML with Code

Understanding Android’s Common Controls

Text Controls

Button Controls

The ImageView Control

Date and Time Controls

The MapView Control

References

Summary

image Chapter 4: Adapters and List Controls

Understanding Adapters

Getting to Know SimpleCursorAdapter

Getting to Know ArrayAdapter

Using Adapters with AdapterViews

The Basic List Control: ListView

The GridView Control

The Spinner Control

The Gallery Control

Summary

image Chapter 5: Building More Advanced UI Layouts

Creating Custom Adapters

Other Controls in Android

Styles and Themes

Using Styles

Using Themes

Understanding Layout Managers

The LinearLayout Layout Manager

The TableLayout Layout Manager

The RelativeLayout Layout Manager

The FrameLayout Layout Manager

The GridLayout Layout Manager

Customizing the Layout for Various Device Configurations

Summary

image Chapter 6: Working with Menus and Action Bars

Working with Menus Through XML Files

Creating XML Menu Resource Files

Populating Activity Menu from Menu XML Files

Responding to XML-Based Menu Items

Working with Menus in Java Code

Working with Menu Groups

Understanding Expanded Menus

Working with Icon Menus

Working with Submenus

Working with Context Menus

Registering a View for a Context Menu

Populating a Context Menu

Responding to Context Menu Items

Incorporating Dynamic Menus

Working with Pop-up Menus

Exploring Action Bars

Implementing a Standard Action Bar

Implementing a Tabbed Action Bar

Implementing a List-Based Action Bar

Exploring Action Bar and Search View

Defining a Search View Widget as a Menu Item

Creating a Search Results Activity

Specifying a Searchable XML File

Defining the Search Results Activity in the Manifest File

Identifying the Search Target for the Search View Widget

Resources

Summary

image Chapter 7: Styles and Themes

Using Styles

Using Themes

References

Summary

image Chapter 8: Fragments

What Is a Fragment?

When to Use Fragments

The Structure of a Fragment

A Fragment’s Life Cycle

Sample Fragment App Showing the Life Cycle

FragmentTransactions and the Fragment Back Stack

Fragment Transaction Transitions and Animations

The FragmentManager

Caution When Referencing Fragments

Saving Fragment State

ListFragments and <fragment>

Invoking a Separate Activity When Needed

Persistence of Fragments

Communications with Fragments

Using startActivity() and setTargetFragment()

References

Summary

image Chapter 9: Responding to Configuration Changes

The Default Configuration Change Process

The Destroy/Create Cycle of Activities

The Destroy/Create Cycle of Fragments

Using FragmentManager to Save Fragment State

Using setRetainInstance on a Fragment

Deprecated Configuration Change Methods

Handling Configuration Changes Yourself

References

Summary

image Chapter 10: Working with Dialogs

Using Dialogs in Android

Understanding Dialog Fragments

DialogFragment Basics

DialogFragment Sample Application

Working with Toast

References

Summary

image Chapter 11: Working with Preferences and Saving State

Exploring the Preferences Framework

Understanding CheckBoxPreference and SwitchPreference

Accessing a Preference Value in Code

Understanding ListPreference

Understanding EditTextPreference

Understanding MultiSelectListPreference

Updating AndroidManifest.xml

Using PreferenceCategory

Creating Child Preferences with Dependency

Preferences with Headers

PreferenceScreens

Dynamic Preference Summary Text

Saving State with Preferences

Using DialogPreference

Reference

Summary

image Chapter 12: Using the Compatibility Library for Older Devices

It All Started with Tablets

Adding the Library to Your Project

Including the v7 Support Library

Including the v8 Support Library

Including the v13 Support Library

Including the v17 Support Library

Including Just the v4 Support Library

Retrofitting an App with the Android Support Library

References

Summary

image Chapter 13: Exploring Packages, Processes, Threads, and Handlers

Understanding Packages and Processes

A Code Pattern for Sharing Data

Understanding Library Projects

Understanding Components and Threads

Understanding Handlers

Using Worker Threads

References

Summary

image Chapter 14: Building and Consuming Services

Consuming HTTP Services

Using the HttpClient for HTTP GET Requests

Using the HttpClient for HTTP POST Requests (a Multipart Example)

SOAP, JSON, and XML Parsers

Dealing with Exceptions

Addressing Multithreading Issues

Fun with Timeouts

Using the HttpURLConnection

Using the AndroidHttpClient

Using Android Services

Understanding Services in Android

Understanding Local Services

Understanding AIDL Services

Defining a Service Interface in AIDL

Implementing an AIDL Interface

Calling the Service from a Client Application

Passing Complex Types to Services

Messengers and Handlers

References

Summary

image Chapter 15: Advanced AsyncTask and Progress Dialogs

Essentials of a Simple AsyncTask

Implementing Your First AsyncTask

Calling an AsyncTask

Understanding the onPreExecute() Callback and Progress Dialog

Understanding the doInBackground() Method

Triggering onProgressUpdate() through publishProgress()

Understanding the onPostExecute() Method

Upgrading to a Deterministic Progress Dialog

AsyncTask and Thread Pools

Issues and Solutions for Correctly Showing the Progress of an AsyncTask

Dealing with Activity Pointers and Device Rotation

Dealing with Managed Dialogs

Using Retained Objects and Fragment Dialogs

Using Retained Fragments and Fragment Dialogs

Using Retained Fragments and ProgressBars

References

Summary

image Chapter 16: Broadcast Receivers and Long-Running Services

Sending a Broadcast

Coding a Simple Receiver

Registering a Receiver in the Manifest File

Accommodating Multiple Receivers

Working with Out-of-Process Receivers

Using Notifications from a Receiver

Monitoring Notifications Through the Notification Manager

Sending a Notification

Starting an Activity in a Broadcast Receiver

Exploring Long-Running Receivers and Services

Understanding Long-Running Broadcast Receiver Protocol

Understanding IntentService

Extending IntentService for a Broadcast Receiver

Exploring Long-Running Broadcast Service Abstraction

Designing A Long-Running Receiver

Abstracting a Wake Lock with LightedGreenRoom

Implementing a Long-Running Service

Understanding a Nonsticky Service

Understanding a Sticky Service

Understanding Redeliver Intents Option

Coding a Long-Running Service

Additional Topics in Broadcast Receivers

References

Summary

image Chapter 17: Exploring the Alarm Manager

Setting Up a Simple Alarm

Setting Off an Alarm Repeatedly

Cancelling an Alarm

Understanding Exactness of Alarms

Understanding Persistence of Alarms

References

Summary

image Chapter 18: Exploring 2D Animation

Exploring Frame-by-Frame Animation

Exploring Layout Animation

Understanding Interpolators

Exploring View Animation

Using Camera to Provide Depth Perception in 2D

Exploring the AnimationListener Class

Notes on Transformation Matrices

Exploring Property Animations: The New Animation API

Understanding Property Animation

Planning a Test Bed for Property Animation

Animating Views with Object Animators

Achieving Sequential Animation with AnimatorSet

Setting Animation Relationships with AnimatorSet.Builder

Using XML to Load Animators

Using PropertyValuesHolder

Understanding View Properties Animation

Understanding Type Evaluators

Understanding Key Frames

Understanding Layout Transitions

Resources

Summary

image Chapter 19: Exploring Maps and Location-Based Services

Understanding the Mapping Package

Obtaining a Maps API Key from Google

Adding the Maps API Key to Your Application

Understanding MapFragment

Adding Markers to Maps

Understanding the Location Package

Geocoding with Android

Understanding Location Services

Using Proximity Alerts and Geofencing

References

Summary

image Chapter 20: Understanding the Media Frameworks

Using the Media APIs

Whither SD Cards?

Playing Media

Playing Audio Content

Playing Video Content

Bonus Online Chapter on Recording and Advanced Media

References

Summary

image Chapter 21: Home Screen Widgets

User Experience with Home Screen Widgets

Understanding Widget Configuration Activity

Understanding the Life Cycle of a Widget

Understanding Widget Definition Phase

Implementing A Sample Widget Application

Defining the Widget Provider

Implementing Widget Configuration Activity

Implementing a Widget Provider

Collection-Based Widgets

Resources

Summary

image Chapter 22: Touch Screens

Understanding MotionEvents

The MotionEvent Object

Recycling MotionEvents

Using VelocityTracker

Multitouch

The Basics of Multitouch

Gestures

The Pinch Gesture

GestureDetector and OnGestureListeners

References

Summary

image Chapter 23: Implementing Drag and Drop

Exploring Drag and Drop

Basics of Drag and Drop in 3.0+

Drag-and-Drop Example Application

List of Files

Laying Out the Example Drag-and-Drop Application

Responding to onDrag in the Dropzone

Setting Up the Drag Source Views

Testing the Example Drag-and-Drop Application

References

Summary

image Chapter 24: Using Sensors

What Is a Sensor?

Detecting Sensors

What Can We Know About a Sensor?

Getting Sensor Events

Issues with Getting Sensor Data

Interpreting Sensor Data

Light Sensors

Proximity Sensors

Temperature Sensors

Pressure Sensors

Gyroscope Sensors

Accelerometers

Magnetic Field Sensors

Using Accelerometers and Magnetic Field Sensors Together

Magnetic Declination and GeomagneticField

Gravity Sensors

Linear Acceleration Sensors

Rotation Vector Sensors

References

Summary

image Chapter 25: Exploring Android Persistence and Content Providers

Saving State Using Shared Preferences

Saving State Using Internal Files

Saving State Using External Files

Saving State Using SQLite

Saving State Using O/R Mapping Libraries

Saving State Using Content Providers

Saving State Using Network Storage

Storing Data Directly Using SQLite

Summarizing Key SQLite Packages and Classes

Creating an SQLite Database

Defining a Database Through DDLs

Migrating a Database

Inserting Rows

Updating Rows

Deleting Rows

Reading Rows

Applying Transactions

Summarizing SQLite

Doing Transactions Through Dynamic Proxies

Exploring Databases on the Emulator and Available Devices

Exploring Content Providers

Exploring Android’s Built-in Providers

Understanding the Structure of Content Provider URIs

Implementing Content Providers

Planning a Database

Extending ContentProvider

Using UriMatcher to Figure Out the URIs

Using Projection Maps

Fulfilling MIME-Type Contracts

Implementing the Query Method

Implementing the Insert Method

Implementing the Update Method

Implementing the Delete Method

Registering the Provider

Exercising the Book Provider

Adding a Book

Removing a Book

Displaying the List of Books

Resources

Summary

image Chapter 26: Understanding Loaders

Understanding the Architecture of Loaders

Listing Basic Loader API Classes

Demonstrating the Loaders

Step 1: Preparing the Activity to Load Data

Step 2: Initializing the Loader

Delving into the Structure of ListActivity

Working with Asynchronous Loading of Data

Step 3: Implementing onCreateLoader()

Step 4: Implementing onLoadFinished()

Step 5: Implementing onLoaderReset()

Using Search with Loaders

Understanding the Order of LoaderManager Callbacks

Writing Custom Loaders

Resources

Summary

image Chapter 27: Exploring the Contacts API

Understanding Accounts

Enumerating Accounts

Understanding Contacts

Examining the Contacts SQLite Database

Understanding Raw Contacts

Understanding the Contacts Data Table

Understanding Aggregated Contacts

Exploring view_contacts

Exploring contact_entities_view

Working with the Contacts API

Exploring Accounts

Exploring Aggregated Contacts

Exploring Raw Contacts

Exploring Raw Contact Data

Adding a Contact with Its Details

Controlling Aggregation of Contacts

Understanding Personal Profile

Reading Profile Raw Contacts

Reading Profile Contact Data

Adding Data to the Personal Profile

Role of Sync Adapters

Using Batch Operations to Optimize ContentProvider Updates

Idea of Batching Content Provider Updates

Batching Commits by Yielding

Using Back References

Optimistic Locking

Reusing the Contact Provider UI

Using Group Features

Using Photo Features

References

Summary

image Chapter 28: Exploring Security and Permissions

Understanding the Android Security Model

Overview of Security Concepts

Signing Applications for Deployment

Performing Runtime Security Checks

Understanding Security at the Process Boundary

Declaring and Using Permissions

Understanding and Using URI Permissions

References

Summary

image Chapter 29: Using Google Cloud Messaging with Android

What Is Google Cloud Messaging?

Understanding the Key Building Blocks of GCM

Preparing to Use GCM in Your Application

Authenticating GCM Communication

Building an Android GCM-Enabled Application

Coding the Client Component for GCM

Coding the Server Component for GCM

Moving Beyond the GCM Introduction

image Chapter 30: Deploying Your Application: Google Play Store and Beyond

Becoming a Publisher

Following the Rules

Developer Console

Preparing Your Application for Sale

Testing for Different Devices

Supporting Different Screen Sizes

Preparing AndroidManifest.xml for Uploading

Localizing Your Application

Preparing Your Application Icon

Directing Users Back to the Play Store

The Android Licensing Service

Using ProGuard for Optimization, Fighting Piracy

Preparing Your .apk File for Uploading

Uploading Your Application

Graphics

Listing Details

Publishing Options

Contact Information

Consent

User Experience on Google Play Store

Beyond Google Play Store

References

Summary

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.237.24