You are previewing Programming Android, 2nd Edition.

Programming Android, 2nd Edition

Cover of Programming Android, 2nd Edition by G. Blake Meike... Published by O'Reilly Media, Inc.
  1. Programming Android
  2. Preface
    1. How This Book Is Organized
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  3. I. Tools and Basics
    1. 1. Installing the Android SDK and Prerequisites
      1. Installing the Android SDK and Prerequisites
      2. Test Drive: Confirm That Your Installation Works
      3. Components of the SDK
      4. Keeping Up-to-Date
      5. Example Code
      6. On Reading Code
    2. 2. Java for Android
      1. Android Is Reshaping Client-Side Java
      2. The Java Type System
      3. Scope
      4. Idioms of Java Programming
    3. 3. The Ingredients of an Android Application
      1. Traditional Programming Models Compared to Android
      2. Activities, Intents, and Tasks
      3. Other Android Components
      4. Component Life Cycles
      5. Static Application Resources and Context
      6. The Android Application Runtime Environment
      7. Extending Android
      8. Concurrency in Android
      9. Serialization
    4. 4. Getting Your Application into Users’ Hands
      1. Application Signing
      2. Placing an Application for Distribution in the Android Market
      3. Alternative Distribution
      4. Google Maps API Keys
      5. Specifying API-Level Compatibility
      6. Compatibility with Many Kinds of Screens
    5. 5. Eclipse for Android Software Development
      1. Eclipse Concepts and Terminology
      2. Eclipse Views and Perspectives
      3. Java Coding in Eclipse
      4. Eclipse and Android
      5. Preventing Bugs and Keeping Your Code Clean
      6. Eclipse Idiosyncrasies and Alternatives
  4. II. About the Android Framework
    1. 6. Building a View
      1. Android GUI Architecture
      2. Assembling a Graphical Interface
      3. Wiring Up the Controller
      4. The Menu and the Action Bar
      5. View Debugging and Optimization
    2. 7. Fragments and Multiplatform Support
      1. Creating a Fragment
      2. Fragment Life Cycle
      3. The Fragment Manager
      4. Fragment Transactions
      5. The Support Package
      6. Fragments and Layout
    3. 8. Drawing 2D and 3D Graphics
      1. Rolling Your Own Widgets
      2. Bling
    4. 9. Handling and Persisting Data
      1. Relational Database Overview
      2. SQLite
      3. The SQL Language
      4. SQL and the Database-Centric Data Model for Android Applications
      5. The Android Database Classes
      6. Database Design for Android Applications
      7. Using the Database API: MJAndroid
  5. III. A Skeleton Application for Android
    1. 10. A Framework for a Well-Behaved Application
      1. Visualizing Life Cycles
      2. Visualizing the Fragment Life Cycle
      3. The Activity Class and Well-Behaved Applications
      4. Life Cycle Methods of the Application Class
    2. 11. Building a User Interface
      1. Top-Level Design
      2. Visual Editing of User Interfaces
      3. Starting with a Blank Slate
      4. Laying Out the Fragments
      5. Folding and Unfolding a Scalable UI
      6. Making Activity, Fragment, Action Bar, and Multiple Layouts Work Together
      7. The Other Activity
    3. 12. Using Content Providers
      1. Understanding Content Providers
      2. Defining a Provider Public API
      3. Writing and Integrating a Content Provider
      4. File Management and Binary Data
      5. Android MVC and Content Observation
      6. A Complete Content Provider: The SimpleFinchVideoContentProvider Code
      7. Declaring Your Content Provider
    4. 13. A Content Provider as a Facade for a RESTful Web Service
      1. Developing RESTful Android Applications
      2. A “Network MVC”
      3. Summary of Benefits
      4. Code Example: Dynamically Listing and Caching YouTube Video Content
      5. Structure of the Source Code for the Finch YouTube Video Example
      6. Stepping Through the Search Application
      7. Step 1: Our UI Collects User Input
      8. Step 2: Our Controller Listens for Events
      9. Step 3: The Controller Queries the Content Provider with a managedQuery on the Content Provider/Model
      10. Step 4: Implementing the RESTful Request
  6. IV. Advanced Topics
    1. 14. Search
      1. Search Interface
      2. Query Suggestions
    2. 15. Location and Mapping
      1. Location-Based Services
      2. Mapping
      3. The Google Maps Activity
      4. The MapView and MapActivity
      5. Working with MapViews
      6. MapView and MyLocationOverlay Initialization
      7. Pausing and Resuming a MapActivity
      8. Controlling the Map with Menu Buttons
      9. Controlling the Map with the Keypad
      10. Location Without Maps
      11. StreetView
    3. 16. Multimedia
      1. Audio and Video
      2. Playing Audio and Video
      3. Recording Audio and Video
      4. Stored Media Content
    4. 17. Sensors, NFC, Speech, Gestures, and Accessibility
      1. Sensors
      2. Near Field Communication (NFC)
      3. Gesture Input
      4. Accessibility
    5. 18. Communication, Identity, Sync, and Social Media
      1. Account Contacts
      2. Authentication and Synchronization
      3. Bluetooth
    6. 19. The Android Native Development Kit (NDK)
      1. Native Methods and JNI Calls
      2. The Android NDK
      3. Native Libraries and Headers Provided by the NDK
      4. Building Your Own Custom Library Modules
      5. Native Activities
  7. Index
  8. About the Authors
  9. Colophon
  10. Copyright

Chapter 6. Building a View

Android comes with many requirements that herald complexity in the user interface; it’s a multiprocessing system that supports multiple concurrent applications, accepts multiple forms of input, is highly interactive, and is flexible enough to support a wide range of devices now and in the future. The user interface is both rich and easy to use.

This chapter provides you with the techniques for implementing a graphical interface on Android. It explains the architecture of the Android UI toolkit, while showing you in practical terms how to use basic interface elements such as buttons and text boxes. It also covers event handling, using multiple threads to offload long-running tasks so that the UI doesn’t freeze, and other topics that make user interfaces pleasant and performant.

Android GUI Architecture

The Android environment adds yet another GUI toolkit to the Java ecosystem, joining AWT, Swing, SWT, LWUIT, and others. If you have worked with any of these, the Android UI framework will look familiar. Like them, it is single-threaded, event-driven, and built on a library of nestable components.

The Android UI framework is, like other Java UI frameworks, organized around the common Model-View-Controller (MVC) pattern illustrated in Figure 6-1. It provides structure and tools for building a Controller that handles user input (such as keystrokes and screen taps) and a View that renders graphical information to the screen.

Figure 6-1. Model-View-Controller concept ...

The best content for your career. Discover unlimited learning on demand for around $1/day.