Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 328 trang
THÔNG TIN TÀI LIỆU
Cấu trúc
Cover
Copyright
Credits
About the Author
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Installing PhoneGap
Operating systems
Dependencies
Getting started with iOS
Time for action – Getting an app running on the simulator
Installing PhoneGap-iPhone
Time for action – Hello World with PhoneGap-iPhone
Getting started with Android
A note on development environments
Time for action – Getting the SDK running
PhoneGap Android
Time for action – Hello World on PhoneGap Android
What's in a PhoneGap Android application, anyway?
Getting started with BlackBerry web works
Time for action – Your first PhoneGap BlackBerry app
Code signing for BlackBerry
Summary
Chapter 2: Building and Debugging on Multiple Platforms
Designing with desktop browsers
WebKit
Developing our first application: You Are The Best
Time for action – Initial design and functionality
Our workflow
Our styles
Unobtrusiveness
Width and height
-webkit-border-radius
Our scripts
Unobtrusiveness
addEventListener
DOMContentLoaded
Using the web inspector
Accessing web inspector
Time for action – Simple logging and error checking
Moving to native platforms
Time for action – You Are The Best for iPhone
<meta name="viewport">
phonegap.js
deviceready
Summary
Chapter 3: Mobile Web to Mobile Applications
Implementing web server roles
Time for action – Implementing LocalStorage
Other storage options
Web SQL
Indexed DB
View templating
Time for action – Food detail view
Accessing remote resources
Cross-origin policy
Time for action – Talking about food
Accessing remote resources
Parsing remote data
Event delegation
Sleight: The PhoneGap development server
Summary
Chapter 4: Managing a Cross-Platform Codebase
Inherent differences between platforms
Using a single codebase
Time for action - Detection and fallbacks
User agent sniffing
Feature detection
Media queries
Preprocessing code
Summary
Chapter 5: HTML5 APIs and Mobile JavaScript
Mobile JavaScript
XUI
Time for action – Downloading, building, and using XUI
Why not jQuery?
HTML5
Media elements
Time for action – My dinner with PhoneGap
Media events and attributes
The audio element
The canvas element
Time for action: Dinner dashboard
The canvas API
A note on performance
What else is in HTML5?
Summary
Chapter 6: CSS3: Transitions, Transforms,
and Animation
Translate with transitions
Time for action – The modal tweet view
Timing functions
Other transformations
Scrolling
Viewports: Visual and otherwise
iScroll
Time for action – Scrolling list of food
Other approaches
Explicit animations
Time for action – Animating our headline
Animations: CSS3 or HTML5?
Summary
Chapter 7: Accessing Device Sensors with PhoneGap
What are device sensors?
Time for action – A postcard writer
PhoneGap versus HTML5
Other geolocation data
Accelerometer data
Time for action – Detecting shakes
Device orientation and device motion events
Orientation media queries
Time for action – Landscape postcards
Other media queries
Magnetometer: The missing API
Summary
Chapter 8: Accessing Camera Data and Files
Time for action – Hello World with the Camera API
Browsers are not emulators or devices
Image sources
Other options
What about when we finally get an image?
Time for action – Getting a file path to display
Where is this image, anyway?
Raw image data
Time for action – Saving pictures
Ensure quality is set
Editing or accessing live data
Summary
Chapter 9: Reading and Writing to Contacts
Time for action – navigator.service.contacts.find
ContactFields
Writing contact data
Time for action – Making friends
What if I encounter a new problem?
ContactFields, ContactName, and similar objects
Be responsible
Summary
Chapter 10: PhoneGap Plugins
Getting PhoneGap plugins
Time for action – Integrating ChildBrowser
Differences between platforms
Plugin discovery
Writing a PhoneGap plugin
Time for action – Battery view
Noteworthy information about the PhoneGap plugin with iOS
Porting your plugin
Time for action – Android and BlackBerry
Do you need cross-platform plugins?
No limits
Summary
Chapter 11: Working Offline: Sync and Caching
Ruby and Sinatra
Time for action – A news site, with an API
Alternatives to Sinatra
Caching new stories
Time for action – Caching stories in a local database
Managing application initialization
Summary
Appendix A: Deploying to iOS
Time for action–deploying to a device
Appendix B: Pop Quiz Answers
Chapter 1
PhoneGap iPhone Basics Answers
Chapter 2
Initial Design Answers
Chapter 3
Templating with Mustache Answers
Chapter 4
Feature Detection vs UA Sniffing Answers
Chapter 5
XUI Answers
Media Elements Pop Quiz Answers
Chapter 6
Scrolling Answers
Chapter 7
Geolocation Answers
Orientation and Media Queries Answers
Chapter 8
navigator.camera.getPicture Answers
Destination Types Answers
Chapter 9
Contacts Answers
Chapter 10
Using PhoneGap Plugins Answers
Writing PhoneGap Plugins Answers
Chapter 11
A Simple Web Service Answers
Index
Nội dung
[...]... Answers Chapter 10 Using PhoneGap Plugins Answers Writing PhoneGap Plugins Answers Chapter 11 A Simple Web Service Answers Index 295 295 295 295 296 296 297 297 298 298 298 299 299 299 299 300 300 300 301 301 301 302 302 302 303 303 237 [v] Preface PhoneGap: A Beginner's Guide is an introduction to PhoneGap: an open source, crossplatform framework for developing mobile applications PhoneGap allows developers... implementations for sprucing up the look and feel of your PhoneGap applications Chapter 7, Accessing Device Sensors with PhoneGap, demonstrates the use of PhoneGap' s device sensor capabilities for managing the location and accelerometer readings from your PhoneGap application Chapter 8, Accessing Camera Data and Files, shows how to use the PhoneGap APIs to manage access to the user's photo library... the Git installed and available in your PATH Enter the following command: $ git clone git://github.com /phonegap/ phonegap-iphone.git [ 12 ] Chapter 1 3 Now change into that directory, build the installer, and run it: $ cd phonegap- iphone $ make $ open PhoneGapLibInstaller.pkg 4 You'll see the PhoneGap GUI installer in front of you Follow the instructions onscreen—the installation process takes... Reading and Writing to Contacts, uses the Contacts APIs from PhoneGap to work with the user's native contacts list on their device, for use in your own application Chapter 10, PhoneGap Plugins, shows how the iOS, Android, and BlackBerry implementations of PhoneGap can be easily extended to access any native capabilities not exposed by the PhoneGap core APIs Chapter 11, Working Offline: Sync and Caching,... details Installing PhoneGap- iPhone First things first—yes, it should be called PhoneGap iOS As the old programming saying goes, there are only two hard problems in Computer Science: cache invalidation, off by one error and naming things You'll notice that neither of those problems involved PhoneGap, which is a doddle by comparison Let's get going Time for action – Hello World with PhoneGap- iPhone 1... ContactName, and similar objects Be responsible Summary 230 230 231 232 Chapter 10: PhoneGap Plugins 233 Getting PhoneGap plugins Time for action – Integrating ChildBrowser Differences between platforms Plugin discovery 234 234 241 241 Writing a PhoneGap plugin Time for action – Battery view 242 243 Noteworthy information about the PhoneGap plugin with iOS Porting your plugin Time for action – Android and BlackBerry... encounter any errors 5 Quit and reopen Xcode if you still have it open—it will need to be restarted for the PhoneGap Project Template to be visible [ 13 ] Installing PhoneGap 4 From the newly opened Xcode, select New Project again, and this time choose PhoneGap from the User Templates section, and PhoneGap- based Application from the main pane Call your new project FirstGapApp (or, you know, something... edit away at the PhoneGap library—that's the beauty of open source software But don't do that just yet [ 16 ] Chapter 1 The more eagle eyed among you will have noticed that the www folder contains only index.html, but it requires a file called phonegap. js on line 15 This JavaScript file isn't strictly necessary for PhoneGap development, but it does give you access to all of the PhoneGap APIs By... differences between a PhoneGap- based Xcode application and a regular view-based iOS application, but we'll come to those in due time Let's play around with our iPhone application for a bit, and then move onto the next platform Pop quiz – PhoneGap iPhone basics 1 Where are your PhoneGap assets (HTML, JavaScript, and CSS) located in an Xcode project? a In the project root b In the phonegap folder c In... folder 2 How do you rename a PhoneGap iOS application? a Change the tag in index.html b Rename index.html to SomeThingNew.html c Edit the Application-Info.plist file 3 What function is called by the alert('Hello PhoneGap! ') code? a The standard alert function in the iOS WebView b The alert function defined in phonegap. js c The native Objective-C notification API that PhoneGap links to Getting . 302 Using PhoneGap Plugins Answers 302 Wring PhoneGap Plugins Answers 302 Chapter 11 303 A Simple Web Service Answers 303 Index 237 Preface PhoneGap: A Beginner's Guide is an introducon to PhoneGap: . developer and all-around fall guy for the PhoneGap Build web service, a member of the PhoneGap team, and has over 10 years' experience with PhoneGap and related technologies. He is fond. with PhoneGap- iPhone 12 Geng started with Android 17 A note on development environments 18 Time for acon – Geng the SDK running 18 PhoneGap Android 22 Time for acon – Hello World on PhoneGap