phonegap底层原理学习和研究(三)

      针对Phonegap开发中常用的DroidGap类继承自PhonegapActivity,PhonegapActivity继承自Activity。源代码如下:

Java代码   收藏代码
  1. /* 
  2.  * PhoneGap is available under *either* the terms of the modified BSD license *or* the 
  3.  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. 
  4.  *  
  5.  * Copyright (c) 2005-2010, Nitobi Software Inc. 
  6.  * Copyright (c) 2010, IBM Corporation 
  7.  */  
  8. package com.phonegap.api;  
  9.   
  10. import android.app.Activity;  
  11. import android.content.Intent;  
  12.   
  13. /** 
  14.  * The Phonegap activity abstract class that is extended by DroidGap. 
  15.  * It is used to isolate plugin development, and remove dependency on entire Phonegap library. 
  16.  */  
  17. public abstract class PhonegapActivity extends Activity {  
  18.   
  19.     /** 
  20.      * Add a class that implements a service. 
  21.      *  
  22.      * @param serviceType 
  23.      * @param className 
  24.      */  
  25.     abstract public void addService(String serviceType, String className);  
  26.       
  27.     /** 
  28.      * Send JavaScript statement back to JavaScript. 
  29.      *  
  30.      * @param message 
  31.      */  
  32.     abstract public void sendJavascript(String statement);  
  33.   
  34.     /** 
  35.      * Launch an activity for which you would like a result when it finished. When this activity exits,  
  36.      * your onActivityResult() method will be called. 
  37.      *   
  38.      * @param command           The command object 
  39.      * @param intent            The intent to start 
  40.      * @param requestCode       The request code that is passed to callback to identify the activity 
  41.      */  
  42.     abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);  
  43.   
  44.     /** 
  45.      * Set the plugin to be called when a sub-activity exits. 
  46.      *  
  47.      * @param plugin            The plugin on which onActivityResult is to be called 
  48.      */  
  49.     abstract public void setActivityResultCallback(IPlugin plugin);  
  50.   
  51.     /** 
  52.      * Load the specified URL in the PhoneGap webview. 
  53.      *  
  54.      * @param url               The URL to load. 
  55.      */  
  56.     abstract public void loadUrl(String url);  
  57. }  

 

在使用这个类启动Webapp移动项目时候可以配置许多东西,如下:

Java代码   收藏代码
  1. This class is the main Android activity that represents the PhoneGap  
  2. application.  It should be extended by the user to load the specific  
  3. html file that contains the application.  
  4.   
  5. As an example:  
  6.   
  7.     package com.phonegap.examples;  
  8.     import android.app.Activity;  
  9.     import android.os.Bundle;  
  10.     import com.phonegap.*;  
  11.       
  12.     public class Examples extends DroidGap {  
  13.       @Override  
  14.       public void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.                    
  17.         // Set properties for activity  
  18.         super.setStringProperty("loadingDialog""Title,Message"); // show loading dialog  
  19.         super.setStringProperty("errorUrl""file:///android_asset/www/error.html"); // if error loading file in super.loadUrl().  
  20.   
  21.         // Initialize activity  
  22.         super.init();  
  23.           
  24.         // Clear cache if you want  
  25.         super.appView.clearCache(true);  
  26.           
  27.         // Load your application  
  28.         super.setIntegerProperty("splashscreen", R.drawable.splash); // load splash.jpg image from the resource drawable directory  
  29.         super.loadUrl("file:///android_asset/www/index.html"3000); // show splash screen 3 sec before loading app  
  30.       }  
  31.     }  

 

DroidGap中可以配置的属性如下:

Properties: The application can be configured using the following properties:


     //加载时候加载对话框的信息
     // Display a native loading dialog when loading app.  Format for value = "Title,Message".  
     // (String - default=null)
     super.setStringProperty("loadingDialog", "Wait,Loading Demo...");
 
     //加载对话对话框
     // Display a native loading dialog when loading sub-pages.  Format for value = "Title,Message".  
     // (String - default=null)
     super.setStringProperty("loadingPageDialog", "Loading page..."); 
    
     // Cause all links on web page to be loaded into existing web view, 
     // instead of being loaded into new browser. (Boolean - default=false)
     super.setBooleanProperty("loadInWebView", true);
    //加载相关的动画信息
     // Load a splash screen image from the resource drawable directory.
     // (Integer - default=0)
     super.setIntegerProperty("splashscreen", R.drawable.splash); 
    //设置默认的背景色
     // Set the background color.
     // (Integer - default=0 or BLACK)
     super.setIntegerProperty("backgroundColor", Color.WHITE);
     //设置超时时间
     // Time in msec to wait before triggering a timeout error when loading
     // with super.loadUrl().  (Integer - default=20000)
     super.setIntegerProperty("loadUrlTimeoutValue", 60000); 
    //设置请求错误时候的提示页面
     // URL to load if there's an error loading specified URL with loadUrl().  
     // Should be a local URL starting with file://. (String - default=null)
     super.setStringProperty("errorUrl", "file:///android_asset/www/error.html"); 
    //是否在后台运行的功能
     // Enable app to keep running in background. (Boolean - default=true)
     super.setBooleanProperty("keepRunning", false);
 
     
Phonegap.xml的配置如下:
     PhoneGap uses a configuration file at res/xml/phonegap.xml to specify the following settings.
     //允许phonegap访问的路径和域
     Approved list of URLs that can be loaded into DroidGap
         <access origin="http://server regexp" subdomains="true" / >

   //日志的模式
     Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR)
         <log level="DEBUG" /> 

Phonegap plugins:
     PhoneGap uses a file at res/xml/plugins.xml to list all plugins that are installed.
     Before using a new plugin, a new element must be added to the file.
         name attribute is the service name passed to PhoneGap.exec() in JavaScript
         value attribute is the Java class name to call.
     
     <plugins>
         <plugin name="App" value="com.phonegap.App"/> 
         ...
     </plugins>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值