Pro Android 3

Book description

Pro Android 3 shows you how to build real-world and fun mobile applications using the new Android 3.0 SDK. It covers everything from the fundamentals of building apps for embedded devices, phones, and tablets to advanced concepts such as custom 3D components and multi-tasking.

Using the tutorials and expert advice, you'll quickly be able to build cool mobile apps and run them on dozens of Android-based smartphones. You'll explore and use the Android APIs, including those for media and sensors. And you'll check out what's new with Android 3.0, including the improved UI across all Android platforms, integration with WebM, and more, giving you the knowledge to create stunning, cutting-edge apps, while keeping you agile enough to respond to changes in the future.

What you'll learn

  • How to use Android to build Java-based mobile applications for Google phones with a touch screen or keyboard

  • How to design and implement irresistible user interfaces for touchscreens with Views and layouts

  • How to populate your application with data from data sources, using Content Providers

  • How to create 3D graphics with OpenGL and custom components

  • How to build multimedia and game apps using Android's Media APIs and OpenGL

  • How to use Android's location-based services, network-based services, and security

  • How to use new Android 3.0 features, such as Fragments and the ActionBar

Who this book is for

This book is for professional software engineers/programmers looking to move their ideas and applications into the mobile space with Android. It assumes a passable understanding of Java, including how to write classes and handle basic inheritance structures.

Table of contents

  1. Copyright
  2. Foreword
  3. About the Authors
  4. About the Technical Reviewer
  5. Acknowledgments
  6. Preface
  7. 1. Introducing the Android Computing Platform
    1. 1.1. A New Platform for a New Personal Computer
    2. 1.2. Early History of Android
    3. 1.3. Delving Into the Dalvik VM
    4. 1.4. Understanding the Android Software Stack
    5. 1.5. Developing an End-User Application with the Android SDK
      1. 1.5.1. Android Emulator
      2. 1.5.2. The Android UI
      3. 1.5.3. The Android Foundational Components
      4. 1.5.4. Advanced UI Concepts
      5. 1.5.5. Android Service Components
      6. 1.5.6. Android Media and Telephony Components
      7. 1.5.7. Android Java Packages
    6. 1.6. Taking Advantage of Android Source Code
    7. 1.7. The Sample Projects in this Book
    8. 1.8. Summary
  8. 2. Setting Up Your Development Environment
    1. 2.1. Setting Up Your Environment
      1. 2.1.1. Downloading JDK 6
      2. 2.1.2. Downloading Eclipse 3.6
      3. 2.1.3. Downloading the Android SDK
        1. 2.1.3.1. Updating Your PATH Environment Variable
      4. 2.1.4. The Tools Window
      5. 2.1.5. Installing Android Development Tools (ADT)
    2. 2.2. Learning the Fundamental Components
      1. 2.2.1. View
      2. 2.2.2. Activity
      3. 2.2.3. Intent
      4. 2.2.4. Content Provider
      5. 2.2.5. Service
      6. 2.2.6. AndroidManifest.xml
      7. 2.2.7. Android Virtual Devices
    3. 2.3. Hello World!
    4. 2.4. Android Virtual Devices
    5. 2.5. Exploring the Structure of an Android Application
    6. 2.6. Analyzing the Notepad Application
      1. 2.6.1. Loading and Running the Notepad Application
      2. 2.6.2. Dissecting the Application
    7. 2.7. Examining the Application Lifecycle
    8. 2.8. Debugging Your App
      1. 2.8.1. Launching the Emulator
      2. 2.8.2. StrictMode
      3. 2.8.3. References
    9. 2.9. Summary
  9. 3. Understanding Android Resources
    1. 3.1. Understanding Resources
      1. 3.1.1. String Resources
      2. 3.1.2. Layout Resources
      3. 3.1.3. Resource Reference Syntax
      4. 3.1.4. Defining Your Own Resource IDs for Later Use
      5. 3.1.5. Compiled and Uncompiled Android Resources
    2. 3.2. Enumerating Key Android Resources
      1. 3.2.1.
        1. 3.2.1.1. String Arrays
        2. 3.2.1.2. Plurals
        3. 3.2.1.3. More on String Resources
        4. 3.2.1.4. Color Resources
        5. 3.2.1.5. Dimension Resources
        6. 3.2.1.6. Image Resources
        7. 3.2.1.7. Color-Drawable Resources
    3. 3.3. Working with Arbitrary XML Resource Files
    4. 3.4. Working with Raw Resources
    5. 3.5. Working with Assets
    6. 3.6. Reviewing the Resources Directory Structure
    7. 3.7. Resources and Configuration Changes
    8. 3.8. Reference URLs
    9. 3.9. Summary
  10. 4. Understanding Content Providers
    1. 4.1. Exploring Android's Built-in Providers
      1. 4.1.1.
        1. 4.1.1.1. Exploring Databases on the Emulator and Available Devices
        2. 4.1.1.2. Quick SQLite Primer
    2. 4.2. Architecture of Content Providers
      1. 4.2.1.
        1. 4.2.1.1. Structure of Android Content URIs
        2. 4.2.1.2. Structure of Android MIME Types
        3. 4.2.1.3. Reading Data Using URIs
        4. 4.2.1.4. Using the Android Cursor
        5. 4.2.1.5. Working with the where Clause
          1. 4.2.1.5.1. Passing a where Clause Through a URI
          2. 4.2.1.5.2. Using Explicit where Clauses
        6. 4.2.1.6. Inserting Records
        7. 4.2.1.7. Adding a File to a Content Provider
        8. 4.2.1.8. Updates and Deletes
    3. 4.3. Implementing Content Providers
      1. 4.3.1.
        1. 4.3.1.1. Planning a Database
        2. 4.3.1.2. Extending ContentProvider
        3. 4.3.1.3. Fulfilling MIME-Type Contracts
        4. 4.3.1.4. Implementing the Query Method
        5. 4.3.1.5. Implementing an Insert Method
        6. 4.3.1.6. Implementing an Update Method
        7. 4.3.1.7. Implementing a Delete Method
        8. 4.3.1.8. Using UriMatcher to Figure Out the URIs
        9. 4.3.1.9. Using Projection Maps
        10. 4.3.1.10. Registering the Provider
    4. 4.4. Exercising the Book Provider
      1. 4.4.1. Adding A Book
      2. 4.4.2. Removing a Book
      3. 4.4.3. Getting a Count of the Books
      4. 4.4.4. Displaying the List of Books
    5. 4.5. Resources
    6. 4.6. Summary
  11. 5. Understanding Intents
    1. 5.1. Basics of Android Intents
    2. 5.2. Available Intents in Android
    3. 5.3. Exploring Intent Composition
      1. 5.3.1. Intents and Data URIs
      2. 5.3.2. Generic Actions
      3. 5.3.3. Using Extra Information
      4. 5.3.4. Using Components to Directly Invoke an Activity
      5. 5.3.5. Understanding Intent Categories
      6. 5.3.6. Rules for Resolving Intents to Their Components
        1. 5.3.6.1. Action
        2. 5.3.6.2. Data
        3. 5.3.6.3. Data Type
        4. 5.3.6.4. Data Scheme
        5. 5.3.6.5. Data Authority
        6. 5.3.6.6. Data Path
        7. 5.3.6.7. Intent Categories
    4. 5.4. Exercising the ACTION_PICK
    5. 5.5. Exercising the GET_CONTENT Action
    6. 5.6. Introducing Pending Intents
    7. 5.7. Resources
    8. 5.8. Summary
  12. 6. Building User Interfaces and Using Controls
    1. 6.1. UI Development in Android
      1. 6.1.1. Building a UI Completely in Code
      2. 6.1.2. Building a UI Completely in XML
      3. 6.1.3. Building a UI in XML With Code
        1. 6.1.3.1. FILL_PARENT vs. MATCH_PARENT
    2. 6.2. Understanding Android's Common Controls
      1. 6.2.1. Text Controls
        1. 6.2.1.1. TextView
        2. 6.2.1.2. EditText
        3. 6.2.1.3. AutoCompleteTextView
        4. 6.2.1.4. MultiAutoCompleteTextView
      2. 6.2.2. Button Controls
        1. 6.2.2.1. The Button Control
        2. 6.2.2.2. The ImageButton Control
        3. 6.2.2.3. The ToggleButton Control
        4. 6.2.2.4. The CheckBox Control
        5. 6.2.2.5. The RadioButton Control
      3. 6.2.3. The ImageView Control
      4. 6.2.4. Date and Time Controls
        1. 6.2.4.1. The DatePicker and TimePicker Controls
        2. 6.2.4.2. The DigitalClock and AnalogClock Controls
      5. 6.2.5. The MapView Control
    3. 6.3. Understanding Adapters
      1. 6.3.1. Getting to Know SimpleCursorAdapter
      2. 6.3.2. Getting to Know ArrayAdapter
    4. 6.4. Using Adapters With AdapterViews
      1. 6.4.1. The Basic List Control: ListView
        1. 6.4.1.1. Displaying Values in a ListView
        2. 6.4.1.2. Clickable Items in a ListView
        3. 6.4.1.3. Adding Other Controls With a ListView
        4. 6.4.1.4. Another Way to Read Selections From a ListView
      2. 6.4.2. The GridView Control
      3. 6.4.3. The Spinner Control
      4. 6.4.4. The Gallery Control
      5. 6.4.5. Creating Custom Adapters
      6. 6.4.6. Other Controls in Android
    5. 6.5. Styles and Themes
      1. 6.5.1. Using Styles
      2. 6.5.2. Using Themes
    6. 6.6. Understanding Layout Managers
      1. 6.6.1. The LinearLayout Layout Manager
        1. 6.6.1.1. Understanding Weight and Gravity
        2. 6.6.1.2. android:gravity vs. android:layout_gravity
      2. 6.6.2. The TableLayout Layout Manager
      3. 6.6.3. The RelativeLayout Layout Manager
      4. 6.6.4. The FrameLayout Layout Manager
      5. 6.6.5. Customizing Layout for Various Device Configurations
    7. 6.7. Debugging and Optimizing Layouts with the Hierarchy Viewer
    8. 6.8. References
    9. 6.9. Summary
  13. 7. Working with Menus
    1. 7.1. Understanding Android Menus
      1. 7.1.1. Creating a Menu
      2. 7.1.2. Working with Menu Groups
    2. 7.2. Responding to Menu Items
      1. 7.2.1.
        1. 7.2.1.1. Responding to Menu Items through onOptionsItemSelected
        2. 7.2.1.2. Responding to Menu Items through Listeners
        3. 7.2.1.3. Using an Intent to Respond to Menu Items
    3. 7.3. Creating a Test Harness for Testing Menus
      1. 7.3.1.
        1. 7.3.1.1. Creating an XML Layout
        2. 7.3.1.2. Creating an Activity
        3. 7.3.1.3. Setting Up the Menu
        4. 7.3.1.4. Adding Regular Menu Items
        5. 7.3.1.5. Adding Secondary Menu Items
        6. 7.3.1.6. Responding to Menu Item Clicks
        7. 7.3.1.7. Tweaking the AndroidManifest.xml File
    4. 7.4. Working with Other Menu Types
      1. 7.4.1. Expanded Menus
      2. 7.4.2. Working with Icon Menus
      3. 7.4.3. Working with Submenus
      4. 7.4.4. Provisioning for System Menus
      5. 7.4.5. Working with Context Menus
        1. 7.4.5.1. Registering a View for a Context Menu
        2. 7.4.5.2. Populating a Context Menu
        3. 7.4.5.3. Responding to Context Menu Items
      6. 7.4.6. Working with Alternative Menus
      7. 7.4.7. Working with Menus in Response to Changing Data
    5. 7.5. Loading Menus Through XML Files
      1. 7.5.1. Structure of an XML Menu Resource File
      2. 7.5.2. Inflating XML Menu Resource Files
      3. 7.5.3. Responding to XML-Based Menu Items
      4. 7.5.4. A Brief Introduction to Additional XML Menu Tags
        1. 7.5.4.1. Group Category Tag
        2. 7.5.4.2. Checkable Behavior Tags
        3. 7.5.4.3. Tags to Simulate a Submenu
        4. 7.5.4.4. Menu Icon Tag
        5. 7.5.4.5. Menu Enabling/Disabling Tag
        6. 7.5.4.6. Menu Item Shortcuts
        7. 7.5.4.7. Menu Visibility
    6. 7.6. Resource
    7. 7.7. Summary
  14. 8. Working with Dialogs
    1. 8.1. Using Dialogs in Android
      1. 8.1.1. Designing an Alert Dialog
      2. 8.1.2. Designing a Prompt Dialog
        1. 8.1.2.1. XML Layout File for the Prompt Dialog
        2. 8.1.2.2. Setting Up an Alert-Dialog Builder with a User View
        3. 8.1.2.3. Setting Up Buttons and Listeners
        4. 8.1.2.4. Creating and Showing the Prompt Dialog
        5. 8.1.2.5. Prompt Dialog Listener
        6. 8.1.2.6. Putting It All Together
      3. 8.1.3. Nature of Dialogs in Android
      4. 8.1.4. Rearchitecting the Prompt Dialog
    2. 8.2. Working with Managed Dialogs
      1. 8.2.1. Understanding the Managed-Dialog Protocol
      2. 8.2.2. Recasting the Nonmanaged Dialog as a Managed Dialog
      3. 8.2.3. Simplifying the Managed-Dialog Protocol
        1. 8.2.3.1. IDialogProtocol
        2. 8.2.3.2. ManagedActivityDialog
        3. 8.2.3.3. DialogRegistry
        4. 8.2.3.4. ManagedDialogsActivity
        5. 8.2.3.5. IDialogFinishedCallBack
        6. 8.2.3.6. GenericManagedAlertDialog
        7. 8.2.3.7. GenericPromptDialog
    3. 8.3. Working with Toast
    4. 8.4. Resources
    5. 8.5. Summary
  15. 9. Working with Preferences and Saving State
    1. 9.1. Exploring the Preferences Framework
      1. 9.1.1. Understanding ListPreference
      2. 9.1.2. Understanding CheckBoxPreference
      3. 9.1.3. Understanding EditTextPreference
      4. 9.1.4. Understanding RingtonePreference
    2. 9.2. Organizing Preferences
    3. 9.3. Manipulating Preferences Programmatically
    4. 9.4. Saving State with Preferences
    5. 9.5. Reference
    6. 9.6. Summary
  16. 10. Exploring Security and Permissions
    1. 10.1. Understanding the Android Security Model
      1. 10.1.1. Overview of Security Concepts
      2. 10.1.2. Signing Applications for Deployment
        1. 10.1.2.1. Generating a Self-Signed Certificate Using the Keytool
        2. 10.1.2.2. The Debug Keystore and the Development Certificate
        3. 10.1.2.3. Using the Jarsigner Tool to Sign the .apk File
        4. 10.1.2.4. Aligning Your Application with zipalign
        5. 10.1.2.5. Installing Updates to an Application and Signing
    2. 10.2. Performing Runtime Security Checks
      1. 10.2.1. Understanding Security at the Process Boundary
      2. 10.2.2. Declaring and Using Permissions
      3. 10.2.3. Understanding and Using Custom Permissions
      4. 10.2.4. Understanding and Using URI Permissions
        1. 10.2.4.1. Passing URI Permissions in Intents
        2. 10.2.4.2. Specifying URI Permissions in Content Providers
    3. 10.3. References
    4. 10.4. Summary
  17. 11. Building and Consuming Services
    1. 11.1. Consuming HTTP Services
      1. 11.1.1. Using the HttpClient for HTTP GET Requests
      2. 11.1.2. Using the HttpClient for HTTP POST Requests (a Multipart Example)
      3. 11.1.3. SOAP, JSON, and XML Parsers
      4. 11.1.4. Dealing with Exceptions
      5. 11.1.5. Addressing Multithreading Issues
      6. 11.1.6. Fun With Timeouts
      7. 11.1.7. Using the HttpURLConnection
      8. 11.1.8. Using the AndroidHttpClient
      9. 11.1.9. Using Background Threads (AsyncTask)
      10. 11.1.10. Handling Configuration Changes with AsyncTasks
      11. 11.1.11. Getting Files Using DownloadManager
    2. 11.2. Using Android Services
      1. 11.2.1. Understanding Services in Android
      2. 11.2.2. Understanding Local Services
      3. 11.2.3. Understanding AIDL Services
      4. 11.2.4. Defining a Service Interface in AIDL
      5. 11.2.5. Implementing an AIDL Interface
      6. 11.2.6. Calling the Service from a Client Application
      7. 11.2.7. Passing Complex Types to Services
    3. 11.3. Real-World Example Using Services
      1. 11.3.1. Google Translate API
      2. 11.3.2. Using the Google Translate API
    4. 11.4. References
    5. 11.5. Summary
  18. 12. Exploring Packages
    1. 12.1. Packages and Processes
      1. 12.1.1. Details of a Package Specification
      2. 12.1.2. Translating Package Name to a Process Name
      3. 12.1.3. Listing Installed Packages
      4. 12.1.4. Deleting a Package through the Package Browser
    2. 12.2. Revisiting the Package Signing Process
      1. 12.2.1. Understanding Digital Signatures: Scenario 1
      2. 12.2.2. Understanding Digital Signatures: Scenario 2
      3. 12.2.3. A Pattern for Understanding Digital Signatures
      4. 12.2.4. So How Do You Digitally Sign?
      5. 12.2.5. Implications of the Signing Process
    3. 12.3. Sharing Data Among Packages
      1. 12.3.1. The Nature of Shared User IDs
      2. 12.3.2. A Code Pattern for Sharing Data
    4. 12.4. Library Projects
      1. 12.4.1. What Is a Library Project?
      2. 12.4.2. Library Project Predicates
      3. 12.4.3. Creating a Library Project
      4. 12.4.4. Creating an Android Project That Uses a library
    5. 12.5. References
    6. 12.6. Summary
  19. 13. Exploring Handlers
    1. 13.1. Android Components and Threading
      1. 13.1.1. Activities Run on the Main Thread
      2. 13.1.2. Broadcast Receivers run on the Main Thread
      3. 13.1.3. Services Run on the Main Thread
      4. 13.1.4. Content Provider Runs on the Main Thread
      5. 13.1.5. Implications of a Singular Main Thread
      6. 13.1.6. Thread Pools, Content Providers, External Service Components
      7. 13.1.7. Thread Utilities: Discover Your Threads
    2. 13.2. Handlers
      1. 13.2.1. Implications of Holding the Main Thread
      2. 13.2.2. Using a Handler to Defer Work on the Main Thread
      3. 13.2.3. A Sample Handler Source Code That Defers Work
      4. 13.2.4. Constructing a Suitable Message Object
      5. 13.2.5. Sending Message Objects to the Queue
      6. 13.2.6. Responding to the handleMessage Callback
    3. 13.3. Using Worker Threads
      1. 13.3.1. Invoking a Worker Thread from a Menu
      2. 13.3.2. Communicating Between the Worker and the Main Threads
        1. 13.3.2.1. WorkerThreadRunnable Implementation
        2. 13.3.2.2. ReportStatusHandler Implementation
      3. 13.3.3. A Quick Overview of Thread Behavior
    4. 13.4. Handler Example Driver classes
      1. 13.4.1. Driver Activity File
      2. 13.4.2. Layout File
      3. 13.4.3. Menu File
      4. 13.4.4. Manifest File
    5. 13.5. Component and Process Lifetimes
      1. 13.5.1. Activity Life Cycle
      2. 13.5.2. Service Life Cycle
      3. 13.5.3. Receiver Life Cycle
      4. 13.5.4. Provider Life Cycle
    6. 13.6. Instructions for Compiling the Code
      1. 13.6.1. Creating the Project from the ZIP File
      2. 13.6.2. Creating the Project from the Listings
    7. 13.7. References
    8. 13.8. Summary
  20. 14. Broadcast Receivers and Long-Running Services
    1. 14.1. Broadcast Receivers
      1. 14.1.1. Sending a Broadcast
      2. 14.1.2. Coding a Simple Receiver: Sample Code
      3. 14.1.3. Registering a Receiver in the Manifest File
      4. 14.1.4. Sending a Test Broadcast
      5. 14.1.5. Accommodating Multiple Receivers
      6. 14.1.6. A Project for Out-of-Process Receivers
    2. 14.2. Using Notifications from a Receiver
      1. 14.2.1. Monitoring Notifications Through the Notification Manager
      2. 14.2.2. Sending a Notification
    3. 14.3. Long-Running Receivers and Services
      1. 14.3.1. Long-Running Broadcast Receiver Protocol
      2. 14.3.2. IntentService
      3. 14.3.3. IntentService Source Code
    4. 14.4. Extending IntentService for a Broadcast Receiver
      1. 14.4.1. Long-Running Broadcast Service Abstraction
      2. 14.4.2. A Long-Running Receiver
      3. 14.4.3. Abstracting a Wake Lock with LightedGreenRoom
        1. 14.4.3.1. A Lighted Green Room
        2. 14.4.3.2. Lighted Green Room Implementation
    5. 14.5. Long-Running Service Implementation
      1. 14.5.1. Details of a Nonsticky Service
      2. 14.5.2. Details of a Sticky Service
      3. 14.5.3. A Variation of Nonsticky: Redeliver Intents
      4. 14.5.4. Specifying Service Flags in OnStartCommand
      5. 14.5.5. Picking Suitable Stickiness
      6. 14.5.6. Controlling the Wake Lock from Two Places
      7. 14.5.7. Long-Running Service Implementation
      8. 14.5.8. Testing Long Running Services
    6. 14.6. Instructions for Compiling the Code
      1. 14.6.1. Creating the Projects from the ZIP File
      2. 14.6.2. Creating the Project from the Listings
        1. 14.6.2.1. TestBCR Project files
        2. 14.6.2.2. Stand-Alone BCR Project Files
    7. 14.7. References
    8. 14.8. Summary
  21. 15. Exploring the Alarm Manager
    1. 15.1. Alarm Manager Basics: Setting Up a Simple Alarm
      1. 15.1.1. Obtaining the Alarm Manager
      2. 15.1.2. Setting Up the Time for the Alarm
      3. 15.1.3. Setting Up a Receiver for the Alarm
      4. 15.1.4. Creating a PendingIntent Suitable for an Alarm
      5. 15.1.5. Setting the Alarm
      6. 15.1.6. Test Project
    2. 15.2. Exploring Alarm Manager Alternate Scenarios
      1. 15.2.1. Setting Off an Alarm Repeatedly
        1. 15.2.1.1. Compiling Code for This Example
      2. 15.2.2. Cancelling an Alarm
        1. 15.2.2.1. Compiling code for this example
      3. 15.2.3. Working with Multiple Alarms
        1. 15.2.3.1. Compiling Code for This Example
      4. 15.2.4. Intent Primacy in Setting Off Alarms
      5. 15.2.5. Persistence of Alarms
    3. 15.3. Alarm Manager Predicates
    4. 15.4. References
    5. 15.5. Summary
  22. 16. Exploring 2D Animation
    1. 16.1. Frame-by-Frame Animation
      1. 16.1.1. Planning for Frame-by-Frame Animation
      2. 16.1.2. Creating the Activity
      3. 16.1.3. Adding Animation to the Activity
    2. 16.2. Layout Animation
      1. 16.2.1. Basic Tweening Animation Types
      2. 16.2.2. Planning the Layout Animation Test Harness
      3. 16.2.3. Creating the Activity and the ListView
      4. 16.2.4. Animating the ListView
      5. 16.2.5. Using Interpolators
    3. 16.3. View Animation
      1. 16.3.1. Understanding View Animation
      2. 16.3.2. Adding Animation
      3. 16.3.3. Using Camera to Provide Depth Perception in 2D
      4. 16.3.4. Exploring the AnimationListener Class
      5. 16.3.5. Some Notes on Transformation Matrices
    4. 16.4. Resources
    5. 16.5. Summary
  23. 17. Exploring Maps and Location-based Services
    1. 17.1. Understanding the Mapping Package
      1. 17.1.1. Obtaining a map-api Key from Google
      2. 17.1.2. Understanding MapView and MapActivity
      3. 17.1.3. Adding Markers Using Overlays
    2. 17.2. Understanding the Location Package
      1. 17.2.1. Geocoding with Android
      2. 17.2.2. Geocoding with Background Threads
      3. 17.2.3. Understanding the LocationManager Service
        1. 17.2.3.1. How to Enable Location Providers
        2. 17.2.3.2. What Can You Do With a Location?
        3. 17.2.3.3. Sending Location Updates to Your Application During Development
        4. 17.2.3.4. Sending Location Updates From the Emulator Console
        5. 17.2.3.5. Alternate Ways of Getting Location Updates
      4. 17.2.4. Showing Your Location Using MyLocationOverlay
        1. 17.2.4.1. Customizing MyLocationOverlay
      5. 17.2.5. Using Proximity Alerts
    3. 17.3. References
    4. 17.4. Summary
  24. 18. Using the Telephony APIs
    1. 18.1. Working with SMS
      1. 18.1.1. Sending SMS Messages
      2. 18.1.2. Monitoring Incoming SMS Messages
      3. 18.1.3. Working with SMS Folders
      4. 18.1.4. Sending E-mail
    2. 18.2. Working with the Telephony Manager
    3. 18.3. Session Initiation Protocol (SIP)
    4. 18.4. References
    5. 18.5. Summary
  25. 19. Understanding the Media Frameworks
    1. 19.1. Using the Media APIs
      1. 19.1.1. Using SD Cards
    2. 19.2. Playing Media
      1. 19.2.1. Playing Audio Content
        1. 19.2.1.1. Understanding the setDataSource Method
        2. 19.2.1.2. Use SoundPool for Simultaneous Track Playing
        3. 19.2.1.3. Playing Sounds with JetPlayer
        4. 19.2.1.4. Playing Background Sounds with AsyncPlayer
        5. 19.2.1.5. Low-level Audio Playback Using AudioTrack
        6. 19.2.1.6. Understanding the MediaPlayer Oddities
      2. 19.2.2. Playing Video Content
    3. 19.3. Recording Media
      1. 19.3.1. Exploring Audio Recording with MediaRecorder
      2. 19.3.2. Recording Audio with AudioRecord
      3. 19.3.3. Exploring Video Recording
        1. 19.3.3.1. Camera and Camcorder Profiles
      4. 19.3.4. Exploring the MediaStore Class
      5. 19.3.5. Recording Audio Using an Intent
      6. 19.3.6. Adding Media Content to the Media Store
      7. 19.3.7. Triggering MediaScanner for the Entire SD Card
      8. 19.3.8. References
    4. 19.4. Summary
  26. 20. Programming 3D Graphics with OpenGL
    1. 20.1. Understanding the History and Background of OpenGL
      1. 20.1.1. OpenGL ES
      2. 20.1.2. OpenGL ES and Java ME
      3. 20.1.3. M3G: Another Java ME 3D Graphics Standard
    2. 20.2. Fundamentals of OpenGL
      1. 20.2.1. Essential Drawing with OpenGL ES
        1. 20.2.1.1. glVertexPointer and Specifying Drawing Vertices
        2. 20.2.1.2. glDrawElements
        3. 20.2.1.3. glClear
        4. 20.2.1.4. glColor
      2. 20.2.2. Understanding OpenGL Camera and Coordinates
        1. 20.2.2.1. gluLookAt and the Camera Symbolism
        2. 20.2.2.2. glFrustum and the Viewing Volume
        3. 20.2.2.3. glViewport and Screen Size
    3. 20.3. Interfacing OpenGL ES with Android
      1. 20.3.1. Using GLSurfaceView and Related Classes
      2. 20.3.2. Implementing the Renderer
      3. 20.3.3. Using GLSurfaceView from an Activity
      4. 20.3.4. Changing Camera Settings
      5. 20.3.5. Using Indices to Add Another Triangle
      6. 20.3.6. Animating the Simple OpenGL Triangle
        1. 20.3.6.1. AnimatedSimpleTriangleRenderer
    4. 20.4. Braving OpenGL: Shapes and Textures
      1. 20.4.1. Drawing a Rectangle
      2. 20.4.2. Working with Shapes
        1. 20.4.2.1. A Regular Polygon as a Shape
        2. 20.4.2.2. Implementing the RegularPolygon Shape
        3. 20.4.2.3. Rendering a Square Using RegularPolygon
        4. 20.4.2.4. Animating RegularPolygons
      3. 20.4.3. Working with Textures
        1. 20.4.3.1. Understanding Textures
        2. 20.4.3.2. Normalized Texture Coordinates
        3. 20.4.3.3. Abstracting Common Texture Handling
        4. 20.4.3.4. Drawing Using Textures
      4. 20.4.4. Drawing Multiple Figures
    5. 20.5. OpenGL ES 2.0
      1. 20.5.1. Java Bindings for OpenGL ES 2.0
      2. 20.5.2. Rendering Steps
      3. 20.5.3. Understanding Shaders
      4. 20.5.4. Compiling Shaders into a Program
      5. 20.5.5. Getting Access to the Shader Program Variables
      6. 20.5.6. A Simple ES 2.0 Triangle
      7. 20.5.7. Further Reading on OpenGL ES 2.0
    6. 20.6. Instructions for Compiling the Code
      1. 20.6.1. References
    7. 20.7. Summary
  27. 21. Exploring Live Folders
    1. 21.1. Exploring Live Folders
      1. 21.1.1. How a User Experiences Live Folders
      2. 21.1.2. Building a Live Folder
        1. 21.1.2.1. AndroidManifest.xml
        2. 21.1.2.2. AllContactsLiveFolderCreatorActivity.java
        3. 21.1.2.3. MyContactsProvider.java
        4. 21.1.2.4. MyCursor.java
        5. 21.1.2.5. BetterCursorWrapper.java
        6. 21.1.2.6. Exercising Live Folders
    2. 21.2. Instructions for Compiling the Code
    3. 21.3. References
    4. 21.4. Summary
  28. 22. Home Screen Widgets
    1. 22.1. Architecture of Home Screen Widgets
      1. 22.1.1. What Are Home Screen Widgets?
      2. 22.1.2. User Experience with Home Screen Widgets
        1. 22.1.2.1. Creating a Widget Instance on the Home Screen
        2. 22.1.2.2. Understanding Widget Configurator
      3. 22.1.3. Life Cycle of a Widget
        1. 22.1.3.1. Widget Definition Phase
        2. 22.1.3.2. Widget Instance Creation Phase
        3. 22.1.3.3. onUpdate Phase
        4. 22.1.3.4. Widget View Mouse Click Event Callbacks
        5. 22.1.3.5. Deleting a Widget Instance
        6. 22.1.3.6. Uninstalling Widget Packages
    2. 22.2. A Sample Widget Application
      1. 22.2.1. Defining the Widget Provider
      2. 22.2.2. Defining Widget Size
      3. 22.2.3. Widget Layout-Related Files
        1. 22.2.3.1. Widget Layout File
        2. 22.2.3.2. Widget Background Shape File
      4. 22.2.4. Implementing a Widget Provider
      5. 22.2.5. Implementing Widget Models
        1. 22.2.5.1. Interface for a Widget Model
        2. 22.2.5.2. Abstract Implementation of a Widget Model
        3. 22.2.5.3. Implementation of a Widget Model for Birthday Widget
        4. 22.2.5.4. A Few Date-Related Utilities
      6. 22.2.6. Implementing Widget Configuration Activity
    3. 22.3. Widget Limitations and Extensions
    4. 22.4. Resources
    5. 22.5. Summary
  29. 23. Android Search
    1. 23.1. Android Search Experience
      1. 23.1.1. Exploring Android Global Search
      2. 23.1.2. Enabling Suggestion Providers for Global Search
        1. 23.1.2.1. Working with Search Settings in Android Release 2.2
        2. 23.1.2.2. Working with Search Settings in Android Release 2.3
    2. 23.2. Activities and Search Key Interaction
      1. 23.2.1. Behavior of Search Key on a Regular Activity
      2. 23.2.2. Behavior of an Activity that Disables Search
      3. 23.2.3. Explicitly Invoking Search Through a Menu
      4. 23.2.4. Understanding Local Search and Related Activities
      5. 23.2.5. Enabling Type-to-Search
    3. 23.3. Implementing a Simple Suggestion Provider
      1. 23.3.1. Planning the Simple Suggestions Provider
      2. 23.3.2. Simple Suggestions Provider Implementation Files
      3. 23.3.3. Implementing the SimpleSuggestionProviderclass
        1. 23.3.3.1. Responsibilities of a Simple Suggestion Provider
        2. 23.3.3.2. Complete Source Code of SimpleSuggestionProvider
        3. 23.3.3.3. Understanding SearchRecentSuggestionsProvider Database Modes
        4. 23.3.3.4. Declaring the Suggestion Provider in the Manifest File
      4. 23.3.4. Understanding Simple Suggestions Provider Search Activity
        1. 23.3.4.1. Complete Source Code of a Search Activity
        2. 23.3.4.2. Checking the Action and Retrieving the Query
        3. 23.3.4.3. Understanding onCreate() and onNewIntent()
        4. 23.3.4.4. Testing for onNewIntent()
        5. 23.3.4.5. Saving the Query Using SearchRecentSuggestionsProvider
        6. 23.3.4.6. Search Metadata
      5. 23.3.5. Search Invoker Activity
      6. 23.3.6. Simple Suggestion Provider User Experience
    4. 23.4. Implementing a Custom Suggestion Provider
      1. 23.4.1. Planning the Custom Suggestion Provider
      2. 23.4.2. SuggestURLProvider Project Implementation Files
      3. 23.4.3. Implementing the SuggestUrlProvider Class
        1. 23.4.3.1. Responsibilities of a Suggestion Provider
        2. 23.4.3.2. Overall Source Code for SuggestUrlProvider
        3. 23.4.3.3. Understanding Suggestion Provider URIs
        4. 23.4.3.4. Implementing getType() and Specifying MIME Types
        5. 23.4.3.5. Passing Query to the Suggestion Provider: The Selection Argument
        6. 23.4.3.6. Exploring Search Metadata for Custom Suggestion Providers
        7. 23.4.3.7. Suggestion Cursor Columns
        8. 23.4.3.8. Populating and Returning the List of Columns
      4. 23.4.4. Implementing a Search Activity for a Custom Suggestion Provider
        1. 23.4.4.1. SearchActivity for a Custom Suggestion Provider
        2. 23.4.4.2. Details of SearchActivity Invocation
        3. 23.4.4.3. Responding to ACTION_SEARCH and ACTION_VIEW
        4. 23.4.4.4. Search Activity Layout
        5. 23.4.4.5. Corresponding strings.xml
        6. 23.4.4.6. Responding to onCreate() and onNewIntent()
        7. 23.4.4.7. Notes on Finishing a Search Activity
      5. 23.4.5. Custom Suggestions Provider Manifest File
      6. 23.4.6. Custom Suggestion User Experience
    5. 23.5. Using Action Keys and Application-Specific Search Data
      1. 23.5.1. Using Action Keys in Android Search
      2. 23.5.2. Working with Application-Specific Search Context
    6. 23.6. Resources
    7. 23.7. Implications for Tablets
    8. 23.8. Summary
  30. 24. Exploring Text to Speech
    1. 24.1. The Basics of Text-to-Speech Capabilities in Android
    2. 24.2. Using Utterances to Keep Track of Our Speech
    3. 24.3. Using Audio Files for Your Voice
    4. 24.4. Advanced Features of the TTS Engine
      1. 24.4.1. Setting Audio Streams
      2. 24.4.2. Using Earcons
      3. 24.4.3. Playing Silence
      4. 24.4.4. Choosing a Different Text-to-Speech Engine
      5. 24.4.5. Using Language Methods
    5. 24.5. References
    6. 24.6. Summary
  31. 25. Touch Screens
    1. 25.1. Understanding MotionEvents
      1. 25.1.1. The MotionEvent Object
      2. 25.1.2. Recycling MotionEvents
      3. 25.1.3. Using VelocityTracker
      4. 25.1.4. Exploring Drag and Drop
    2. 25.2. Multitouch
      1. 25.2.1. Multitouch Before Android 2.2
      2. 25.2.2. Multitouch Since Android 2.2
    3. 25.3. Touches with Maps
    4. 25.4. Gestures
      1. 25.4.1. The Pinch Gesture
      2. 25.4.2. GestureDetector and OnGestureListeners
      3. 25.4.3. Custom Gestures
      4. 25.4.4. The Gestures Builder Application
    5. 25.5. References
    6. 25.6. Summary
  32. 26. Using Sensors
    1. 26.1. What Is a Sensor?
      1. 26.1.1. Detecting Sensors
      2. 26.1.2. What Can We Know About a Sensor?
    2. 26.2. Getting Sensor Events
      1. 26.2.1. Issues with Getting Sensor Data
        1. 26.2.1.1. onAccuracyChanged() Always Says the Same Thing
        2. 26.2.1.2. No Direct Access to Sensor Values
        3. 26.2.1.3. Sensor Values not Sent Fast Enough
        4. 26.2.1.4. Sensors Turn Off with Screen in Android 2.1
          1. 26.2.1.4.1. The Unregister/Register Technique for Continual Sensor Updates
          2. 26.2.1.4.2. The Keep-the-Screen-On Technique for Continual Sensor Updates
    3. 26.3. Interpreting Sensor Data
      1. 26.3.1. Light Sensors
      2. 26.3.2. Proximity Sensors
      3. 26.3.3. Temperature Sensors
      4. 26.3.4. Pressure Sensors
      5. 26.3.5. Gyroscope Sensors
      6. 26.3.6. Accelerometers
        1. 26.3.6.1. Accelerometers and Display Orientation
        2. 26.3.6.2. Accelerometers and Gravity
        3. 26.3.6.3. Using Accelerometers to Measure the Device's Angle
      7. 26.3.7. Magnetic Field Sensors
      8. 26.3.8. Using Accelerometers and Magnetic Field Sensors Together
      9. 26.3.9. Orientation Sensors
      10. 26.3.10. Magnetic Declination and GeomagneticField
      11. 26.3.11. Gravity Sensors
      12. 26.3.12. Linear Acceleration Sensors
      13. 26.3.13. Rotation Vector Sensors
      14. 26.3.14. Near Field Communication Sensors
        1. 26.3.14.1. Enabling The NFC Sensor
        2. 26.3.14.2. Routing NFC Tags
        3. 26.3.14.3. Receiving NFC Tags
        4. 26.3.14.4. Reading NFC Tags
        5. 26.3.14.5. NFC Card Emulation
        6. 26.3.14.6. NFC Peer-to-Peer (P2P)
        7. 26.3.14.7. Testing NFC with NFCDemo
    4. 26.4. References
    5. 26.5. Summary
  33. 27. Exploring the Contacts API
    1. 27.1. Understanding Accounts
      1. 27.1.1. A Quick Tour of Account Screens
      2. 27.1.2. Relevance of Accounts to Contacts
      3. 27.1.3. Enumerating Accounts
    2. 27.2. Understanding Contacts Application
      1. 27.2.1. Show Contacts
      2. 27.2.2. Show Contact Detail
      3. 27.2.3. Edit Contact Details
      4. 27.2.4. Setting a Contact's Photo
      5. 27.2.5. Exporting Contacts
      6. 27.2.6. Various Contact Data Types
    3. 27.3. Understanding Contacts
      1. 27.3.1. Examining the Contents SQLite Database
      2. 27.3.2. Raw Contacts
      3. 27.3.3. Data Table
      4. 27.3.4. Aggregated Contacts
      5. 27.3.5. view_contacts
      6. 27.3.6. contact_entities_view
    4. 27.4. Working with the Contacts API
      1. 27.4.1. Exploring Accounts
        1. 27.4.1.1. The Menu file
        2. 27.4.1.2. Account Function Tester-Related files
          1. 27.4.1.2.1. IReportBack.java
          2. 27.4.1.2.2. BaseTester.java
          3. 27.4.1.2.3. AccountsFunctionTester.java
        3. 27.4.1.3. Driver Activity Classes
          1. 27.4.1.3.1. DebugActivity.java
          2. 27.4.1.3.2. debug_layout_activity.java
          3. 27.4.1.3.3. TestContactsDriverActivity.java
          4. 27.4.1.3.4. Manifest File
        4. 27.4.1.4. Running the Program
      2. 27.4.2. Exploring Aggregated Contacts
      3. 27.4.3. Exploring Raw Contacts
      4. 27.4.4. Exploring Raw Contact Data
      5. 27.4.5. Adding a Contact and Its Details
    5. 27.5. Controlling Aggregation
    6. 27.6. Impacts of Syncing
    7. 27.7. References
    8. 27.8. Summary
  34. 28. Deploying Your Application: Android Market and Beyond
    1. 28.1. Becoming a Publisher
      1. 28.1.1. Following the Rules
      2. 28.1.2. Developer Console
    2. 28.2. Preparing Your Application for Sale
      1. 28.2.1. Testing for Different Devices
      2. 28.2.2. Supporting Different Screen Sizes
      3. 28.2.3. Preparing AndroidManifest.xml for Uploading
      4. 28.2.4. Localizing Your Application
      5. 28.2.5. Preparing Your Application Icon
      6. 28.2.6. Considerations for Making Money From Apps
      7. 28.2.7. Directing Users Back to the Market
      8. 28.2.8. The Android Licensing Service
      9. 28.2.9. Preparing Your .apk File for Uploading
    3. 28.3. Uploading Your Application
    4. 28.4. User Experience on Android Market
    5. 28.5. Beyond Android Market
    6. 28.6. References
    7. 28.7. Summary
  35. 29. Fragments for Tablets and More
    1. 29.1. What is a Fragment?
      1. 29.1.1. When to Use Fragments
      2. 29.1.2. The Structure of a Fragment
      3. 29.1.3. A Fragment's Lifecycle
        1. 29.1.3.1. The onInflate() Callback
        2. 29.1.3.2. The onAttach() Callback
        3. 29.1.3.3. The onCreate() Callback
        4. 29.1.3.4. The onCreateView() Callback
        5. 29.1.3.5. The onActivityCreated() Callback
        6. 29.1.3.6. The onStart() Callback
        7. 29.1.3.7. The onResume() Callback
        8. 29.1.3.8. The onPause() Callback
        9. 29.1.3.9. The onStop() Callback
        10. 29.1.3.10. The onDestroyView() Callback
        11. 29.1.3.11. The onDestroy() Callback
        12. 29.1.3.12. The onDetach() Callback
        13. 29.1.3.13. Using setRetainInstance()
      4. 29.1.4. Sample Fragment App Showing the Lifecycle
    2. 29.2. FragmentTransactions and the Fragment Back Stack
      1. 29.2.1. Fragment Transaction Transitions and Animations
    3. 29.3. The FragmentManager
      1. 29.3.1. Caution When Referencing Fragments
      2. 29.3.2. ListFragments and <fragment>
      3. 29.3.3. Invoking a Separate Activity When Needed
      4. 29.3.4. Persistence of Fragments
    4. 29.4. Understanding Dialog Fragments
      1. 29.4.1. DialogFragment Basics
        1. 29.4.1.1. Constructing a Dialog Fragment
          1. 29.4.1.1.1. Overriding onCreateView
          2. 29.4.1.1.2. Overriding onCreateDialog
        2. 29.4.1.2. Displaying a Dialog Fragment
        3. 29.4.1.3. Dismissing a Dialog Fragment
        4. 29.4.1.4. Implications of a Dialog Dismiss
      2. 29.4.2. DialogFragment Sample Application
        1. 29.4.2.1. Dialog Sample: MainActivity
        2. 29.4.2.2. Dialog Sample: OnDialogDoneListener
        3. 29.4.2.3. Dialog Sample: PromptDialogFragment
        4. 29.4.2.4. Dialog Sample: HelpDialogFragment
        5. 29.4.2.5. Dialog Sample: AlertDialogFragment
        6. 29.4.2.6. Dialog Sample: Main Layout main.xml
    5. 29.5. More Communications with Fragments
      1. 29.5.1. Using startActivity() and setTargetFragment()
    6. 29.6. Custom Animations with ObjectAnimator
    7. 29.7. References
    8. 29.8. Summary
  36. 30. Exploring ActionBar
    1. 30.1. Anatomy of an Action Bar
    2. 30.2. Tabbed Navigation Action Bar Activity
      1. 30.2.1. Implementing Base Activity Classes
      2. 30.2.2. Assigning Uniform Behavior for the ActionBar
      3. 30.2.3. Implementing the Tabbed Listener
      4. 30.2.4. Implementing the Tabbed Action Bar Activity
        1. 30.2.4.1. Obtaining an Action Bar Instance
        2. 30.2.4.2. Action Bar Navigation Modes
      5. 30.2.5. Scrollable Debug Text View Layout
      6. 30.2.6. Action Bar and Menu Interaction
        1. 30.2.6.1. Displaying the Menu
        2. 30.2.6.2. Menu Items as Actions
      7. 30.2.7. Android Manifest File
      8. 30.2.8. Examining the Tabbed Action Bar Activity
    3. 30.3. List Navigation Action Bar Activity
      1. 30.3.1. Creating a SpinnerAdapter
      2. 30.3.2. Creating a List Listener
      3. 30.3.3. Setting Up a List Action Bar
      4. 30.3.4. Making Changes to BaseActionBarActivity
      5. 30.3.5. Making Changes to AndroidManifest.xml
      6. 30.3.6. Examining the List Action Bar Activity
    4. 30.4. Standard Navigation Action Bar Activity
      1. 30.4.1. StandardNavigationActionBarActivity
      2. 30.4.2. Making Changes to BaseActionBarActivity
      3. 30.4.3. Making Changes to AndroidManifest.xml
      4. 30.4.4. Examining the Standard Action Bar activity
    5. 30.5. References
    6. 30.6. Summary
  37. 31. Additional Topics in 3.0
    1. 31.1. List-Based Home Screen Widgets
      1. 31.1.1. New Remote Views in 3.0
      2. 31.1.2. Working with Lists in Remote Views
        1. 31.1.2.1. Preparing a Remote Layout
        2. 31.1.2.2. Loading a Remote Layout
        3. 31.1.2.3. Setting up RemoteViewsService
        4. 31.1.2.4. Setting up RemoteViewsFactory
          1. 31.1.2.4.1. RemoteViewsFactory Constructor
          2. 31.1.2.4.2. onCreate() Callback
          3. 31.1.2.4.3. onDestroy() Callback
          4. 31.1.2.4.4. getCount() Callback
          5. 31.1.2.4.5. getViewAt() Callback
          6. 31.1.2.4.6. getLoadingView() Callback
          7. 31.1.2.4.7. getViewTypeCount() Callback
          8. 31.1.2.4.8. getItemId() Callback
          9. 31.1.2.4.9. hasStableIds() Callback
          10. 31.1.2.4.10. onDataSetChanged() Callback
        5. 31.1.2.5. Setting up onClick Events
        6. 31.1.2.6. Responding to onClick Events
      3. 31.1.3. Working Sample: Test Home Screen List Widget
        1. 31.1.3.1. Creating the Test Widget Provider
        2. 31.1.3.2. Creating the Remote Views Factory
        3. 31.1.3.3. Coding Remote Views Service
        4. 31.1.3.4. Main Widget Layout file
          1. 31.1.3.4.1. Layout for the Individual List Items
        5. 31.1.3.5. Widget Provider Metadata
        6. 31.1.3.6. AndroidManifest.xml
      4. 31.1.4. Testing the Test List Widget
    2. 31.2. Drag and Drop
      1. 31.2.1. Basics of Drag and Drop in 3.0
      2. 31.2.2. Drag and Drop Sample Application
        1. 31.2.2.1. List of Files
        2. 31.2.2.2. Laying out the Sample Drag and Drop Application
        3. 31.2.2.3. Responding to onDrag in the Drop Zone
        4. 31.2.2.4. Setting up the Drag Source Views
      3. 31.2.3. Testing the Sample Drag-and-Drop Application
    3. 31.3. References
    4. 31.4. Summary

Product information

  • Title: Pro Android 3
  • Author(s):
  • Release date: April 2011
  • Publisher(s): Apress
  • ISBN: 9781430232223