54
移动应用开发 PhoneGap + JQuery + Dreamweaver

After max+phonegap

  • Upload
    yangdj

  • View
    905

  • Download
    4

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: After max+phonegap

移动应用开发 PhoneGap + JQuery + Dreamweaver

Page 2: After max+phonegap
Page 3: After max+phonegap

very much!

Page 4: After max+phonegap

But, less than 7yue

Page 5: After max+phonegap

MOBILE HTML

Page 6: After max+phonegap

Web App

or

Hybrid App or

Native App

Page 7: After max+phonegap

http://mobilehtml5.org/

MOBILE HTML ?

Page 8: After max+phonegap

摄像头

运动传感器

指南针

设备信息

GPS

通知

网络状态

CSS 3

JavaScript

HTML标记和语义

设备API

图形、图像、特效 部件

音视频 Web font

Page 9: After max+phonegap

摄像头

运动传感器

指南针

设备信息

GPS

通知

网络状态

CSS 3

JavaScript

HTML标记和语义

设备API

图形、图像、特效 部件

音视频 Web font

浏览器

Page 10: After max+phonegap

摄像头

运动传感器

指南针

设备信息

GPS

通知

网络状态

CSS 3

JavaScript

HTML标记和语义

设备API

图形、图像、特效 部件

音视频 Web font

浏览器

Native Wrapper

Page 11: After max+phonegap

摄像头

运动传感器

指南针

设备信息

GPS

通知

网络状态

CSS 3

JavaScript

HTML标记和语义

设备API

图形、图像、特效 部件

音视频 Web font

WebView

Native Wrapper

PhoneGap

Page 12: After max+phonegap

Web App & Hybrid App

使用 HTML + JavaScript + CSS3

开发的移动应用 (基于浏览器+可安装的)

Page 13: After max+phonegap

Framework? Tools?

Page 14: After max+phonegap
Page 15: After max+phonegap

JQuery mobile (http://jquerymobile.com/)

创建面向现代智能移动设备的 跨平台UI框架

Page 16: After max+phonegap

构建于JQuery Core 跨平台 (iOS, Android, Blackberry, Palm WebOS, Nokia/Symbian, Windows Phone 7, MeeGo, Opera Mobile/Mini, Firefox Mobile, Kindle, Nook, 所有现代浏览器)

HTML5标记配置 轻量级 模块化架构 触摸和鼠标事件支持 强大的主题框架 统一的、可扩充的UI组件

Page 17: After max+phonegap

<body> <div data-role="page" id="page">

<div data-role="header"> <h1>Page One</h1> </div> <div data-role="content"> <ul data-role="listview"> <li><a href="#page2">Page Two</a></li>

<li><a href="#page3">Page Three</a></li> <li><a href="#page4">Page Four</a></li> </ul> </div> <div data-role="footer"> <h4>Page Footer</h4> </div>

</div> <div data-role="page" id="page2">

<div data-role="header"> <h1>Page Two</h1> </div> <div data-role="content"> Content </div> <div data-role="footer"> <h4>Page Footer</h4> </div>

</div> </body>

Page

Page 18: After max+phonegap

<div data-role="page" id="page2" > <div data-role="header" id="page2Header" data-position="!xed" > <a href="#page1" data-role="button" data-icon="home">home</a>

<h1>PIE</h1> </div> <div data-role="content"> <div id="interactive" class="graph" ></div> </div> <div data-role="footer" data-position="!xed" id="page2Footer"> <h4>Page Footer</h4> </div> </div>

jquery."ot.js

1

2

准备div:interactive

Page 19: After max+phonegap

$(function () { var data=[]; var series = Math."oor(Math.random()*5)+5; for( var i = 0; i<series; i++) { data[i] = { label: "Series"+(i+1), data: Math."oor(Math.random()*100)+1 } }

jquery."ot.js

准备数据

Page 20: After max+phonegap

$.plot($("#interactive"), data,

{ series: { pie: { show: true, innerRadius: 0.4 } }, grid: { hoverable: false, clickable: true }, legend: { show: false } });

$("#interactive").bind("plotclick", pieClick);

}); jquery."ot.js

使用Jquery plugin plot在interactive div上绘制

Page 21: After max+phonegap

<div data-role="page" id="page3"> <div data-role="header"> <a href="#page4" data-role="button" data-icon="back">返回</a> <h1>LIST</h1> </div> <div data-role="content"> <ul data-role="listview" data-theme="d" id="listAfterMax"

data-inset="true"> </ul> </div> <div data-role="footer"> <h4>Page Footer</h4> </div> </div>

listview

Page 22: After max+phonegap

var itemData = [ {imgURL: "images/"owing-rock.jpg" , label: "Series1", desc: 10, price: 120, stock:1200}, {imgURL: "images/grass-blades.jpg" , label: "Series2", desc: 30, price: 220, ck:200}, …… ];

数据

Page 23: After max+phonegap

<script id="newsItem" type="text/x-jquery-tmpl"> <li data-messageId="${label}" class="newsItem">

<img src="${imgURL}" class="itemImageWrapper" /> <h3> <a href="#page4" onClick="activeGallery()">${label}</a> </h3>

<p class="subItem"><strong>Price ${price}元 </strong></p> <div class="ui-li-aside"> <p><strong>${stock} 部</strong></p> </div> </li> </script>

“itemrenderer”

Page 24: After max+phonegap

var newsList = $( "#listAfterMax" ); newsList.empty(); $( "#newsItem" ).tmpl( itemData).appendTo( newsList ); newsList.listview( "refresh" );

使用Jquery plugin: tmpl 构

建list

Page 25: After max+phonegap

My Stupid Demo

Page 26: After max+phonegap

http://www.markus-falk.com/mobile-frameworks-comparison-chart/ MORE…

Page 27: After max+phonegap

http://www.markus-falk.com/mobile-frameworks-comparison-chart/

http://www.markus-falk.com/mobile-frameworks-comparison-chart/ MORE…

Page 28: After max+phonegap

PhoneGap

Page 29: After max+phonegap

使用HTML5、CSS3、JavaScript构建APP

访问移动设备本地特性

打包部署到多种平台

phoneGap plugin

Page 30: After max+phonegap
Page 31: After max+phonegap

打包

Page 32: After max+phonegap

public class CirclesActivity extends DroidGap {

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/circles.html"); }}

Native Wrapper with PhoneGap

Page 33: After max+phonegap

在dreamweaver中构建

Page 34: After max+phonegap

PhoneGap : Build

Page 35: After max+phonegap

PhoneGap Build

Compile in the cloud

Page 36: After max+phonegap
Page 37: After max+phonegap

PhoneGap plugin

Page 38: After max+phonegap

一个JavaScript与匹配的Java

一个JavaScript与匹配的.h和.m

定制PhoneGap Plugin (IOS 和 Android)

Page 39: After max+phonegap

PhoneGap如何工作?

Page 40: After max+phonegap

PhoneGap架构

Mobile OS

Web App

HTML5+JavaScript+CSS3

HTML Engine (WebView、UIWebView⋯)

PhoneGap Plug-ins

摄像头 运动传感器

指南针

设备信息

GPS 通知

网络状态 ⋯

定制plugin

HTML5 API

PhoneGap JS API

OS API OS API

PhoneGap Native API

Page 41: After max+phonegap

HTML5项目

phonegap.jar

plugins.xml

AndroidManifest.xml

android activity

Page 42: After max+phonegap

public class CirclesActivity extends DroidGap {

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/index.html"); }}

Native Wrapper with PhoneGap

Page 43: After max+phonegap

public class callsPGPlugin extends Plugin { // List Actions public static !nal String ACTION="list"; @Override public PluginResult execute(String action, JSONArray data, String callbackId) { PluginResult result=null; if(ACTION.equals(action)){ CallLogAI callLogAI = new CallLogAI(ctx); JSONObject callsHistory=callLogAI.fetchCallLogs(null); Log.d("RESULT=", callsHistory.toString()); result=new PluginResult(Status.OK,callsHistory); }else{ result=new PluginResult(Status.INVALID_ACTION); Log.d("CallsPlugin","Invalidate action:" + action); } return result; }

}

Java定制plugin

Page 44: After max+phonegap

注册plugin <?xml version="1.0" encoding="UTF-8"?> <plugins> <plugin name="App" value="com.phonegap.App"/> <plugin name="Geolocation" value="com.phonegap.GeoBroker"/> <plugin name="Device" value="com.phonegap.Device"/> …… <plugin name="Temperature" value="com.phonegap.TempListener"/> <plugin name="FileTransfer" value="com.phonegap.FileTransfer"/> <plugin name="Capture" value="com.phonegap.Capture"/>

<plugin name="CallsHistoryPlugin" value="com.mark.phonegap.plugin.callsPGPlugin" /> </plugins>

Page 45: After max+phonegap

Javascript接口 var CallsListing=function(){}; CallsListing.prototype.list=function(successCallback,failureCallback){

return PhoneGap.exec(successCallback, failureCallback, 'CallsHistoryPlugin', 'list',['test'] );

}; PhoneGap.addConstructor(function(){

PhoneGap.addPlugin("callsListing",new CallsListing); });

Page 46: After max+phonegap

window.plugins.callsListing.list(function(r){printResult(r)},function(e){console.log(e)}

);

Javascript 调用plugin

Page 47: After max+phonegap

window.plugins.callsListing.list(function(r){printResult(r)},function(e){console.log(e)}

);

CallsListing.prototype.list=function(successCallback,failureCallback){

return PhoneGap.exec(successCallback,failureCallback,'CallsHistoryPlugin','list',['test’]);

};public class callsPGPlugin extends Plugin {

// List Actions public static !nal String ACTION="list"; @Override public PluginResult execute(String

action, JSONArray data, String callbackId) {

<plugin name="CallsHistoryPlugin" value="com.mark.phonegap.plugin.callsPGPlugin" />

Page 48: After max+phonegap

PhoneGap的 小秘密

Page 49: After max+phonegap

CallbackServer:XmlHttpRequestsever

WebChromClient: onJsPrompt

addJavaScriptInterface

Page 50: After max+phonegap

CallsListing.prototype.list=function(successCallback,failureCallback){

return PhoneGap.exec(successCallback,failureCallback,'CallsHistoryPlugin','list',['test’]);

};

PhoneGap.exec = function(success, fail, service, action, args) { … var r = prompt(JSON.stringify(args), "gap:"+JSON.stringify([service, action, callbackId, true])); …

Page 51: After max+phonegap

Droidgap.java public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { …… String r = pluginManager.exec(service, action, callbackId, message, async); …… }

Pluginmanager.java public String exec(!nal String service, !nal String action, !nal String callbackId, !nal String jsonArgs, !nal boolean async) {

…… cr = plugin.execute(action, args, callbackId); ctx.sendJavascript(cr.toErrorCallbackString(callbackId));

……

}

Page 52: After max+phonegap

Pluginmanager.java

ctx.sendJavascript(cr.toErrorCallbackString(callbackId));

CallbackServer.java : XHR server

PhoneGap.Channel.join(function() { // Start listening for XHR callbacks setTimeout(function() { if (PhoneGap.UsePolling) { PhoneGap.JSCallbackPolling(); } ⋯

Page 53: After max+phonegap

Appcelerator Titanium

Mozilla Rhino JavaScriptCore

Native?

Page 54: After max+phonegap

Mark Dong Developer Evangelist [email protected] weibo.com/donglongfei