mobile application development using phonegap

88
1 Mobile Applications using PhoneGap Rohit Ghatol QuickOffice

Upload: indicthreads

Post on 06-Mar-2015

149 views

Category:

Documents


4 download

DESCRIPTION

Presented By Rohit Ghatol at the 2nd IndicThreads.com Conference On Mobile Application Development, August 2011 http://Mobile.IndicThreads.com

TRANSCRIPT

Page 1: Mobile Application Development using PhoneGap

1

Mobile Applications

using PhoneGap Rohit Ghatol

QuickOffice

Page 2: Mobile Application Development using PhoneGap

2

Introduction• Architect @ QuickOffice

• Author @ Apress – Beginning PhoneGap

• Write articles for PhoneGap Wiki

• Technical Talks and Corporate Training

Page 3: Mobile Application Development using PhoneGap

3

Topics1. Short Intro to PhoneGap2. Choosing the right UI Framework

(jQueryMobile, Sencha or GWT)3. Remote Debugging4. Building in the Cloud5. Extending PhoneGap6. Capabilities like OAuth

Page 4: Mobile Application Development using PhoneGap

4

Short Intro to PhoneGap

Page 5: Mobile Application Development using PhoneGap

5

Mobile Platforms

iOS Android

BlackBerry Symbian

WebOS Win7

Bada

Page 6: Mobile Application Development using PhoneGap

6

Common Platform Approach

Page 7: Mobile Application Development using PhoneGap

7

Modern Browsers

Mobile OS BrowserAndroid Webkit basediPhone Webkit basedBlackBerry 6.0 + Webkit basedWindow Phone 7 IE 7-9 based *WebOS Webkit basedNokia Webkit based

All new Smart Phones come with modern browsers, which have better support for HTML5/CSS3 specs

Page 8: Mobile Application Development using PhoneGap

8

WebViewsAll of these smart phones supports using these modern browsers as embedded views (aka WebViews)

WebView WebView

Page 9: Mobile Application Development using PhoneGap

9

9

JavaScript to native and back

Native Code(Java/C++/ObjC)

JSON packets

All these browser engine (most common being webkit) support Javascript to talk to native code and back

HTML/Javascript

WebView

Page 10: Mobile Application Development using PhoneGap

10

What are PhoneGap apps?

iPhoneApp

AndroidApp

BlackBerryApp

WebOSApp

…Symbian, Windows 7 , BadaWebKit component running your javascript phonegap app

Page 11: Mobile Application Development using PhoneGap

11

11

Over all Architecture

HTML5/CSS3 Application

UI Framework e.g jQueryMobile/Sencha PhoneGap API

Phone Gap Bridge

Camera GPS SQLite SQLite

File System Accelerometer

Compass etc

Page 12: Mobile Application Development using PhoneGap

12

New Age Applications

AJAX Application

Mobile clients

Third Party Integrations

/Employee

/DepartmentJSON/XML

Restful Service

Page 13: Mobile Application Development using PhoneGap

13

Benefits of PhoneGap• OpenSource – 6 Platforms• Existing AJAX Developers task force• Same UI across

• Mobile App• Mobile Web

• Mashup Friendly – No Single Origin Policy (That’s a wow)

Page 14: Mobile Application Development using PhoneGap

14

Getting Started with PhoneGap

Page 15: Mobile Application Development using PhoneGap

15

PhoneGap Getting Started• Follow Getting Started Guide

Page 16: Mobile Application Development using PhoneGap

16

What is nature of PhoneGap AppsPhoneGap Apps • Typically are are JavaScript Ajax apps• Only addition is use of PhoneGap API to

• Access Device Info• Access Geo, Accelerometer, Compass• Access FS, DB, Network status• Access Address Book, Camera etc

Page 17: Mobile Application Development using PhoneGap

17

PhoneGap Quick Code Demo• Basic LifeCycle Demo• Showing Compass• Showing Accelerometer• Capturing from Camera

Page 18: Mobile Application Development using PhoneGap

18

Android PhoneGap Project

Page 19: Mobile Application Development using PhoneGap

19

Basic LifeCycle Demo

Page 20: Mobile Application Development using PhoneGap

20

PhoneGap Limitations• Background processing

• e.g Running sync every 5 mins• Notifications

• Putting notification for users

In fact these limitations are quite common for cross platform frameworks.

Page 21: Mobile Application Development using PhoneGap

21

Choosing Right UI Framework

Page 22: Mobile Application Development using PhoneGap

22

The Contenders• jQueryMobile• Sencha Touch• Google Webtoolkit (GWT)

Page 23: Mobile Application Development using PhoneGap

23

jQueryMobile Info

MIT or GPL License

Supports

Page 24: Mobile Application Development using PhoneGap

24

jQueryMobile Info

Page 25: Mobile Application Development using PhoneGap

25

jQueryMobile Demo

Page 26: Mobile Application Development using PhoneGap

26

jQueryMobile basics<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>

<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>

</head>

<body>

</body>

</html>

Page 27: Mobile Application Development using PhoneGap

27

jQueryMobile basics<body>

<div data-role="page”>

<div data-role="header">

<h1>Single Page</h1>

</div><!-- /header

<div data-role="content">

<p>This is a Single Page……….</p>

</div><!-- /content

<div data-role="footer">

<h4>Footer Content</h4>

</div><!-- /footer -->

</div><!-- /page -->

</body>

Page 28: Mobile Application Development using PhoneGap

28

jQueryMobile basics

Page 29: Mobile Application Development using PhoneGap

29

jQueryMobile basics

Page 30: Mobile Application Development using PhoneGap

30

jQueryMobile basics

Page 31: Mobile Application Development using PhoneGap

31

jQueryMobile DemoLet see the demo -

http://jquerymobile.com/demos/1.0b2/

Page 32: Mobile Application Development using PhoneGap

32

Page 33: Mobile Application Development using PhoneGap

33

Sencha Touch

Page 34: Mobile Application Development using PhoneGap

34

Sencha Touch

• iPhone• Android• BlackBerry

Rich Widgets

Page 35: Mobile Application Development using PhoneGap

35

Kitchen Sink on Tablet

Page 36: Mobile Application Development using PhoneGap

36

Kitchen Sink on Mobile

Page 37: Mobile Application Development using PhoneGap

37

Sencha Touch Demo

Page 38: Mobile Application Development using PhoneGap

38

Sencha basics<!DOCTYPE html>

<html>

<head>

<title>GeoTweets</title>

<link rel="stylesheet" href="../../resources/css/sencha-touch.css" type="text/css”>

<script type="text/javascript" src="../../sencha-touch-debug.js"></script>

<!-- Application JS -->

<script type="text/javascript" src="src/index.js"></script>

</head>

<body>

</body>

</html>

Page 39: Mobile Application Development using PhoneGap

39

Sencha basicsExt.setup({

tabletStartupScreen: 'tablet_startup.png',

phoneStartupScreen: 'phone_startup.png',

icon: 'icon.png',

glossOnIcon: false,

onReady: function() {

…….

}

};

Page 40: Mobile Application Development using PhoneGap

40

Sencha basicsvar panel = new Ext.TabPanel({

fullscreen: true,

cardSwitchAnimation: 'slide',

items: [

map,

timeline]

});

Page 41: Mobile Application Development using PhoneGap

41

Sencha basicsvar timeline = new Ext.Component({

title: 'Timeline',

cls: 'timeline',

scroll: 'vertical',

tpl: [

'<tpl for=".">',

'<div class="tweet">',

'<div class="avatar"><img src="{profile_image_url}" /></div>',

'<div class="tweet-content">',

'<h2>{from_user}</h2>',

'<p>{text}</p>',

'</div>',

'</div>',

'</tpl>'

]

});

Page 42: Mobile Application Development using PhoneGap

42

Sencha basics var refresh = function() {

var coords = map.geo.coords;

Ext.util.JSONP.request({

url: 'http://search.twitter.com/search.json',

callbackKey: 'callback',

params: {

geocode: coords.latitude + ',' + coords.longitude + ',' + '5mi',

rpp: 30

},

callback: function(data) {

data = data.results;

// Update the tweets in timeline

timeline.update(data);

}

});

};

Page 43: Mobile Application Development using PhoneGap

43

Page 44: Mobile Application Development using PhoneGap

44

GWT basics• GWT allows developers to code in Java

and compile to Javascript• Used to build browser based apps

Page 45: Mobile Application Development using PhoneGap

45

For Those who know GWTThere are two ways to build PhoneGap Apps for GWT• Using PhoneGap-GWT Library

• 0.9.4 version• Not 100% complete

• Use Overlays and JSNI to wrap PhoneGap JS APIs with GWT APIs

Page 46: Mobile Application Development using PhoneGap

46

When to go for GWT• Your AJAX app is GWT based• Enterprise class AJAX app• Reuse of UI code across

• Web App• Mobile Web App• Mobile PhoneGap App

• Performance, Cross Browser support

Page 47: Mobile Application Development using PhoneGap

47

ComparisonFeature jQueryMobile Sencha GWT

Mobile Support Yes Yes Generic

UI Concept HTML based Javascript based Java Widget based

Widget Support Minimum Good Support Good Support but non generic

Support for complex UI

Good Excellent (mobile) Excellent (both)

Learning curve Minimum Time consuming Time consuming since integration with PhoneGap

Extensibility Moderate – jQuery Plugins

Good Excellent

Page 48: Mobile Application Development using PhoneGap

48

ComparisonFeature jQueryMobile Sencha GWT

Ideal for Smaller Simpler Apps

For moderate to complex apps

Both desktop and mobile – complex apps

App data store No Yes You can implement

Template Engine No Yes Not Required

Page 49: Mobile Application Development using PhoneGap

49

PhoneGap Emulators and Remote Debugging

Page 50: Mobile Application Development using PhoneGap

50

Taking the Pain Off• Testing on Mobile is Pain• Testing on Chrome is easy• Install Ripple Emulator on Chrome

Page 51: Mobile Application Development using PhoneGap

51

Ripple Emulator Demo

Start Chrome with --disable-web-security option

Page 52: Mobile Application Development using PhoneGap

52

Say you are testing on Mobile• How to do Inspect?• How to modify the DOM?• Use http://debug.phonegap.com

Page 53: Mobile Application Development using PhoneGap

53

http://debug.phonegap.com

Page 54: Mobile Application Development using PhoneGap

54

Debugging Demo (Browser)

Page 55: Mobile Application Development using PhoneGap

55

Debugging Demo

Page 56: Mobile Application Development using PhoneGap

56

Debugging Locally• Install Weinre locally -

http://phonegap.github.com/weinre/ • Inject debug script• Debug on locally installed Weinre

Page 57: Mobile Application Development using PhoneGap

57

Building in Cloud – PhoneGap Build (Beta)

Page 58: Mobile Application Development using PhoneGap

58

Building for Major Mobile Platform

• Requires• All SDKs installed• Necessary Emulators required• Windows and Mac OS at minimum• Time and Patience • Difficult for CIT Builds

Page 59: Mobile Application Development using PhoneGap

59

PhoneGap Beta• Build Service for Pure PhoneGap

Applications• Pure PhoneGap == No Extensions• Build on PhoneGap’s cloud• Share Code with PhoneGap• Share necessary certificates with

PhoneGap

Page 60: Mobile Application Development using PhoneGap

60

PhoneGap Build Beta

Page 61: Mobile Application Development using PhoneGap

61

Page 62: Mobile Application Development using PhoneGap

62

Page 63: Mobile Application Development using PhoneGap

63

Page 64: Mobile Application Development using PhoneGap

64

Page 65: Mobile Application Development using PhoneGap

65

Page 66: Mobile Application Development using PhoneGap

66

Page 67: Mobile Application Development using PhoneGap

67

Page 68: Mobile Application Development using PhoneGap

68

Page 69: Mobile Application Development using PhoneGap

69

Extending PhoneGap

Page 70: Mobile Application Development using PhoneGap

70

Need for Extension• Javascript code should avoid heavy

weight lifting• Exposing more of native platform• Platform Specific extensions, things

which are not common

Page 71: Mobile Application Development using PhoneGap

71

Example for Extensions• E.g

• Drop Box file sync• Encryption and Decryption• …..

Page 72: Mobile Application Development using PhoneGap

72

Plugin Architecture

Page 73: Mobile Application Development using PhoneGap

73

Android Extension Code Walk through• Code Demo -

http://wiki.phonegap.com/w/page/36753494/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20Android

Page 74: Mobile Application Development using PhoneGap

74

Android Plugin – Native Part

Page 75: Mobile Application Development using PhoneGap

75

Android Plugin – JavaScript Part

Page 76: Mobile Application Development using PhoneGap

76

Calling Part

Page 77: Mobile Application Development using PhoneGap

77

Conclusion for PhoneGap• Javascript UI Framework works for apps

of moderate complexity• Sencha Touch for complex apps• jQuery for simpler• GWT for apps that go beyond web or

mobile.

Page 78: Mobile Application Development using PhoneGap

78

Conclusion• PhoneGap Build is great way to improve

CIT for pure PhoneGap apps• PhoneGap Extensions are great way to

build hybrid apps e.g FileShare• PhoneGap great way to reduce cost and

risk, but meant for a type of application

Page 79: Mobile Application Development using PhoneGap

79

Features like Oauth(if time permits)

Page 80: Mobile Application Development using PhoneGap

80

PhoneGap Pros and Cons• Goal - Doing things common across

mobile platform• Pros – Good Abstraction to developers• Cons – Not everything works or works

uniformly across platforms.• E.g Oauth – Works on iPhone and

doesn’t work yet on Android and others

Page 81: Mobile Application Development using PhoneGap

81

OAuth for iPhone• How OAuth works? E.g Facebook• Child Browser Support• Tracking URL change on Child Browser• Close Child Browser• Reading token from Child Browser

Page 82: Mobile Application Development using PhoneGap

82

Facebook OAuth Flow

PhoneGap App

PhoneGap Framework

Child Browser Plugin

Listens for URL change

Page 83: Mobile Application Development using PhoneGap

83

Facebook OAuth Flow

PhoneGap Framework

Child Browser Plugin

success.html?key=ads23sfs

Face book Login Page

http://../success.html

Page 84: Mobile Application Development using PhoneGap

84

Facebook OAuth Flow

PhoneGap App

PhoneGap Framework

Child Browser Plugin

Listens for URL change

key = ads23sfs

Page 85: Mobile Application Development using PhoneGap

85

Facebook OAuth Flow

PhoneGap App

PhoneGap Framework

key = ads23sfs

API

Facebook.comJSON

Token passed ads23sfs

Page 86: Mobile Application Development using PhoneGap

86

Q & A

Reachable @ [email protected]

Twitter - rohitghatol

Page 87: Mobile Application Development using PhoneGap

87

Beginning PhoneGap - Apress

Page 88: Mobile Application Development using PhoneGap

88

Beginning PhoneGap - ApressApress Link -

http://www.apress.com/mobile/blackberry/9781430239031