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

View File

@ -14,14 +14,12 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
/**
* This class listens to the accelerometer sensor and stores the latest
* acceleration values x,y,z.
*/
public class AccelListener implements SensorEventListener, Plugin {
public class AccelListener extends Plugin implements SensorEventListener {
public static int STOPPED = 0;
public static int STARTING = 1;
@ -29,9 +27,6 @@ public class AccelListener implements SensorEventListener, Plugin {
public static int ERROR_FAILED_TO_START = 3;
public float TIMEOUT = 30000; // Timeout in msec to shut off listener
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
float x,y,z; // most recent acceleration values
long timestamp; // time of most recent value
@ -59,20 +54,10 @@ public class AccelListener implements SensorEventListener, Plugin {
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
super.setContext(ctx);
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -171,18 +156,6 @@ public class AccelListener implements SensorEventListener, Plugin {
}
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
@ -192,18 +165,6 @@ public class AccelListener implements SensorEventListener, Plugin {
this.stop();
}
/**
* 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------

View File

@ -7,13 +7,10 @@ import org.json.JSONArray;
import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginManager;
import com.phonegap.api.PluginResult;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.webkit.WebView;
/**
* This class called by DroidGap to play and record audio.
@ -26,10 +23,7 @@ import android.webkit.WebView;
* android_asset: file name must start with /android_asset/sound.mp3
* sdcard: file name is just sound.mp3
*/
public class AudioHandler implements Plugin {
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
public class AudioHandler extends Plugin {
HashMap<String,AudioPlayer> players; // Audio player object
@ -40,26 +34,6 @@ public class AudioHandler implements Plugin {
this.players = new HashMap<String,AudioPlayer>();
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -118,18 +92,6 @@ public class AudioHandler implements Plugin {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Stop all audio players and recorders.
*/
@ -144,18 +106,6 @@ public class AudioHandler implements Plugin {
this.players.clear();
}
/**
* 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------

View File

@ -95,7 +95,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
public void startRecording(String file) {
if (this.mPlayer != null) {
System.out.println("AudioPlayer Error: Can't record in play mode.");
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_PLAY_MODE_SET+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_PLAY_MODE_SET+");");
}
// Make sure we're not already recording
@ -116,11 +116,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
} catch (IOException e) {
e.printStackTrace();
}
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STARTING_RECORDING+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STARTING_RECORDING+");");
}
else {
System.out.println("AudioPlayer Error: Already recording.");
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_ALREADY_RECORDING+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_ALREADY_RECORDING+");");
}
}
@ -162,7 +162,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
public void startPlaying(String file) {
if (this.recorder != null) {
System.out.println("AudioPlayer Error: Can't play in record mode.");
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_RECORD_MODE_SET+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_RECORD_MODE_SET+");");
}
// If this is a new request to play audio, or stopped
@ -205,7 +205,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
}
catch (Exception e) {
e.printStackTrace();
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STARTING_PLAYBACK+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STARTING_PLAYBACK+");");
}
}
@ -219,7 +219,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
}
else {
System.out.println("AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_RESUME_STATE+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_RESUME_STATE+");");
}
}
}
@ -236,7 +236,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
}
else {
System.out.println("AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_PAUSE_STATE+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_PAUSE_STATE+");");
}
}
@ -250,7 +250,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
}
else {
System.out.println("AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STOP_STATE+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STOP_STATE+");");
}
}
@ -348,7 +348,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
this.prepareOnly = false;
// Send status notification to JavaScript
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
}
@ -368,7 +368,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
this.mPlayer.release();
// Send error notification to JavaScript
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
return false;
}
@ -379,7 +379,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
*/
private void setState(int state) {
if (this.state != state) {
this.handler.ctx.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_STATE+", "+this.state+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
}
this.state = state;

View File

@ -20,7 +20,6 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.net.Uri;
import android.os.Environment;
import android.webkit.WebView;
import android.provider.MediaStore;
/**
@ -28,7 +27,7 @@ import android.provider.MediaStore;
* and returns the captured image. When the camera view is closed, the screen displayed before
* the camera view was shown is redisplayed.
*/
public class CameraLauncher implements Plugin {
public class CameraLauncher extends Plugin {
private static final int DATA_URL = 0; // Return base64 encoded string
private static final int FILE_URI = 1; // Return file uri (content://media/external/images/media/2 for Android)
@ -37,9 +36,6 @@ public class CameraLauncher implements Plugin {
private static final int CAMERA = 1; // Take picture from camera
private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android)
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
private Uri imageUri; // Uri of captured image
@ -49,26 +45,6 @@ public class CameraLauncher implements Plugin {
public CameraLauncher() {
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -103,35 +79,6 @@ public class CameraLauncher implements Plugin {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
/**
* 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) {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public void onDestroy() {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
@ -235,7 +182,7 @@ public class CameraLauncher implements Plugin {
os.close();
// Send Uri back to JavaScript for viewing image
this.ctx.sendJavascript("navigator.camera.success('" + uri.toString() + "');");
this.sendJavascript("navigator.camera.success('" + uri.toString() + "');");
}
} catch (IOException e) {
e.printStackTrace();
@ -272,7 +219,7 @@ public class CameraLauncher implements Plugin {
// If sending filename back
else if (destType == FILE_URI) {
this.ctx.sendJavascript("navigator.camera.success('" + uri + "');");
this.sendJavascript("navigator.camera.success('" + uri + "');");
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
@ -296,7 +243,7 @@ public class CameraLauncher implements Plugin {
byte[] code = jpeg_data.toByteArray();
byte[] output = Base64.encodeBase64(code);
String js_out = new String(output);
this.ctx.sendJavascript("navigator.camera.success('" + js_out + "');");
this.sendJavascript("navigator.camera.success('" + js_out + "');");
}
}
catch(Exception e) {
@ -310,6 +257,6 @@ public class CameraLauncher implements Plugin {
* @param err
*/
public void failPicture(String err) {
this.ctx.sendJavascript("navigator.camera.error('" + err + "');");
this.sendJavascript("navigator.camera.error('" + err + "');");
}
}

View File

@ -13,13 +13,11 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
/**
* This class listens to the compass sensor and stores the latest heading value.
*/
public class CompassListener implements SensorEventListener, Plugin{
public class CompassListener extends Plugin implements SensorEventListener {
public static int STOPPED = 0;
public static int STARTING = 1;
@ -28,9 +26,6 @@ public class CompassListener implements SensorEventListener, Plugin{
public long TIMEOUT = 30000; // Timeout in msec to shut off listener
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
int status; // status of listener
float heading; // most recent heading value
long timeStamp; // time of most recent value
@ -54,20 +49,10 @@ public class CompassListener implements SensorEventListener, Plugin{
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
super.setContext(ctx);
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -149,18 +134,6 @@ public class CompassListener implements SensorEventListener, Plugin{
}
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called when listener is to be shut down and object is being destroyed.
@ -169,18 +142,6 @@ public class CompassListener implements SensorEventListener, Plugin{
this.stop();
}
/**
* 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------

View File

@ -3,20 +3,13 @@ package com.phonegap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.util.Log;
import android.webkit.WebView;
import android.content.Intent;
public class ContactManager implements Plugin {
public class ContactManager extends Plugin {
private static ContactAccessor contactAccessor;
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
private static final String LOG_TAG = "Contact Query";
/**
@ -25,26 +18,6 @@ public class ContactManager implements Plugin {
public ContactManager() {
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -83,45 +56,4 @@ public class ContactManager implements Plugin {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
/**
* 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) {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
}

View File

@ -6,40 +6,14 @@ import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Intent;
import android.webkit.WebView;
public class CryptoHandler implements Plugin {
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
public class CryptoHandler extends Plugin {
/**
* Constructor.
*/
public CryptoHandler() {
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -64,47 +38,6 @@ public class CryptoHandler implements Plugin {
}
}
/**
* 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) {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
@ -113,7 +46,7 @@ public class CryptoHandler implements Plugin {
try {
String encrypted = SimpleCrypto.encrypt(pass,text);
// TODO: Why not just return text now?
this.ctx.sendJavascript("Crypto.gotCryptedString('" + text + "')");
this.sendJavascript("Crypto.gotCryptedString('" + text + "')");
} catch (Exception e) {
e.printStackTrace();
}
@ -122,7 +55,7 @@ public class CryptoHandler implements Plugin {
public void decrypt(String pass, String text) {
try {
String decrypted = SimpleCrypto.decrypt(pass,text);
this.ctx.sendJavascript("Crypto.gotPlainString('" + text + "')");
this.sendJavascript("Crypto.gotPlainString('" + text + "')");
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -29,19 +29,14 @@ import org.json.JSONObject;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.webkit.WebView;
public class Device implements Plugin {
public class Device extends Plugin {
public static String phonegapVersion = "pre-0.92 EDGE"; // PhoneGap version
public static String platform = "Android"; // Device OS
public static String uuid; // Device UUID
private DroidGap ctx; // DroidGap object
@SuppressWarnings("unused")
private WebView webView; // Webview object
/**
* Constructor.
@ -56,20 +51,10 @@ public class Device implements Plugin {
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
super.setContext(ctx);
Device.uuid = getUuid();
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -113,37 +98,6 @@ public class Device implements Plugin {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called when the activity is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------

View File

@ -279,8 +279,8 @@ public class DroidGap extends Activity {
if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
Package pack = this.getClass().getPackage();
String appPackage = pack.getName();
Storage cupcakeStorage = (Storage)this.pluginManager.addPlugin("com.phonegap.Storage");
cupcakeStorage.setStorage(appPackage);
// TODO: Storage cupcakeStorage = (Storage)this.pluginManager.addPlugin("com.phonegap.Storage");
// TODO: cupcakeStorage.setStorage(appPackage);
}

View File

@ -9,14 +9,11 @@ import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Intent;
import android.webkit.WebView;
/**
* This class provides SD card file and directory services to JavaScript.
* Only files on the SD card can be accessed.
*/
public class FileUtils implements Plugin {
public class FileUtils extends Plugin {
public static int NOT_FOUND_ERR = 8;
public static int SECURITY_ERR = 18;
@ -25,10 +22,6 @@ public class FileUtils implements Plugin {
public static int NOT_READABLE_ERR = 24;
public static int ENCODING_ERR = 26;
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
FileReader f_in;
FileWriter f_out;
@ -39,26 +32,6 @@ public class FileUtils implements Plugin {
System.out.println("FileUtils()");
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -161,37 +134,6 @@ public class FileUtils implements Plugin {
return true;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------

View File

@ -9,20 +9,14 @@ import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Intent;
import android.webkit.WebView;
/*
* This class is the interface to the Geolocation. It's bound to the geo object.
*
* This class only starts and stops various GeoListeners, which consist of a GPS and a Network Listener
*/
public class GeoBroker implements Plugin {
public class GeoBroker extends Plugin {
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
// List of gGeolocation listeners
private HashMap<String, GeoListener> geoListeners;
private GeoListener global;
@ -34,26 +28,6 @@ public class GeoBroker implements Plugin {
this.geoListeners = new HashMap<String, GeoListener>();
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -92,18 +66,6 @@ public class GeoBroker implements Plugin {
// Starting listeners is easier to run on main thread, so don't run async.
return true;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called when the activity is to be shut down.
@ -124,18 +86,6 @@ public class GeoBroker implements Plugin {
this.global = null;
}
/**
* 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
@ -152,7 +102,7 @@ public class GeoBroker implements Plugin {
// Create a geolocation listener just for getCurrentLocation and call it "global"
if (this.global == null) {
this.global = new GeoListener("global", this.ctx, maximumAge, this.webView);
this.global = new GeoListener(this, "global", maximumAge);
}
else {
this.global.start(maximumAge);
@ -173,7 +123,7 @@ public class GeoBroker implements Plugin {
// Make sure this listener doesn't already exist
GeoListener listener = geoListeners.get(key);
if (listener == null) {
listener = new GeoListener(key, this.ctx, maximumAge, this.webView);
listener = new GeoListener(this, key, maximumAge);
geoListeners.put(key, listener);
}

View File

@ -17,9 +17,7 @@ public class GeoListener {
NetworkListener mNetwork; // Network listener
LocationManager mLocMan; // Location manager
private DroidGap ctx; // DroidGap object
@SuppressWarnings("unused")
private WebView mAppView; // Webview object
private GeoBroker broker; // GeoBroker object
int interval;
@ -31,24 +29,23 @@ public class GeoListener {
* @param time Sampling period in msec
* @param appView
*/
GeoListener(String id, DroidGap ctx, int time, WebView appView) {
GeoListener(GeoBroker broker, String id, int time) {
this.id = id;
this.interval = time;
this.ctx = ctx;
this.broker = broker;
this.mGps = null;
this.mNetwork = null;
this.mLocMan = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
this.mLocMan = (LocationManager) broker.ctx.getSystemService(Context.LOCATION_SERVICE);
// If GPS provider, then create and start GPS listener
if (this.mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) {
this.mGps = new GpsListener(ctx, time, this);
this.mGps = new GpsListener(broker.ctx, time, this);
}
// If network provider, then create and start network listener
if (this.mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
this.mNetwork = new NetworkListener(ctx, time, this);
this.mNetwork = new NetworkListener(broker.ctx, time, this);
}
this.mAppView = appView;
}
/**
@ -72,7 +69,7 @@ public class GeoListener {
if (id == "global") {
this.stop();
}
this.ctx.sendJavascript("navigator._geo.success('" + id + "'," + params + ");");
this.broker.sendJavascript("navigator._geo.success('" + id + "'," + params + ");");
}
/**
@ -82,7 +79,7 @@ public class GeoListener {
* @param msg The error message
*/
void fail(int code, String msg) {
this.ctx.sendJavascript("navigator._geo.fail('" + this.id + "', " + ", " + code + ", '" + msg + "');");
this.broker.sendJavascript("navigator._geo.fail('" + this.id + "', " + ", " + code + ", '" + msg + "');");
this.stop();
}

View File

@ -9,19 +9,13 @@ import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Context;
import android.content.Intent;
import android.net.*;
import android.webkit.WebView;
public class NetworkManager implements Plugin {
public class NetworkManager extends Plugin {
public static int NOT_REACHABLE = 0;
public static int REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
public static int REACHABLE_VIA_WIFI_NETWORK = 2;
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
ConnectivityManager sockMan;
@ -38,20 +32,10 @@ public class NetworkManager implements Plugin {
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
super.setContext(ctx);
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -92,37 +76,6 @@ public class NetworkManager implements Plugin {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
@ -169,13 +122,13 @@ public class NetworkManager implements Plugin {
uri = "http://" + uri;
}
if (isAvailable()) {
if (this.isAvailable()) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(uri);
httpclient.execute(httpget);
if (isWifiActive()) {
if (this.isWifiActive()) {
reachable = REACHABLE_VIA_WIFI_NETWORK;
}
else {

View File

@ -5,47 +5,22 @@ import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
import android.webkit.WebView;
/**
* This class provides access to notifications on the device.
*/
public class Notification implements Plugin {
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
public class Notification extends Plugin {
/**
* Constructor.
*/
public Notification() {
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -80,37 +55,6 @@ public class Notification implements Plugin {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------

View File

@ -6,18 +6,13 @@ import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.*;
import android.util.Log;
import android.webkit.WebView;
public class Storage implements Plugin {
public class Storage extends Plugin {
private static final String LOG_TAG = "SQLite Storage:";
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
SQLiteDatabase myDb;
String path;
@ -29,26 +24,6 @@ public class Storage implements Plugin {
public Storage() {
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -92,37 +67,6 @@ public class Storage implements Plugin {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
@ -146,7 +90,7 @@ public class Storage implements Plugin {
} catch (SQLiteException ex) {
Log.d(LOG_TAG, ex.getMessage());
txid = "";
this.ctx.sendJavascript("droiddb.fail(" + ex.getMessage() + "," + txid + ");");
this.sendJavascript("droiddb.fail(" + ex.getMessage() + "," + txid + ");");
}
}
@ -167,9 +111,9 @@ public class Storage implements Plugin {
}
}
resultString += "}";
this.ctx.sendJavascript("droiddb.addResult('" + resultString + "', " + txid + ");");
this.sendJavascript("droiddb.addResult('" + resultString + "', " + txid + ");");
} while (cur.moveToNext());
this.ctx.sendJavascript("droiddb.completeQuery(" + txid + ");");
this.sendJavascript("droiddb.completeQuery(" + txid + ");");
txid = "";
myDb.close();
}

View File

@ -12,13 +12,8 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
public class TempListener implements SensorEventListener, Plugin {
WebView webView; // WebView object
DroidGap ctx; // DroidGap object
public class TempListener extends Plugin implements SensorEventListener {
Sensor mSensor;
private SensorManager sensorManager;
@ -36,20 +31,10 @@ public class TempListener implements SensorEventListener, Plugin {
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
super.setContext(ctx);
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
@ -69,28 +54,6 @@ public class TempListener implements SensorEventListener, Plugin {
}
return new PluginResult(status, result);
}
/**
* 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) {
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called by AccelBroker when listener is to be shut down.
@ -100,18 +63,6 @@ public class TempListener implements SensorEventListener, Plugin {
this.stop();
}
/**
* 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").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
@ -135,7 +86,7 @@ public class TempListener implements SensorEventListener, Plugin {
public void onSensorChanged(SensorEvent event) {
// We want to know what temp this is.
float temp = event.values[0];
this.ctx.sendJavascript("gotTemp(" + temp + ");");
this.sendJavascript("gotTemp(" + temp + ");");
}
}

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);
}

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);
}
}