2012年11月2日星期五

phonegap-splashscreen

其实就是自定义一个启动页面,不顾完全可以不用这么做,MainActivity就可以充当启动页面来做,这个是官方的例子就顺便学习一下。同时这里也有延迟加载的例子。 

  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Splashscreen Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  7.     <script type="text/javascript" charset="utf-8">  
  8.   
  9.     // Wait for Cordova to load  
  10.     //  
  11.     document.addEventListener("deviceready", onDeviceReady, false);  
  12.   
  13.     // Cordova is ready  
  14.     //  
  15.     function onDeviceReady() {  
  16.         //navigator.splashscreen.show();  
  17.         navigator.splashscreen.hide();  
  18.     }  
  19.   
  20.     </script>  
  21.   </head>  
  22.   <body>  
  23.     <h1>Example</h1>  
  24.   </body>  
  25. </html>  


  1. package com.fanfq.phonegap.splashscreen;  
  2.   
  3. import org.apache.cordova.DroidGap;  
  4.   
  5. import android.os.Bundle;  
  6.   
  7. public class MainActivity extends DroidGap {  
  8.     @Override  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         // The first line 'super.setIntegerProperty' sets the image to be  
  12.         // displayed as the splashscreen. If you have named your image anything  
  13.         // other than splash.png you will have to modify this line. The second  
  14.         // line is the normal 'super.loadUrl' line but it has a second parameter  
  15.         // which is the timeout value for the splash screen. In this example the  
  16.         // splash screen will display for 10 seconds. If you want to dismiss the  
  17.         // splash screen once you get the "deviceready" event you should call  
  18.         // the navigator.splashscreen.hide() method.  
  19.         super.setIntegerProperty("splashscreen", R.drawable.splash);  
  20.         super.loadUrl("file:///android_asset/www/index.html"10000);  
  21.     }  
  22. }  

phonegap-event

监听各类事件,我用的是phonegap2.0.0的版本,越高级的版本支持功能就越多。 

  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Event Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="jquery-1.8.1.min.js"></script>  
  7.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  8.     <script type="text/javascript" charset="utf-8">  
  9.   
  10.       
  11.     // Wait for Cordova to load  
  12.     // details plz see http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#Events  
  13.     document.addEventListener("deviceready", onDeviceReadyEvent, false);  
  14.     document.addEventListener("pasue", onPasueEvent, false);  
  15.     document.addEventListener("resume", onResumeEvent, false);  
  16.     document.addEventListener("online", onlineEvent, false);  
  17.     document.addEventListener("offline", offlineEvent, false);  
  18.     document.addEventListener("backbutton", onBackbuttonEvent, false);  
  19.     document.addEventListener("batterycritical", onBatterycriticalEvent, false);  
  20.     document.addEventListener("batterylow", onBatterylowEvent, false);  
  21.     document.addEventListener("batterystatus", onBatterystatusEvent, false);  
  22.     document.addEventListener("menubutton", onMenubuttonEvent, false);  
  23.     document.addEventListener("startcallbutton", onStartcallbuttonEvent, false);  
  24.     document.addEventListener("volumedownbutton", onVolumedownbuttonEvent, false);  
  25.     document.addEventListener("volumeupbutton", onVolumeupbuttonEvent, false);  
  26.   
  27.   
  28.     // Cordova is ready  
  29.     //  
  30.     function onDeviceReadyEvent() {  
  31.         $("#msg").append("==>onDeviceReadyEvent<p/>");  
  32.     }  
  33.       
  34.     function onPasueEvent() {  
  35.         $("#msg").append("==>onPasueEvent<p/>");  
  36.     }  
  37.       
  38.     function onResumeEvent() {  
  39.         $("#msg").append("==>onResumeEvent<p/>");  
  40.     }  
  41.       
  42.     function onlineEvent() {  
  43.         $("#msg").append("==>onlineEvent<p/>");  
  44.     }  
  45.       
  46.     function offlineEvent() {  
  47.         $("#msg").append("==>offlineEvent<p/>");  
  48.     }  
  49.       
  50.     function onBackbuttonEvent() {  
  51.         $("#msg").append("==>onBackbuttonEvent<p/>");  
  52.     }  
  53.       
  54.     function onBatterycriticalEvent() {  
  55.         $("#msg").append("==>onBatterycriticalEvent<p/>");  
  56.     }  
  57.       
  58.     function onBatterylowEvent() {  
  59.         $("#msg").append("==>onBatterylowEvent<p/>");  
  60.     }  
  61.       
  62.     function onBatterystatusEvent() {  
  63.         $("#msg").append("==>onBatterystatusEvent<p/>");  
  64.     }  
  65.       
  66.     function onMenubuttonEvent() {  
  67.         $("#msg").append("==>onMenubuttonEvent<p/>");  
  68.     }  
  69.       
  70.     function onStartcallbuttonEvent() {  
  71.         $("#msg").append("==>onStartcallbuttonEvent<p/>");  
  72.     }  
  73.       
  74.     function onVolumedownbuttonEvent() {  
  75.         $("#msg").append("==>onVolumedownbuttonEvent<p/>");  
  76.     }  
  77.       
  78.     function onVolumeupbuttonEvent() {  
  79.         $("#msg").append("==>onVolumeupbuttonEvent<p/>");  
  80.     }  
  81.   
  82.     </script>  
  83.   </head>  
  84.   <body>  
  85.     <h1>Event Example</h1>  
  86.     <div id="msg"></div>  
  87.   </body>  
  88. </html>  

2012年11月1日星期四

phonegap-notification

phonegap notification 的sample有点坑爹哇,与想象的有点差距其实就是个弹出对话框。 
如图: 
  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Notification Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  7.     <script type="text/javascript" charset="utf-8">  
  8.   
  9.     // Wait for Cordova to load  
  10.     //  
  11.     document.addEventListener("deviceready", onDeviceReady, false);  
  12.   
  13.     // Cordova is ready  
  14.     //  
  15.     function onDeviceReady() {  
  16.         // Empty  
  17.     }  
  18.   
  19.     // alert dialog dismissed  
  20.     function alertDismissed() {  
  21.         // do something  
  22.     }  
  23.   
  24.     // Show a custom alertDismissed  
  25.     //  
  26.     function showAlert() {  
  27.         navigator.notification.alert(  
  28.             'You are the winner!',  // message  
  29.             alertDismissed,         // callback  
  30.             'Game Over',            // title  
  31.             'Done'                  // buttonName  
  32.         );  
  33.     }  
  34.   
  35.     </script>  
  36.   </head>  
  37.   <body>  
  38.     <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>  
  39.   </body>  
  40. </html>