Preface

This book is about PhoneGap—a really cool technology that allows you to build native mobile applications for multiple mobile device platforms using standard web technologies such as HTML, CSS, and JavaScript. I’d been looking at PhoneGap for several years, and when I finally got a chance to start working with it, I quickly found it to be a really simple and compelling way to build a single application that can run across multiple device platforms.

I knew Java from my work at RIM and from building Android applications. I’d poked around at Objective-C for iOS development and even did some work for Windows Mobile using Visual Basic. The world, however, is no longer focusing on applications for single mobile platforms but instead expects that mobile applications are available simultaneously for all popular mobile device platforms. PhoneGap helps solve that particular problem.

This book is for web developers who want to learn how to leverage the capabilities of the PhoneGap framework. It assumes you already know how to build web applications and are looking to understand the additional capabilities PhoneGap provides. The book highlights the PhoneGap API capabilities and how to use the tools provided with PhoneGap.

To understand the topics covered in this book, you will need to have some experience with one or more of the most popular smartphones. Some experience with smartphone SDKs is a benefit, but I’ll show you how to install and use the native SDKs as I discuss each supported platform.

The book is organized into three parts:

Part I, PhoneGap: Includes a very thorough introduction to PhoneGap: what it is, how it works, and more

Part II, PhoneGap Developer Tools: Includes instructions on how to install and use the SDKs and PhoneGap tools for each of the supported smartphone platforms

Part III, PhoneGap APIs: Includes a detailed description of each PhoneGap API plus sample code that illustrates how to exercise the API

Additional information, downloadable code projects, and errata can be found on the book’s web site at www.phonegapessentials.com.

When I first proposed this book to my publisher, it had a completely different structure than the book you’re reading now. As I started writing, I realized that the structure I’d picked didn’t work for people learning PhoneGap. So, I quickly reordered it and broke it into the parts listed earlier. I’ve tried to take you step-by-step through the things that matter for PhoneGap development. I also tried to make it as complete as possible—and not skip anything related to the topic at hand. This means, for example, that when you get to the chapters on configuring development environments for PhoneGap, you’ll see that I cover each supported platform in detail (with the exception of webOS since at the time HP indicated it was going to kill the platform). If you need to write PhoneGap applications for any of those platforms, you’ll find the information you need here. If you are focusing on a subset of the supported platforms, you’ll find that you will need to skip some chapters, but they’ll be there later if you expand the scope of your development efforts. The other PhoneGap books that preceded this one focused primarily on Android and iOS, and that didn’t seem right to me.

If you’re looking for a no-nonsense, complete guide to PhoneGap, this is it.

Inside the Book

As I worked through the manuscript, I deliberately assessed each topic against the book’s title and my goals for the publication. I kept my focus on PhoneGap and eliminated any topic that didn’t directly relate.

What you’ll find in the book:

• Lots of detailed information about PhoneGap and how PhoneGap works

• Lots of code examples

What you won’t find in this book:

• Mobile web development topics (this is a book about PhoneGap, not mobile web development)

• Complete listing of the phonegap.js source file

• Expressions or phrases in languages other than English

• Obscure references to pop-culture topics (although there is an obscure reference to Douglas Adams’ Hitchhiker’s Guide to the Galaxy and one blatant reference to Monty Python)

• Pictures of my cats (I have no cats, but a picture of one of my dogs did make it into the book)

As you look through the example code provided herein, it’s important to keep in mind that the code was deliberately written to clearly illustrate a particular PhoneGap-related topic or concept. While there are many things a developer can do to write compact and/or efficient code, it’s distracting to readers when they have to analyze every line in order to be able to tell what’s really going on therein. In this book, the code is expanded to make it as readable as possible. There are, for example, very few instances where JavaScript anonymous functions are used in the sample applications. Although using them would have made the code samples smaller, I deliberately eliminated them (in all but one chapter) for readability purposes.

No effort whatsoever has been made to optimize these examples for speed or compactness. They’ve been created to teach you the nuances of the PhoneGap APIs, not best practices for web development.

The Challenges in Writing a PhoneGap Book

Writing a book about PhoneGap (and many other mobile technologies) is hard. The writing isn’t hard, but keeping up with the changes that occur as you write is hard. For this book, a lot of important and interesting things happened during the writing process, and I found myself regularly rewriting chapters to accommodate recent changes. The good news is that most of the PhoneGap-specific content in here will remain valid for a very long time. It was industry changes and developer tool changes that gave me the most trouble.

Let me give you some examples:

Six (or more) versions of PhoneGap: When I started the book, version 1.0 of PhoneGap had just been released. It seemed that I’d picked the perfect time to start work on a PhoneGap book. It took me just about four-and-a-half months to write the manuscript, and during that time three additional versions of PhoneGap (1.1, 1.2, and 1.3) were released. During editing and all of the post-production work that needed to be done on the manuscript, versions 1.4 and 1.5 were released. I expect that by the time this book makes it onto paper, yet another version of PhoneGap, version 1.6, will have been released.

HP killing and then resurrecting webOS: As I started the manuscript, HP announced it was discontinuing its webOS devices and would be seeking someone to acquire the technology. For that reason, I decided to omit any webOS-related topics from the book. Of course, HP then changed its mind and announced it would be releasing webOS as an open source project. Unfortunately, the announcement was made after I’d finished the manuscript, so you will not find much information about webOS development for PhoneGap in this book. After the book is published, I will try to publish an update that includes information on webOS support.

Nokia changed the way it supported web development: Immediately after I completed the chapter on Symbian development, Nokia released a new version of its Symbian SDK that removed support for testing web applications on the simulator. Readers of this book will need to make sure they deploy an older version of the SDK in order to build and test PhoneGap applications for Symbian.

Adding Windows Phone support to PhoneGap: With the release of PhoneGap 1.2, the development team added partial support for Windows Phone development. This was fortunate since it allowed me to replace the webOS chapter with one on Windows Phone. With PhoneGap release 1.3, the team added full API support for Windows Phone development.

Adding BlackBerry PlayBook support to PhoneGap: In PhoneGap 1.3, the development team added support for the BlackBerry PlayBook. This, of course, completely changed the way the Ant scripts used to build BlackBerry applications worked, and the chapter had to be completely rewritten. The BlackBerry stuff stayed basically the same, but the command-line options changed, and a whole new suite of tools was added to support the PlayBook.

Deprecating support for the Symbian OS: Beginning with version 1.5, the PhoneGap project has removed support for Symbian from the PhoneGap download. You will have to download the code from a separate location if you want to continue to work with Symbian applications.

PhoneGap donated to the Apache project: One of the biggest changes that occurred during this process was Nitobi’s announcement that the project was being donated to the Apache Foundation. While not a huge change for the development community, what was difficult was that the project was supposed to get a name change. It was first donated to Apache as DeviceReady, but then because of a conflict with a company with the same name, it was quickly changed to Callback, which was for some bizarre reason later changed to Apache Cordova (named after the street where Nitobi’s offices were located). We’ve been told that the commercial product will keep the PhoneGap name while the open source project will have a different name, but I’m really not sure how that’s going to work out.

Nitobi Acquired by Adobe: Immediately following the previous announcement (actually the next day), Adobe Systems Incorporated (www.adobe.com) announced it was acquiring Nitobi, the company responsible for the PhoneGap project. That meant big changes for PhoneGap since the folks at Nitobi could now focus entirely on the PhoneGap project instead of working on it in their spare time. A while later, Adobe announced it was ceasing development of its Flash product for mobile devices. This was huge news and clearly indicated that PhoneGap now had a very important place in Adobe’s mobile strategy.

One of the biggest problems I faced was getting the help I needed when things didn’t work or didn’t make sense. As an open source project run by volunteers, many of my forum questions went unanswered (and to this day are still unanswered). You can try to get help there, but usually you’re on your own (all the more reason to pick up this book).

Code Conventions

I put a few notes and sidebars in the manuscript, but for the most part I kept the manuscript as clean and simple as I could. I did, however, illustrate sample code in two ways.

A code snippet, a section of a complete application, will be represented in the manuscript in the following manner:

var d = new Date(heading.timestamp);
hc.innerHTML = "Timestamp: " + d.toLocaleString();

The code could stand alone, like a complete function that you could use in your application, but in many cases this type of listing illustrates a piece of code that simply affects one small part of an application.

On the other hand, complete code listings will look like this:


HelloWorld Example

<!DOCTYPE HTML>
<html>
<head>
  <title>HelloWorld</title>
</head>
<body>
  <h1>Hello World!</h1>
  <p>This is a very simple web page.</p>
</body>
</html>


In this example, the code shown is a complete, functional application that you can copy into your IDE and use.

Web Resources

I’ve created a web site for the book: www.phonegapessentials.com (see Figure P-1). The site contains information about the book’s chapters but will also contain any errata (ideally none!), reader comments, and more. I will also make the book’s source code available so you can test the applications yourself and use the code from this book in your own projects.

I also regularly publish mobile development–related articles to my personal web site at www.johnwargo.com. Check out the site when you get a chance.

Image

Figure P-1 PhoneGap Essentials web site

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset