PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap...

51
PhoneGap Cross the Gap from HTML5 to Mobile OSCON 2012 Paul Beusterien July 19, 2012

Transcript of PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap...

Page 1: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap Cross the Gap from HTML5 to Mobile

OSCON 2012

Paul BeusterienJuly 19, 2012

Page 2: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Today's Talk● Why Web Development for Mobile? ● Why PhoneGap?● What is PhoneGap?● Technology Map

Slides at http://goo.gl/Uf625

Page 3: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Follow Along

http://www.mobiledevelopersolutions.com● Requires: Eclipse ADT● See Get Started with AppLaud

http://www.applaudcloud.com● Web-based development● Google Chrome● AppLaud App (install from QRcode)

OR

Eclipse Plugin for PhoneGap Android

AppLaud Cloud

Page 4: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

About Me - Paul Beusterien

● Creating top-notch mobile development solutions

[email protected]

● @paulbeusterien

● http://www.mobiledevelopersolutions.com● http://www.applaudcloud.com

Page 5: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Who Need Apps?

1 Billion television sets worldwide

Page 6: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Fragmentation

Page 7: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

HTML5 to the Rescue

Page 8: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

(Hint: There are Lots of Web Developers)

Who Can Write HTML5?

Page 9: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Making Sense of it All

Page 10: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Running as a Web PageBrowser Device Browser

Page 11: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Running as a Native App

Page 12: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Native Vs Web

Why not use both?

Page 13: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Mobile Capabilities

Page 14: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap APIs

http://docs.phonegap.com/

Page 15: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap Demo

Page 16: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Accelerometer

Captures device motion in the x, y and z direction

Methods:○ getCurrentAcceleration○ watchAcceleration○ clearWatch

Page 17: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Camera

Provide access to default camera application

Methods:○ getPicture

Page 18: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Capture

Provides access to the audio, image, and video capabilities of the device

Methods:○ captureAudio○ captureImage○ captureVideo○ MediaFile.getFormatData

Page 19: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Compass

Obtain the direction the device is pointing

Methods:○ getCurrentHeading○ watchHeading○ clearWatch

Page 20: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Connection

The connection object gives access to the device's cellular and wifi connection information.Properties:

○ connection.type

Constants:○ Connection.UNKNOWN○ Connection.ETHERNET○ Connection.WIFI○ Connection.CELL_2G○ Connection.CELL_3G○ Connection.CELL_4G○ Connection.CELL_NONE

Page 21: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Contacts

Provide access to the device contacts database

Methods:○ create○ find

Page 22: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Device

The device object describes the device's hardware and software

Properties:○ device.name○ device.phonegap○ device.platform○ device.uuid○ device.version

Page 23: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Events

PhoneGap Lifecycle events

Event Types:● deviceready● pause● resume● online● offline● backbutton● batterycritical● batterylow● batterystatus

● menubutton● searchbutton● startcallbutton● endcallbutton● volumedownbutton● volumeupbutton

Page 24: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

File

An API to read, write and navigate file system hierarchies.

Objects and Methods for:○ Directory Navigation○ File Read○ File Write○ File Transfer

Page 25: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Geolocation

Provide location information for the device

Methods:○ getCurrentPosition○ watchPosition○ clearWatch

Page 26: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Media

Provide the ability to record and play back audio files on a device

Methods:○ getCurrentPosition○ getDuration○ play○ pause○ release○ seekTo○ startRecord○ stopRecord○ stop

Page 27: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Notification

Visual, audible and tactile device notifications

Methods:○ alert○ confirm○ beep○ vibrate

Page 28: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Storage

Provide access to the device's storage options.

Web Storage Methods:○ openDatabase○ transaction○ changeVersion○ executeSql○ item

Local Storage Methods:○ key○ getItem○ setItem○ removeItem○ clear

Page 29: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap Implementation● Embeds a chromeless browser in a native app● Creates a bridge from the browser to native via a set

of JavaScript APIs

Page 30: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Android Implementation

● Was (pre Android 2.3)○ WebView ○ addJavaScriptInterface

● Now○ onJsPrompt override

PhoneGap Bridge

Page 31: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap Goals and Principles

● "The purpose of PhoneGap is for PhoneGap to cease to exist."

- Brian LeRoux, Adobe PhoneGap Lead

● Embrace web technology - HTML5● Build a first-class development environment around web technology

Page 32: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap and Titanium

Page 33: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap vs Titanium

Thanks -> Tony Lukasavage http://savagelook.com/blog/portfolio/phonegap-is-web-based-appcelerator-is-pure-javascript

Page 34: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap Platforms

http://phonegap.com/about/features

(all major smart phone OS's!)

Page 35: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

PhoneGap Plugins

Extending PhoneGap

● Provide JavaScript APIs for native capabilities

● Examples include Bluetooth, Speech Recognizer, ChildBrowser, TTS, Status Bar Notification and ftp

● Many are open sourced at https://github.com/phonegap/phonegap-plugins

Page 36: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Plugin Basics1. Native Part - Java on Android

○ Add Java Class, Include Java Code2. JavaScript Part

○ Add JS file to project, Edit index.html3. Connect Plugin to App

○ Edit res/xml/plugins.xml4. README file

○ Permissions - AndroidManifest.xml○ Plugin-specific instructions: init calls, resources○ API description and usage examples

Page 37: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Apache Cordova?

(Apache Callback)

Apache Cordova

October 3, 2011

Page 38: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

UI Libraries

Page 39: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Mobile UI Paradigm

● Optimized for Touch○ Finger-sized controls○ Minimize typing

■ Smart forms - buttons, sliders, etc.○ Swipe and tap events

■ No mouse-overs and clicks● Orientation/Layout Change● Themes and Transitions

Page 40: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

UI Frameworks

Sencha

Jo EmbedJS zepto.js jQ.Mobi

Page 41: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

jQuery Mobile

Touch-Optimized Web Framework for Smartphones & Tablets

"A unified user interface system across all popular mobile device platforms, built on the rock-solid jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily themeable design."

Page 42: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Simulation/Emulation

App Stores

Page 43: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Ripple Demo

Page 44: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Debug

App Stores

Page 45: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Weinre Demoweinre is WEb INspector REmote

Page 46: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

debug.phonegap.com

Page 47: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Jo EmbedJS zepto.js

Pulling it all Together

Sencha

Debug

Emulate

Page 48: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

AppLaud Eclipse Plugin

Page 49: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

AppLaud Cloud

● Demo

Page 50: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

Today's Talk● Why Web Development for Mobile? ● Why PhoneGap?● What is PhoneGap?● Technology Map● Live Demos

Slides at http://goo.gl/qoyk4

Page 51: PhoneGap OSCON 2012assets.en.oreilly.com/1/event/80/PhoneGap _ Cross the Gap from HT… · PhoneGap Goals and Principles "The purpose of PhoneGap is for PhoneGap to cease to exist."

More ...

● http://www.phonegap.com ● https://groups.google.com/forum/#!forum/phonegap● http://stackoverflow.com/questions/tagged/phonegap● http://incubator.apache.org/projects/callback.html● http://www.mobiledevelopersolutions.com● http://www.applaudcloud.com● twitter @paulbeusterien

Slides at http://goo.gl/Uf625

* Some images from Creative Commons* Thanks to Brian LeRoux of Adobe for input