Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Programming Android
Preface
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
I. Tools and Basics
1. Installing the Android SDK and Prerequisites
Installing the Android SDK and Prerequisites
The Java Development Kit (JDK)
The Eclipse Integrated Development Environment (IDE)
The Android SDK
Adding Build Targets to the SDK
The Android Developer Tools (ADT) Plug-in for Eclipse
Using the Install New Software Wizard to download and install the ADT plug-in
Configuring the ADT plug-in
Test Drive: Confirm That Your Installation Works
Making an Android Project
Making an Android Virtual Device (AVD)
Running a Program on an AVD
Running a Program on an Android Device
Troubleshooting SDK Problems: No Build Targets
Components of the SDK
The Android Debug Bridge (adb)
The Dalvik Debug Monitor Server (DDMS)
Components of the ADT Eclipse Plug-in
The Android Layout Editor
The Android Manifest Editor
XML editors for other Android XML files
Building Android apps
Running and debugging Android apps
The DDMS
Android Virtual Devices
QEMU
The SDK and AVD Manager
Other SDK Tools
Hierarchy Viewer
Layoutopt
Monkey
sqlite3
keytool
Zipalign
Draw 9-patch
android
Keeping Up-to-Date
Keeping the Android SDK Up-to-Date
Keeping Eclipse and the ADT Plug-in Up-to-Date
Keeping the JDK Up-to-Date
Example Code
SDK Example Code
Example Code from This Book
On Reading Code
2. Java for Android
Android Is Reshaping Client-Side Java
The Java Type System
Primitive Types
Objects and Classes
Object Creation
The Object Class and Its Methods
Objects, Inheritance, and Polymorphism
Final and Static Declarations
Abstract Classes
Interfaces
Exceptions
The Java Collections Framework
Collection interface types
Collection implementation types
Java generics
Garbage Collection
Scope
Java Packages
Access Modifiers and Encapsulation
Idioms of Java Programming
Type Safety in Java
Encapsulation
Getters and setters
Using Anonymous Classes
Modular Programming in Java
Basic Multithreaded Concurrent Programming in Java
Synchronization and Thread Safety
Thread Control with wait() and notify() Methods
Synchronization and Data Structures
3. The Ingredients of an Android Application
Traditional Programming Models Compared to Android
Activities, Intents, and Tasks
Other Android Components
Service
Content Providers
Using a content provider
Content providers and the Internet
BroadcastReceiver
Component Life Cycles
The Activity Life Cycle
On Porting Software to Android
Static Application Resources and Context
Organizing Java Source
Resources
Application Manifests
Initialization Parameters in AndroidManifest.xml
Packaging an Android Application: The .apk File
The Android Application Runtime Environment
The Dalvik VM
Zygote: Forking a New Process
Sandboxing: Processes and Users
The Android Libraries
Extending Android
The Android Application Template
Overrides and Callbacks
Polymorphism and Composition
Extending Android Classes
Concurrency in Android
AsyncTask and the UI Thread
Threads in an Android Process
Serialization
Java Serialization
Parcelable
Classes That Support Serialization
Serialization and the Application Life Cycle
4. Getting Your Application into Users’ Hands
Application Signing
Public Key Encryption and Cryptographic Signing
How Signatures Protect Software Users, Publishers, and Secure Communications
Self-signed certificates for Android software
Signing an Application
Debug certificates
Creating a self-signed certificate
Don’t lose it!
Using a self-signed certificate to sign an application
Placing an Application for Distribution in the Android Market
Becoming an Official Android Developer
Uploading Applications in the Market
Getting Paid
Alternative Distribution
Verizon Applications for Android
How to submit to the Verizon Apps store for Android
Technical tips for Verizon Android development
Related links
Amazon Applications for Android
Google Maps API Keys
Specifying API-Level Compatibility
Compatibility with Many Kinds of Screens
Testing for Screen Size Compatibility
Resource Qualifiers and Screen Sizes
5. Eclipse for Android Software Development
Eclipse Concepts and Terminology
Plug-ins
Workspaces
Java Environments
Eclipse’s Java Runtime Environment
The Java compiler
The application runtime
Projects
Builders and Artifacts
Extensions
Associations
Eclipse Views and Perspectives
The Package Explorer View
The Task List View
The Outline View
The Problems View
Java Coding in Eclipse
Editing Java Code and Code Completion
Refactoring
Eclipse and Android
Preventing Bugs and Keeping Your Code Clean
Static Analyzers
FindBugs
Applying Static Analysis to Android Code
Limitations of Static Analysis
Eclipse Idiosyncrasies and Alternatives
II. About the Android Framework
6. Building a View
Android GUI Architecture
The Model
The View
The Controller
Putting It Together
Assembling a Graphical Interface
Wiring Up the Controller
Listening to the Model
Listening for Touch Events
Multiple Pointers and Gestures
Listening for Key Events
Choosing an Event Handler
Advanced Wiring: Focus and Threading
The Menu and the Action Bar
View Debugging and Optimization
7. Fragments and Multiplatform Support
Creating a Fragment
Fragment Life Cycle
The Fragment Manager
Fragment Transactions
The Support Package
Fragments and Layout
8. Drawing 2D and 3D Graphics
Rolling Your Own Widgets
Layout
Measurement
Arrangement
Canvas Drawing
Drawing text
Matrix transformations
Drawables
Bitmaps
Bling
Shadows, Gradients, Filters, and Hardware Acceleration
Animation
Transition animation
Background animation
Surface view animation
OpenGL Graphics
9. Handling and Persisting Data
Relational Database Overview
SQLite
The SQL Language
SQL Data Definition Commands
SQLite types
Database constraints
SQL Data Manipulation Commands
Additional Database Concepts
Database Transactions
Example Database Manipulation Using sqlite3
SQL and the Database-Centric Data Model for Android Applications
The Android Database Classes
Database Design for Android Applications
Basic Structure of the SimpleVideoDbHelper Class
Using the Database API: MJAndroid
Android and Social Networking
The Source Folder (src)
Loading and Starting the Application
Database Queries and Reading Data from the Database
Using the query method
Modifying the Database
Inserting data into the database
Using the insert method
Using the execSQL method
Updating data already in the database
Using the update method
Using the execSQL method
Deleting data in the database
Using the delete method
Using the execSQL method
III. A Skeleton Application for Android
10. A Framework for a Well-Behaved Application
Visualizing Life Cycles
Visualizing the Activity Life Cycle
Memory recovery and life cycles
Life cycle methods of the Activity class
Saving and restoring instance state
Configuration changes and the activity life cycle
Minor life cycle methods of the Activity class
Visualizing the Fragment Life Cycle
The Activity Class and Well-Behaved Applications
The Activity Life Cycle and the User Experience
Life Cycle Methods of the Application Class
11. Building a User Interface
Top-Level Design
Fragment, Activity, and Scalable Design
Visual Editing of User Interfaces
Starting with a Blank Slate
Laying Out the Fragments
Lay Out Fragments Using the Visual Editor
Multiple Layouts
Folding and Unfolding a Scalable UI
Decisions about Screen Size and Resolution
Delegating to Fragment Classes
Making Activity, Fragment, Action Bar, and Multiple Layouts Work Together
Action Bar
Tabs and Fragments
The Other Activity
12. Using Content Providers
Understanding Content Providers
Implementing a Content Provider
Browsing Video with Finch
The simple video database
Structure of the simple version of the code
Defining a Provider Public API
Defining the CONTENT_URI
Creating the Column Names
Declaring Column Specification Strings
Writing and Integrating a Content Provider
Common Content Provider Tasks
Extending ContentProvider
File Management and Binary Data
Android MVC and Content Observation
A Complete Content Provider: The SimpleFinchVideoContentProvider Code
The SimpleFinchVideoContentProvider Class and Instance Variables
Implementing the onCreate Method
Implementing the getType Method
Implementing the Provider API
The query method
The insert method
The update method
The delete method
Determining How Often to Notify Observers
Declaring Your Content Provider
13. A Content Provider as a Facade for a RESTful Web Service
Developing RESTful Android Applications
A “Network MVC”
Summary of Benefits
Code Example: Dynamically Listing and Caching YouTube Video Content
Structure of the Source Code for the Finch YouTube Video Example
Stepping Through the Search Application
Step 1: Our UI Collects User Input
Step 2: Our Controller Listens for Events
Step 3: The Controller Queries the Content Provider with a managedQuery on the Content Provider/Model
Step 4: Implementing the RESTful Request
Constants and Initialization
Creating the Database
A Networked Query Method
RESTfulContentProvider: A REST helper
UriRequestTask
YouTubeHandler
insert and ResponseHandlers
File Management: Storing Thumbnails
IV. Advanced Topics
14. Search
Search Interface
Search Basics
Search logic
Index-based search logic
Database-backed search logic
Searchable configuration
Searchable activity
Search Dialog
Search Widget
Query Suggestions
Recent Query Suggestions
Custom Query Suggestions
15. Location and Mapping
Location-Based Services
Mapping
The Google Maps Activity
The MapView and MapActivity
Working with MapViews
MapView and MyLocationOverlay Initialization
Pausing and Resuming a MapActivity
Controlling the Map with Menu Buttons
Controlling the Map with the Keypad
Location Without Maps
The Manifest and Layout Files
Connecting to a Location Provider and Getting Location Updates
Updating the Emulated Location
Using geo to update location
Using DDMS to update location
StreetView
16. Multimedia
Audio and Video
Playing Audio and Video
Audio Playback
MediaPlayer audio playback
AudioTrack audio playback
Video Playback
Recording Audio and Video
Audio Recording
MediaRecorder audio recording
Intent audio recording
AudioRecorder audio recording
Video Recording
MediaRecorder video recording
Intent video recording
Stored Media Content
17. Sensors, NFC, Speech, Gestures, and Accessibility
Sensors
Position
Accelerometer
Gyroscope
Rotation vector
Linear acceleration
Gravity
Other Sensors
Near Field Communication (NFC)
Reading a Tag
Writing to a Tag
P2P Mode and Beam
API levels 10−13
Beam: API level 14+
Gesture Input
Accessibility
18. Communication, Identity, Sync, and Social Media
Account Contacts
Authentication and Synchronization
Authentication
Synchronization
Bluetooth
The Bluetooth Protocol Stack
Bluetooth-specific protocols and adopted protocols
BlueZ: The Linux Bluetooth Implementation
Using Bluetooth in Android Applications
Bluetooth and related I/O classes
The DeviceListActivity class
The BtConsoleActivity class
19. The Android Native Development Kit (NDK)
Native Methods and JNI Calls
Conventions in Native Method Calls
Conventions on the Java Side
The Android NDK
Setting Up the NDK Environment
Editing C/C++ Code in Eclipse
Compiling with the NDK
JNI, NDK, and SDK: A Sample App
Native Libraries and Headers Provided by the NDK
Building Your Own Custom Library Modules
Native Activities
Index
About the Authors
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →