Add IPlugin interface and change Plugin to be abstract class. Plugins can either implement IPlugin or extend Plugin.

This commit is contained in:
Bryce Curtis
2010-10-04 23:58:14 -05:00
parent cbff3812e8
commit 68146329b9
18 changed files with 161 additions and 748 deletions
+74
View File
@@ -0,0 +1,74 @@
package com.phonegap.api;
import org.json.JSONArray;
import com.phonegap.DroidGap;
import android.content.Intent;
import android.webkit.WebView;
/**
* Plugin interface must be implemented by any plugin classes.
*
* The execute method is called by the PluginManager.
*/
public interface IPlugin {
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @return A PluginResult object with a status and message.
*/
PluginResult execute(String action, JSONArray args);
/**
* Identifies if action to be executed returns a value and should be run synchronously.
*
* @param action The action to execute
* @return T=returns value
*/
public boolean isSynch(String action);
/**
* Sets the context of the Plugin. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
void setContext(DroidGap ctx);
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
void setView(WebView webView);
/**
* Called when the system is about to start resuming a previous activity.
*/
void onPause();
/**
* Called when the activity will start interacting with the user.
*/
void onResume();
/**
* The final call you receive before your activity is destroyed.
*/
void onDestroy();
/**
* Called when an activity you launched exits, giving you the requestCode you started it with,
* the resultCode it returned, and any additional data from it.
*
* @param requestCode The request code originally supplied to startActivityForResult(),
* allowing you to identify who this result came from.
* @param resultCode The integer result code returned by the child activity through its setResult().
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
void onActivityResult(int requestCode, int resultCode, Intent intent);
}
+32 -12
View File
@@ -1,10 +1,7 @@
package com.phonegap.api;
import org.json.JSONArray;
import com.phonegap.DroidGap;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
@@ -13,7 +10,11 @@ import android.webkit.WebView;
*
* The execute method is called by the PluginManager.
*/
public interface Plugin {
public abstract class Plugin implements IPlugin {
public WebView webView; // WebView object
public DroidGap ctx; // DroidGap object
/**
* Executes the request and returns PluginResult.
*
@@ -21,7 +22,7 @@ public interface Plugin {
* @param args JSONArry of arguments for the plugin.
* @return A PluginResult object with a status and message.
*/
PluginResult execute(String action, JSONArray args);
public abstract PluginResult execute(String action, JSONArray args);
/**
* Identifies if action to be executed returns a value and should be run synchronously.
@@ -29,7 +30,9 @@ public interface Plugin {
* @param action The action to execute
* @return T=returns value
*/
public boolean isSynch(String action);
public boolean isSynch(String action) {
return false;
}
/**
* Sets the context of the Plugin. This can then be used to do things like
@@ -37,7 +40,9 @@ public interface Plugin {
*
* @param ctx The context of the main Activity.
*/
void setContext(DroidGap ctx);
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
@@ -45,22 +50,27 @@ public interface Plugin {
*
* @param webView The PhoneGap WebView
*/
void setView(WebView webView);
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
void onPause();
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
void onResume();
public void onResume() {
}
/**
* The final call you receive before your activity is destroyed.
*/
void onDestroy();
public void onDestroy() {
}
/**
* Called when an activity you launched exits, giving you the requestCode you started it with,
@@ -71,6 +81,16 @@ public interface Plugin {
* @param resultCode The integer result code returned by the child activity through its setResult().
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
void onActivityResult(int requestCode, int resultCode, Intent intent);
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
/**
* Send JavaScript statement back to JavaScript.
*
* @param statement
*/
public void sendJavascript(String statement) {
this.ctx.callbackServer.sendJavascript(statement);
}
}