You are previewing Multimobile Development: Building Applications for the iPhone and Android Platforms.
O'Reilly logo
Multimobile Development: Building Applications for the iPhone and Android Platforms

Book Description

You've developed a killer app for one mobile device—now it's time to maximize your intellectual investment and develop for the full spectrum of mobile platforms and devices. With Multimobile Development, you'll learn how to quickly retool between the iPhone and Android platforms and broaden the interest and audience of your app, without working with burdensome and error-prone compatibility layers and toolkits.

Multimobile Development takes you, the developer, through the same mobile software development project on both platforms, learning the differences between and the relative strengths and weaknesses of each platform as you go. No magic intermediate layers of obfuscation—by the time you get to the end you'll be an expert at developing for any of the major smartphone platforms using each vendor's preferred toolset and approach.

Multimobile Development covers the iPhone and Android platforms, two of the hottest mobile device platforms on the market today.

Table of Contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewer
  4. Acknowledgments
  5. 1. Introduction
    1. 1.1. What's the Purpose of This Book?
    2. 1.2. How Is This Book Structured?
    3. 1.3. Where Can You Get Help and Support?
    4. 1.4. Conclusion
  6. 2. The Six Bookmarks Server Service
    1. 2.1. Creating an API Account
      1. 2.1.1. Creating a User
    2. 2.2. The Users Service
      1. 2.2.1. RESTful Web Services
      2. 2.2.2. Testing the Calls
      3. 2.2.3. Examining Logon Operations
        1. 2.2.3.1. Obtaining a Token
        2. 2.2.3.2. Logging On the User
        3. 2.2.3.3. Cleaning Up
    3. 2.3. The Bookmarks Service
      1. 2.3.1. Adding Some Test Data
      2. 2.3.2. Working with OData
      3. 2.3.3. OData Queries
      4. 2.3.4. Issuing Updates over OData
      5. 2.3.5. Constraining Data to the Logged-On User
    4. 2.4. Conclusion
  7. 3. Application Architecture and Functional Specification
    1. 3.1. A Word About Slates
    2. 3.2. Functional Specification
      1. 3.2.1. Logging On
      2. 3.2.2. Synchronizing
      3. 3.2.3. Navigator
      4. 3.2.4. Configuring Bookmarks
      5. 3.2.5. Configuring a Single Bookmark ("Configure Singleton")
      6. 3.2.6. Missing Functionality
    3. 3.3. Application Architecture and Technical Specification
      1. 3.3.1. Approach
      2. 3.3.2. Object-Relational Mapping
        1. 3.3.2.1. Metadata
        2. 3.3.2.2. Entities
        3. 3.3.2.3. Generating Entities
        4. 3.3.2.4. SQL Statements
        5. 3.3.2.5. Change Processors
      3. 3.3.3. Server Communication
      4. 3.3.4. Technical Approach Broken Down by Platform
        1. 3.3.4.1. Core Toolset
        2. 3.3.4.2. Issue HTTP Requests
        3. 3.3.4.3. Read XML Document (Including Reading OData Results)
        4. 3.3.4.4. Write an XML Document
        5. 3.3.4.5. Maintain a Local Store
    4. 3.4. Conclusion
  8. 4. Android: Installing the Toolset
    1. 4.1. Why Android First?
    2. 4.2. Installing the Toolset
      1. 4.2.1. Installing Java
      2. 4.2.2. Installing Eclipse
      3. 4.2.3. Installing the Android SDK
        1. 4.2.3.1. Bug in the "r05" Installer
      4. 4.2.4. Installing the Android Development Tools (ADT) into Eclipse
    3. 4.3. Configuring the Emulator
    4. 4.4. Creating Our Android "Hello, World" Application
      1. 4.4.1. Saying "Hello, World"
      2. 4.4.2. Declarative Layout
      3. 4.4.3. Wiring Up the Button
    5. 4.5. Conclusion
  9. 5. Android: Building the Logon Form and Consuming REST Services
    1. 5.1. Creating the Project
    2. 5.2. Conventions for Presenting Code
    3. 5.3. Calling RESTful Services
      1. 5.3.1. Issuing Web Requests
        1. 5.3.1.1. The "DownloadSettings" Class
        2. 5.3.1.2. The "Download" and "DownloadXml" Methods
        3. 5.3.1.3. Extra Methods on "HttpHelper"
      2. 5.3.2. Authenticating Our API Account
        1. 5.3.2.1. The "LogonResponse"
        2. 5.3.2.2. Building the "XmlHelper" Class
        3. 5.3.2.3. Creating the "Logon" Method on the API Service
        4. 5.3.2.4. Wiring Up "EnsureApiAuthenticated"
      3. 5.3.3. Authenticating the User via "UsersService"
      4. 5.3.4. Setting "Allow Internet Access" Permission
    4. 5.4. Creating the Logon Form
      1. 5.4.1. Model/View/Controller
        1. 5.4.1.1. Contexts and Building the Controller
        2. 5.4.1.2. Binding the View and Controller
      2. 5.4.2. Logging On
      3. 5.4.3. "Remember Me"
    5. 5.5. Conclusion
  10. 6. Android: An ORM Layer on SQLite
    1. 6.1. SQLite on Android
    2. 6.2. Entities
      1. 6.2.1. "EntityType"
      2. 6.2.2. Creating the Basic "Entity" Class
      3. 6.2.3. Setting Values in an Entity
      4. 6.2.4. Building "Bookmark"
      5. 6.2.5. Registering the "EntityType"
    3. 6.3. Displaying Some Fake Bookmarks
      1. 6.3.1. Creating the Form
        1. 6.3.1.1. Creating the "Navigator.xml" Layout
        2. 6.3.1.2. Creating the Controller
        3. 6.3.1.3. Creating the View Interface
        4. 6.3.1.4. Creating the Navigator Activity
      2. 6.3.2. Showing the Bookmarks
        1. 6.3.2.1. Adding the Activity to the Manifest
        2. 6.3.2.2. Issuing the "Go to Navigator" "Intent"
      3. 6.3.3. Wiring Up the Bookmarks
    4. 6.4. Building the "Sync" Class
      1. 6.4.1. Calling the Server's Bookmarks OData Service
        1. 6.4.1.1. Namespaces
        2. 6.4.1.2. Adding Functionality to "XmlHelper"
        3. 6.4.1.3. Querying the Feed
        4. 6.4.1.4. Creating Entities from Name/Value Collections
      2. 6.4.2. Managing the Database
      3. 6.4.3. The "SqlStatement" Class and "ISqlStatementSource" Interface
      4. 6.4.4. Creating Tables
      5. 6.4.5. Examining the Database with Sqliteman
      6. 6.4.6. Writing Bookmarks to the Database
        1. 6.4.6.1. Building the Change Processor
        2. 6.4.6.2. Inserting Entities
        3. 6.4.6.3. Downloading Bookmarks
      7. 6.4.7. Reading Bookmarks and Displaying Them on the Navigator
        1. 6.4.7.1. Executing the Entity Collection
        2. 6.4.7.2. Asking the Navigator Controller to Load the Real Bookmarks
    5. 6.5. Conclusion
  11. 7. Android: Pushing Changes to the Server
    1. 7.1. Capturing Local Changes
      1. 7.1.1. Constraining SQL Filters
      2. 7.1.2. Excluding Deleted Entities from the View
      3. 7.1.3. Getting a Bookmark by Ordinal
      4. 7.1.4. Building the Configuration Form
        1. 7.1.4.1. List Views
        2. 7.1.4.2. Binding List Data
        3. 7.1.4.3. Selecting Items for Editing
        4. 7.1.4.4. Implementing Menus
        5. 7.1.4.5. Handling Menu Actions
        6. 7.1.4.6. Creating the Context Menu
      5. 7.1.5. Configuring Singletons
    2. 7.2. Pushing Changes to the Server
      1. 7.2.1. Detecting Local Changes
        1. 7.2.1.1. Building the "PushUpdates" Method
      2. 7.2.2. Issuing Server Requests to Insert, Update, and Delete
      3. 7.2.3. Update via "HTTP MERGE" and Insert via "HTTP POST"
        1. 7.2.3.1. The "ODataOperation" Enumeration
      4. 7.2.4. Marking Fields As Being Available on the Server
        1. 7.2.4.1. Building the XML
        2. 7.2.4.2. Building "ExecuteODataOperation"
    3. 7.3. Conclusion
  12. 8. iOS: Installing the Toolset
    1. 8.1. iPad Development
    2. 8.2. Installing Xcode
    3. 8.3. An Objective-C Primer for .NET and Java Developers
      1. 8.3.1. Problems with Objective-C
      2. 8.3.2. Calling Methods (aka "Sending Messages")
        1. 8.3.2.1. Creating the Project
      3. 8.3.3. Properties (and a Little Memory Management)
        1. 8.3.3.1. A Little More about Memory Management
      4. 8.3.4. Methods
      5. 8.3.5. Namespaces
      6. 8.3.6. The Biggest Gotcha in Objective-C
    4. 8.4. "Hello, World" for iPhone
      1. 8.4.1. Building the User Interface
      2. 8.4.2. Creating a Windows and Showing the View
        1. 8.4.2.1. Displaying the Message Box
    5. 8.5. Conclusion
  13. 9. iOS: Building the Logon Form and Consuming REST Services
    1. 9.1. Creating the Project
    2. 9.2. Creating the Logon Form
      1. 9.2.1. Creating the Logon Form User Interface
      2. 9.2.2. Showing the Logon Form
      3. 9.2.3. Special Note About Grouped Views
    3. 9.3. Conventions for Presenting Code in the iPhone Chapters
    4. 9.4. Calling the Services
      1. 9.4.1. Capturing the Logon Request
    5. 9.5. Calling the API Service
      1. 9.5.1. Building the Proxy Classes
        1. 9.5.1.1. The SBHttpHelper and SBDownloadBucket Classes
        2. 9.5.1.2. Implementing SBDownloadBucket
        3. 9.5.1.3. Making a Real Call to the API Service and Parsing the XML
      2. 9.5.2. Calling the Users Service
      3. 9.5.3. Notifying That Work Is in Progress
    6. 9.6. Conclusion
  14. 10. iOS: An ORM Layer on SQLite
    1. 10.1. A Note About Content That Has Already Been Covered
    2. 10.2. Entities
      1. 10.2.1. The SBEntityType Class
      2. 10.2.2. The SBEntity Class
      3. 10.2.3. Setting Values in an Entity
      4. 10.2.4. Building SBBookmark
      5. 10.2.5. Creating SBEntityType Instances
    3. 10.3. Displaying Some Fake Bookmarks
      1. 10.3.1. Creating the View
      2. 10.3.2. Building the View Engine
      3. 10.3.3. Displaying Bookmarks
      4. 10.3.4. Handling Navigation
    4. 10.4. Building the Sync Class
      1. 10.4.1. Calling the Server's Bookmarks OData Service
        1. 10.4.1.1. Namespaces
        2. 10.4.1.2. Querying the Feed
        3. 10.4.1.3. Stubbing SBSync
        4. 10.4.1.4. Parsing the XML
        5. 10.4.1.5. Spinning the Progress Wheel
      2. 10.4.2. Database Operations
        1. 10.4.2.1. Including SQLite
      3. 10.4.3. Building SBDBHelper and Implementing Error Handling
        1. 10.4.3.1. Defining SQL Statements
        2. 10.4.3.2. Creating Tables
        3. 10.4.3.3. Storing the Database in the Correct Location
      4. 10.4.4. Writing Bookmarks to the Database
        1. 10.4.4.1. Building the Change Processor
        2. 10.4.4.2. Completing getLatest
        3. 10.4.4.3. Reading Bookmarks and Displaying Them on the Navigator
    5. 10.5. Conclusion
  15. 11. iOS : Pushing Changes Back to the Server
    1. 11.1. Configuring Bookmarks
      1. 11.1.1. Putting Data on the Table
      2. 11.1.2. Sorting the Bookmarks
      3. 11.1.3. Singleton View
      4. 11.1.4. Editing a Bookmark
        1. 11.1.4.1. Capturing and Committing Changes
      5. 11.1.5. Implementing the Delete Method
      6. 11.1.6. Adding a Bookmark
      7. 11.1.7. Deleting Bookmarks
      8. 11.1.8. Manually Syncing
    2. 11.2. Pushing Changes to the Server
      1. 11.2.1. Work Items
      2. 11.2.2. Issuing OData Change Requests
      3. 11.2.3. Flagging Fields As "Not on Server"
      4. 11.2.4. Issuing Requests
        1. 11.2.4.1. Implementing executeODataOperation
      5. 11.2.5. Modifying processWorkItems
    3. 11.3. Conclusion
  16. 12. iOS: MonoTouch
    1. 12.1. Mono in the Big Picture
    2. 12.2. Chapter Structure
    3. 12.3. Installing MonoTouch
    4. 12.4. "Hello, World"
      1. 12.4.1. Inspecting the Code-Behind
      2. 12.4.2. Wiring Up the Button
      3. 12.4.3. Running the Project
    5. 12.5. Calling the Six Bookmarks API RESTful Service
      1. 12.5.1. Creating the Project
      2. 12.5.2. Building ServiceProxy Et Al.
      3. 12.5.3. Calling the Service Method
    6. 12.6. Conclusion