phonegap下層原理学習と研究(三)
6290 ワード
Phonegap開発でよく使用されるDroidGapクラスはPhonegapActivityから継承され、PhonegapActivityはActivityから継承される.ソースコードは次のとおりです.
このクラスを使用してWebappモバイルプロジェクトを起動すると、次のように多くのものを構成できます.
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//withsuper.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
//ログのパターンLog level:ERROR,WARN,INFO,DEBUG,VERBOSE(default=ERROR)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. ...
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
* Copyright (c) 2010, IBM Corporation
*/
package com.phonegap.api;
import android.app.Activity;
import android.content.Intent;
/**
* The Phonegap activity abstract class that is extended by DroidGap.
* It is used to isolate plugin development, and remove dependency on entire Phonegap library.
*/
public abstract class PhonegapActivity extends Activity {
/**
* Add a class that implements a service.
*
* @param serviceType
* @param className
*/
abstract public void addService(String serviceType, String className);
/**
* Send JavaScript statement back to JavaScript.
*
* @param message
*/
abstract public void sendJavascript(String statement);
/**
* Launch an activity for which you would like a result when it finished. When this activity exits,
* your onActivityResult() method will be called.
*
* @param command The command object
* @param intent The intent to start
* @param requestCode The request code that is passed to callback to identify the activity
*/
abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);
/**
* Set the plugin to be called when a sub-activity exits.
*
* @param plugin The plugin on which onActivityResult is to be called
*/
abstract public void setActivityResultCallback(IPlugin plugin);
/**
* Load the specified URL in the PhoneGap webview.
*
* @param url The URL to load.
*/
abstract public void loadUrl(String url);
}
このクラスを使用してWebappモバイルプロジェクトを起動すると、次のように多くのものを構成できます.
This class is the main Android activity that represents the PhoneGap
application. It should be extended by the user to load the specific
html file that contains the application.
As an example:
package com.phonegap.examples;
import android.app.Activity;
import android.os.Bundle;
import com.phonegap.*;
public class Examples extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set properties for activity
super.setStringProperty("loadingDialog", "Title,Message"); // show loading dialog
super.setStringProperty("errorUrl", "file:///android_asset/www/error.html"); // if error loading file in super.loadUrl().
// Initialize activity
super.init();
// Clear cache if you want
super.appView.clearCache(true);
// Load your application
super.setIntegerProperty("splashscreen", R.drawable.splash); // load splash.jpg image from the resource drawable directory
super.loadUrl("file:///android_asset/www/index.html", 3000); // show splash screen 3 sec before loading app
}
}
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//withsuper.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
//ログのパターンLog level:ERROR,WARN,INFO,DEBUG,VERBOSE(default=ERROR)