SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
12 things you should know

       Mark Dong 董龙飞
       Adobe Developer Evangelist

       weibo.com/donglongfei
       weibo.com/javascriptdev
1. Why?




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
?MOBILE HTML




               http://mobilehtml5.org/
Web App
    or
Hybrid App
    or
Native App
Apps are for loyalty, Mobile web is for discovery.




            from the report “implementing your mobile strategy” by dotMobi
2. What is PhoneGap?




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
Wrap your web app and deploy




 Interface to access native features



 PhoneGap plugin




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
3. What it is not?




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
JavaScript
Framework

 IDE Tools


    Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
4. Where it is from?




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
!    2008: iPhoneDevCamp

!    “bridging the gap
     between the web and the
     iphone SDK”

!    PhoneGap : it is like AIR
     for the Iphone (2008-9-18,
     Nitobi blog)




               Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
5. Open source




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
CallBack Cordova
更名为Apache




      Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
http://incubator.apache.org/cordova/
6 . Across platforms




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
7. Packaging




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
IDE + SDK + PhoneGap


Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
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
                     Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
PhoneGap Build
                                                      Compile in the cloud




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
8. Accessing native features
9. The nature




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
JS                                                      Native




     Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
JavaScript/CSS/HTML5                                             Non Web Tech




   Native Web Control
                                         FFI                             Plugins




               Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
Native Web Control


  Browser : full functions
  Chrome removed
  No top bar
10. Plugin
android activity

HTML5项目


phonegap.jar

plugins.xml

AndroidManifest.xml


        Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
In Java
public class callsPGPlugin extends Plugin {                       Java定制plugin
          // List Actions
         public static final 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;
         }
}	
                 Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
注册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>
                 Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
In JavaScript




Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
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);
});
Javascript接口
使用者调用plugin


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

  CallsListing.prototype.list=function(success
  Callback,failureCallback){	
        	return PhoneGap.exec(successCallback,	
        	failureCallback,	
        	'CallsHistoryPlugin',	
        	'list',['test’]);	
  };	
                                           public class callsPGPlugin extends Plugin {
                                                     // List Actions
<plugin name="CallsHistoryPlugin"                   public static final String ACTION="list";
value="com.mark.phonegap.plugin.callsPGPlu          @Override
gin" />                                             public PluginResult execute(String
                                           action, JSONArray data, String callbackId) {
11. How?
Android
addJavaScriptInterface



WebChromClient: onJsPrompt


CallbackServer:XmlHttpRequestsever
From Native to JS

   WebChromClient: 覆盖onJsPrompt



From JS to Native


   CallbackServer:XmlHttpRequestsever
Javascript
 CallsListing.prototype.list=function(successCallback,fai
 lureCallback){	
       	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]));
 …
             Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
Java
    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(final String service, final String action, final String callbackId, final
String jsonArgs, final boolean async) {
         ……
         cr = plugin.execute(action, args, callbackId);
         ctx.sendJavascript(cr.toErrorCallbackString(callbackId));

           ……
}
Pluginmanager.java                                       Java
      ctx.sendJavascript(cr.toErrorCallbackString(callbackId));



          CallbackServer.java : XHR server


PhoneGap.Channel.join(function() {

 // Start listening for XHR callbacks
 setTimeout(function() {                             Javascript
      if (PhoneGap.UsePolling) {
         PhoneGap.JSCallbackPolling();
      }
…
IOS
实例化UIWebView

 webView =[[UIWebView alloc] initWithFrame:webViewBounds];


JS到Native的通讯


  document.location = “gap://Class.method/args”


Native到JS的通讯

  UIWebView.stringByEvaluatingJavaScriptFromString

          Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
12. Debug
weinre:

  a Remote Debugger
for web pages or
PhoneGap app on
mobile devices.




        Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
wein
     re
<script src="http://192.168.1.101:8080/target/target-script-min.js#anonymous">
</script>




                Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
PhoneGap Debug Server




           Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
Mark Dong
Adobe Developer Evangelist
dong@adobe.com
weibo.com/donglongfei
weibo.com/javascriptdev

Contenu connexe

Tendances

UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
Tobias Schneck
 
Ajax World Comet Talk
Ajax World Comet TalkAjax World Comet Talk
Ajax World Comet Talk
rajivmordani
 
Html5 : stockage local & synchronisation
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisation
goldoraf
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web development
alice yang
 
Lt web quiz_answer
Lt web quiz_answerLt web quiz_answer
Lt web quiz_answer
0983676660
 
Uazaa uma-farsa-parte 2
Uazaa uma-farsa-parte 2Uazaa uma-farsa-parte 2
Uazaa uma-farsa-parte 2
devninjabr
 
Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12
Stephan Hochdörfer
 

Tendances (20)

UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
UI-Testing - Selenium? Rich-Clients? Containers? @APEX connect 2018
 
Ditching jQuery Madison
Ditching jQuery MadisonDitching jQuery Madison
Ditching jQuery Madison
 
JavaFX – 10 things I love about you
JavaFX – 10 things I love about youJavaFX – 10 things I love about you
JavaFX – 10 things I love about you
 
Ajax World Comet Talk
Ajax World Comet TalkAjax World Comet Talk
Ajax World Comet Talk
 
Laravel でやってみるクリーンアーキテクチャ #phpconfuk
Laravel でやってみるクリーンアーキテクチャ #phpconfukLaravel でやってみるクリーンアーキテクチャ #phpconfuk
Laravel でやってみるクリーンアーキテクチャ #phpconfuk
 
Effective C++/WinRT for UWP and Win32
Effective C++/WinRT for UWP and Win32Effective C++/WinRT for UWP and Win32
Effective C++/WinRT for UWP and Win32
 
JavaFX Pitfalls
JavaFX PitfallsJavaFX Pitfalls
JavaFX Pitfalls
 
Hacking pokemon go [droidcon tel aviv 2016]
Hacking pokemon go [droidcon tel aviv 2016]Hacking pokemon go [droidcon tel aviv 2016]
Hacking pokemon go [droidcon tel aviv 2016]
 
Html5 : stockage local & synchronisation
Html5 : stockage local & synchronisationHtml5 : stockage local & synchronisation
Html5 : stockage local & synchronisation
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenInterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and When
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web development
 
Lt web quiz_answer
Lt web quiz_answerLt web quiz_answer
Lt web quiz_answer
 
Developer Android Tools
Developer Android ToolsDeveloper Android Tools
Developer Android Tools
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
Uazaa uma-farsa-parte 2
Uazaa uma-farsa-parte 2Uazaa uma-farsa-parte 2
Uazaa uma-farsa-parte 2
 
Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12Offline strategies for HTML5 web applications - IPC12
Offline strategies for HTML5 web applications - IPC12
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
 

Similaire à Phone gap 12 things you should know

Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事
yangdj
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
yangdj
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
yangdj
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
웹데브모바일
 
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Robert Nyman
 

Similaire à Phone gap 12 things you should know (20)

Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
 
PhoneGap
PhoneGapPhoneGap
PhoneGap
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming En
 
Phone gap android plugins
Phone gap android pluginsPhone gap android plugins
Phone gap android plugins
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Phone Gap
Phone GapPhone Gap
Phone Gap
 
PhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsPhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native Components
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W... 	Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
Bringing the open web and APIs to mobile devices with Firefox OS - Whisky W...
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Hybrid app
Hybrid appHybrid app
Hybrid app
 

Dernier

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Phone gap 12 things you should know

  • 1. 12 things you should know Mark Dong 董龙飞 Adobe Developer Evangelist weibo.com/donglongfei weibo.com/javascriptdev
  • 2. 1. Why? Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 3. ?MOBILE HTML http://mobilehtml5.org/
  • 4. Web App or Hybrid App or Native App
  • 5. Apps are for loyalty, Mobile web is for discovery. from the report “implementing your mobile strategy” by dotMobi
  • 6. 2. What is PhoneGap? Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 7. Wrap your web app and deploy Interface to access native features PhoneGap plugin Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 8. 3. What it is not? Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 9. JavaScript Framework IDE Tools Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 10. 4. Where it is from? Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 11. !  2008: iPhoneDevCamp !  “bridging the gap between the web and the iphone SDK” ! PhoneGap : it is like AIR for the Iphone (2008-9-18, Nitobi blog) Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 12. 5. Open source Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 13. CallBack Cordova 更名为Apache Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 15. 6 . Across platforms Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 16. Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 17. 7. Packaging Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 18. Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 19. IDE + SDK + PhoneGap Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 20. 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 Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 21. PhoneGap Build Compile in the cloud Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 23.
  • 24.
  • 25. 9. The nature Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 26.
  • 27. JS Native Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 28. JavaScript/CSS/HTML5 Non Web Tech Native Web Control FFI Plugins Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 29. Native Web Control Browser : full functions Chrome removed No top bar
  • 31. android activity HTML5项目 phonegap.jar plugins.xml AndroidManifest.xml Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 33. public class callsPGPlugin extends Plugin { Java定制plugin // List Actions public static final 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; } } Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 34. 注册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> Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 35. In JavaScript Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 36. 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); });
  • 37. Javascript接口 使用者调用plugin window.plugins.callsListing.list( function(r){printResult(r)}, function(e){console.log(e)} );
  • 39. window.plugins.callsListing.list( function(r){printResult(r)}, function(e){console.log(e)} ); CallsListing.prototype.list=function(success Callback,failureCallback){ return PhoneGap.exec(successCallback, failureCallback, 'CallsHistoryPlugin', 'list',['test’]); }; public class callsPGPlugin extends Plugin { // List Actions <plugin name="CallsHistoryPlugin" public static final String ACTION="list"; value="com.mark.phonegap.plugin.callsPGPlu @Override gin" /> public PluginResult execute(String action, JSONArray data, String callbackId) {
  • 43. From Native to JS WebChromClient: 覆盖onJsPrompt From JS to Native CallbackServer:XmlHttpRequestsever
  • 44. Javascript CallsListing.prototype.list=function(successCallback,fai lureCallback){ 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])); … Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 45. Java 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(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) { …… cr = plugin.execute(action, args, callbackId); ctx.sendJavascript(cr.toErrorCallbackString(callbackId)); …… }
  • 46. Pluginmanager.java Java ctx.sendJavascript(cr.toErrorCallbackString(callbackId)); CallbackServer.java : XHR server PhoneGap.Channel.join(function() { // Start listening for XHR callbacks setTimeout(function() { Javascript if (PhoneGap.UsePolling) { PhoneGap.JSCallbackPolling(); } …
  • 47. IOS
  • 48. 实例化UIWebView webView =[[UIWebView alloc] initWithFrame:webViewBounds]; JS到Native的通讯 document.location = “gap://Class.method/args” Native到JS的通讯 UIWebView.stringByEvaluatingJavaScriptFromString Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 50. weinre: a Remote Debugger for web pages or PhoneGap app on mobile devices. Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 51. wein re
  • 52. <script src="http://192.168.1.101:8080/target/target-script-min.js#anonymous"> </script> Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 53. PhoneGap Debug Server Adobe 董龙飞 weibo.com/donglongfei weibo.com/javascriptdev
  • 54. Mark Dong Adobe Developer Evangelist dong@adobe.com weibo.com/donglongfei weibo.com/javascriptdev