Apress Multimobile Development, Building Applications for the iPhone and Android Platforms (2010)

Apress Multimobile Development, Building Applications for the iPhone and Android Platforms (2010)

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: BOOKS FOR PROFESSIONALS BY PROFESSIONALS® Companion eBook M ultimobile Development: Building Applications for iPhone and Android is the essential book if you want to learn how to natively target the iOS and Android mobile platforms. You’ll wall through the process of building the same application on both platforms, learning the differences and relative strengths and weaknesses of each. You’ll also get answers to the most common questions developers have, and get you a leg up into understanding the platforms so that you can get on and do the clever thing that only you’ve thought of. Each section starts by looking at installing the toolset and building a “Hello, World” application to get comfortable. Then, you learn to build a proper, end-to-end application that involves Internet communication over HTTP up to a public cloud-based service, local storage using SQLite, a custom object-relational mapping layer and a device-specific user interface. The sections are preceded with a detailed section of the cloud-based service implementation, as well as the application architecture and functional specification. There’s also a bonus chapter on MonoTouch. You’ll learn: • How to develop, end-to-end, the same application on iPhone and Android platforms. • The different service architectures available on each platform, concentrating on services related to storage, communications and security. • Key differences in deploying and managing applications on the various platforms. • How to translate experience at developing on one platform to speed development when attempting a project on a different platform. All of the code is available on GitHub and is licensed under the Mozilla Public License (MPL ) open source license should you wish to use any of it in your own applications. You will also find support resources at http://www.multimobiledevelopment.com/ to help you get the most out of the book. COMPANION eBOOK SEE LAST PAGE FOR DETAILS ON $10 eBOOK VERSION Baxter-Reynolds Matthew Baxter-Reynolds works as an independent software development consultant helping business achieve more from their software teams. His particular interests lie in open standards, the Microsoft server stack and the “big four” mobile computing platforms. Multimobile Development RELATED TITLES Available Discover developing an application end-to-end natively Multimobile Development Building Applications for iPhone and Android Matthew Baxter-Reynolds Shelve in Mobile Computing SOURCE CODE ONLINE www.apress.com Baxter/Reynolds 3198-1 LSI.indd 1 User level: Beginning–Advanced 9/15/10 3:46 PM Multimobile Development Building Applications for the iPhone and Android Platforms ■■■ Matthew Baxter-Reynolds Multimobile Development: Building Applications for the iPhone and Android Platforms Copyright © 2010 by Matthew Baxter-Reynolds All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-3198-1 ISBN-13 (electronic): 978-1-4302-3199-8 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Jonathan Hassell Technical Reviewer: Matthew Fitchett Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anita Castro Copy Editor: Mary Ann Fugate Compositor: Lynn L’Heureux Indexer: Potomac Indexing, LLC Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. 0x34 0x4D 0x2B 0x45 ■CONTENTS Contents at a Glance ■About the Author.................................................................................................................xiii ■About the Technical Reviewer............................................................................................ xiv ■Acknowledgements ............................................................................................................. xv ■Chapter 1: Introduction..........................................................................................................1 ■Chapter 2: The Six Bookmarks Server Service .....................................................................5 ■Chapter 3: Application Architecture and Functional Specification...................................19 ■Chapter 4: Android: Installing the Toolset ..........................................................................35 ■Chapter 5: Android: Building the Logon Form and Consuming REST Services .................55 ■Chapter 6: Android: An ORM Layer on SQLite ....................................................................93 ■Chapter 7: Android: Pushing Changes to the Server .......................................................155 ■Chapter 8: iOS: Installing the Toolset................................................................................211 ■Chapter 9: iOS: Building the Logon Form and Consuming REST Services......................237 ■Chapter 10: iOS: An ORM Layer on SQLite.........................................................................291 ■Chapter 11: iOS : Pushing Changes Back to the Server ..................................................381 ■Chapter 12: iOS: MonoTouch .............................................................................................427 ■Index...................................................................................................................................447 v ■CONTENTS Contents ■About the Author.................................................................................................................xiii ■About the Technical Reviewer............................................................................................ xiv ■Acknowledgements ............................................................................................................. xv ■Chapter 1: Introduction..........................................................................................................1 What’s the Purpose of This Book? ............................................................................................2 How Is This Book Structured?...................................................................................................2 Where Can You Get Help and Support?.....................................................................................4 Conclusion ...............................................................................................................................4 ■Chapter 2: The Six Bookmarks Server Service .....................................................................5 Creating an API Account ...........................................................................................................5 Creating a User ..................................................................................................................6 The Users Service ....................................................................................................................8 RESTful Web Services........................................................................................................8 Testing the Calls ................................................................................................................9 Examining Logon Operations..............................................................................................9 The Bookmarks Service..........................................................................................................12 Adding Some Test Data ...................................................................................................12 Working with OData .........................................................................................................13 OData Queries .................................................................................................................17 Issuing Updates over OData .............................................................................................18 Constraining Data to the Logged-On User ........................................................................18 Conclusion .............................................................................................................................18 vii ■CONTENTS ■Chapter 3: Application Architecture and Functional Specification...................................19 A Word About Slates...............................................................................................................19 Functional Specification .........................................................................................................19 Logging On ......................................................................................................................20 Synchronizing ..................................................................................................................20 Navigator .........................................................................................................................21 Configuring Bookmarks....................................................................................................22 Configuring a Single Bookmark (“Configure Singleton”) ...................................................23 Missing Functionality .......................................................................................................23 Application Architecture and Technical Specification ..............................................................24 Approach .........................................................................................................................24 Object-Relational Mapping...............................................................................................25 Server Communication.....................................................................................................29 Technical Approach Broken Down by Platform .................................................................30 Conclusion .............................................................................................................................33 ■Chapter 4: Android: Installing the Toolset ..........................................................................35 Why Android First? .................................................................................................................35 Installing the Toolset ..............................................................................................................35 Installing Java..................................................................................................................35 Installing Eclipse..............................................................................................................36 Installing the Android SDK................................................................................................36 Installing the Android Development Tools (ADT) into Eclipse.............................................37 Configuring the Emulator........................................................................................................41 Creating Our Android “Hello, World” Application .....................................................................44 Saying “Hello, World” ......................................................................................................47 Declarative Layout ...........................................................................................................47 Wiring Up the Button........................................................................................................49 Conclusion .............................................................................................................................54 ■Chapter 5: Android: Building the Logon Form and Consuming REST Services .................55 Creating the Project................................................................................................................55 Conventions for Presenting Code ............................................................................................56 Calling RESTful Services.........................................................................................................57 Issuing Web Requests......................................................................................................57 Authenticating Our API Account........................................................................................62 viii ■CONTENTS Authenticating the User via “UsersService”......................................................................73 Setting “Allow Internet Access” Permission .....................................................................74 Creating the Logon Form ........................................................................................................75 Model/View/Controller......................................................................................................79 Logging On ......................................................................................................................86 “Remember Me” .............................................................................................................89 Conclusion .............................................................................................................................91 ■Chapter 6: Android: An ORM Layer on SQLite ....................................................................93 SQLite on Android ..................................................................................................................93 Entities...................................................................................................................................93 “EntityType” ....................................................................................................................94 Creating the Basic “Entity” Class ...................................................................................100 Setting Values in an Entity..............................................................................................102 Building “Bookmark” .....................................................................................................107 Registering the “EntityType” ..........................................................................................109 Displaying Some Fake Bookmarks........................................................................................110 Creating the Form..........................................................................................................110 Showing the Bookmarks ................................................................................................117 Wiring Up the Bookmarks ..............................................................................................122 Building the “Sync” Class.....................................................................................................124 Calling the Server’s Bookmarks OData Service...............................................................124 Managing the Database .................................................................................................132 The “SqlStatement” Class and “ISqlStatementSource” Interface....................................134 Creating Tables..............................................................................................................135 Examining the Database with Sqliteman ........................................................................139 Writing Bookmarks to the Database ...............................................................................143 Reading Bookmarks and Displaying Them on the Navigator ...........................................148 Conclusion ...........................................................................................................................153 ■Chapter 7: Android: Pushing Changes to the Server .......................................................155 Capturing Local Changes......................................................................................................155 Constraining SQL Filters.................................................................................................155 Excluding Deleted Entities from the View .......................................................................161 Getting a Bookmark by Ordinal.......................................................................................162 Building the Configuration Form.....................................................................................163 Configuring Singletons...................................................................................................186 ix ■CONTENTS Pushing Changes to the Server.............................................................................................194 Detecting Local Changes ...............................................................................................194 Issuing Server Requests to Insert, Update, and Delete....................................................198 Update via “HTTP MERGE” and Insert via “HTTP POST” .................................................199 Marking Fields As Being Available on the Server ............................................................199 Conclusion ...........................................................................................................................209 Download from Wow! eBook <www.wowebook.com> ■Chapter 8: iOS: Installing the Toolset................................................................................211 iPad Development ................................................................................................................211 Installing Xcode....................................................................................................................211 An Objective-C Primer for .NET and Java Developers.....................................
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern