mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
Merge branch 'master' of github.com:phonegap/phonegap-android
This commit is contained in:
commit
086e6ea56b
5
framework/assets/js/notification.js
Normal file → Executable file
5
framework/assets/js/notification.js
Normal file → Executable file
@ -11,8 +11,9 @@ function Notification() {
|
|||||||
* @param {String} [buttonLabel="OK"] Label of the close button (default: OK)
|
* @param {String} [buttonLabel="OK"] Label of the close button (default: OK)
|
||||||
*/
|
*/
|
||||||
Notification.prototype.alert = function(message, title, buttonLabel) {
|
Notification.prototype.alert = function(message, title, buttonLabel) {
|
||||||
// Default is to use a browser alert; this will use "index.html" as the title though
|
var _title = (title || "Alert");
|
||||||
alert(message);
|
var _buttonLabel = (buttonLabel || "OK");
|
||||||
|
PhoneGap.execAsync(null, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,14 +14,12 @@ import android.hardware.SensorEvent;
|
|||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class listens to the accelerometer sensor and stores the latest
|
* This class listens to the accelerometer sensor and stores the latest
|
||||||
* acceleration values x,y,z.
|
* 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 STOPPED = 0;
|
||||||
public static int STARTING = 1;
|
public static int STARTING = 1;
|
||||||
@ -30,9 +28,6 @@ public class AccelListener implements SensorEventListener, Plugin {
|
|||||||
|
|
||||||
public float TIMEOUT = 30000; // Timeout in msec to shut off listener
|
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
|
float x,y,z; // most recent acceleration values
|
||||||
long timestamp; // time of most recent value
|
long timestamp; // time of most recent value
|
||||||
int status; // status of listener
|
int status; // status of listener
|
||||||
@ -59,28 +54,19 @@ public class AccelListener implements SensorEventListener, Plugin {
|
|||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Executes the request and returns PluginResult.
|
||||||
* a PhoneGap app runs.
|
|
||||||
*
|
*
|
||||||
* @param webView The PhoneGap WebView
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setView(WebView webView) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
this.webView = webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the request and returns CommandResult.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -172,18 +158,6 @@ public class AccelListener implements SensorEventListener, Plugin {
|
|||||||
return false;
|
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.
|
* Called by AccelBroker when listener is to be shut down.
|
||||||
* Stop listener.
|
* Stop listener.
|
||||||
@ -192,18 +166,6 @@ public class AccelListener implements SensorEventListener, Plugin {
|
|||||||
this.stop();
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -7,13 +7,10 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginManager;
|
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class called by DroidGap to play and record audio.
|
* 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
|
* android_asset: file name must start with /android_asset/sound.mp3
|
||||||
* sdcard: file name is just sound.mp3
|
* sdcard: file name is just sound.mp3
|
||||||
*/
|
*/
|
||||||
public class AudioHandler implements Plugin {
|
public class AudioHandler extends Plugin {
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
HashMap<String,AudioPlayer> players; // Audio player object
|
HashMap<String,AudioPlayer> players; // Audio player object
|
||||||
|
|
||||||
@ -41,33 +35,14 @@ public class AudioHandler implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -118,18 +93,6 @@ public class AudioHandler implements Plugin {
|
|||||||
return false;
|
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.
|
* Stop all audio players and recorders.
|
||||||
*/
|
*/
|
||||||
@ -144,18 +107,6 @@ public class AudioHandler implements Plugin {
|
|||||||
this.players.clear();
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -95,7 +95,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
public void startRecording(String file) {
|
public void startRecording(String file) {
|
||||||
if (this.mPlayer != null) {
|
if (this.mPlayer != null) {
|
||||||
System.out.println("AudioPlayer Error: Can't record in play mode.");
|
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
|
// Make sure we're not already recording
|
||||||
@ -116,11 +116,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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 {
|
else {
|
||||||
System.out.println("AudioPlayer Error: Already recording.");
|
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) {
|
public void startPlaying(String file) {
|
||||||
if (this.recorder != null) {
|
if (this.recorder != null) {
|
||||||
System.out.println("AudioPlayer Error: Can't play in record mode.");
|
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
|
// 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) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
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 {
|
else {
|
||||||
System.out.println("AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
|
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 {
|
else {
|
||||||
System.out.println("AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
|
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 {
|
else {
|
||||||
System.out.println("AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
|
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;
|
this.prepareOnly = false;
|
||||||
|
|
||||||
// Send status notification to JavaScript
|
// 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();
|
this.mPlayer.release();
|
||||||
|
|
||||||
// Send error notification to JavaScript
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
*/
|
*/
|
||||||
private void setState(int state) {
|
private void setState(int state) {
|
||||||
if (this.state != 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;
|
this.state = state;
|
||||||
|
@ -20,7 +20,6 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.Bitmap.CompressFormat;
|
import android.graphics.Bitmap.CompressFormat;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.provider.MediaStore;
|
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
|
* and returns the captured image. When the camera view is closed, the screen displayed before
|
||||||
* the camera view was shown is redisplayed.
|
* 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 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)
|
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 CAMERA = 1; // Take picture from camera
|
||||||
private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android)
|
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 int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||||
private Uri imageUri; // Uri of captured image
|
private Uri imageUri; // Uri of captured image
|
||||||
|
|
||||||
@ -50,33 +46,14 @@ public class CameraLauncher implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -104,35 +81,6 @@ public class CameraLauncher 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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
// LOCAL METHODS
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -235,7 +183,7 @@ public class CameraLauncher implements Plugin {
|
|||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
// Send Uri back to JavaScript for viewing image
|
// 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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -272,7 +220,7 @@ public class CameraLauncher implements Plugin {
|
|||||||
|
|
||||||
// If sending filename back
|
// If sending filename back
|
||||||
else if (destType == FILE_URI) {
|
else if (destType == FILE_URI) {
|
||||||
this.ctx.sendJavascript("navigator.camera.success('" + uri + "');");
|
this.sendJavascript("navigator.camera.success('" + uri + "');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
@ -296,7 +244,7 @@ public class CameraLauncher implements Plugin {
|
|||||||
byte[] code = jpeg_data.toByteArray();
|
byte[] code = jpeg_data.toByteArray();
|
||||||
byte[] output = Base64.encodeBase64(code);
|
byte[] output = Base64.encodeBase64(code);
|
||||||
String js_out = new String(output);
|
String js_out = new String(output);
|
||||||
this.ctx.sendJavascript("navigator.camera.success('" + js_out + "');");
|
this.sendJavascript("navigator.camera.success('" + js_out + "');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
@ -310,6 +258,6 @@ public class CameraLauncher implements Plugin {
|
|||||||
* @param err
|
* @param err
|
||||||
*/
|
*/
|
||||||
public void failPicture(String err) {
|
public void failPicture(String err) {
|
||||||
this.ctx.sendJavascript("navigator.camera.error('" + err + "');");
|
this.sendJavascript("navigator.camera.error('" + err + "');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,11 @@ import android.hardware.SensorEvent;
|
|||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.content.Context;
|
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.
|
* 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 STOPPED = 0;
|
||||||
public static int STARTING = 1;
|
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
|
public long TIMEOUT = 30000; // Timeout in msec to shut off listener
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
int status; // status of listener
|
int status; // status of listener
|
||||||
float heading; // most recent heading value
|
float heading; // most recent heading value
|
||||||
long timeStamp; // time of most recent value
|
long timeStamp; // time of most recent value
|
||||||
@ -54,28 +49,19 @@ public class CompassListener implements SensorEventListener, Plugin{
|
|||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Executes the request and returns PluginResult.
|
||||||
* a PhoneGap app runs.
|
|
||||||
*
|
*
|
||||||
* @param webView The PhoneGap WebView
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setView(WebView webView) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
this.webView = webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the request and returns CommandResult.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -150,18 +136,6 @@ public class CompassListener implements SensorEventListener, Plugin{
|
|||||||
return false;
|
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.
|
* Called when listener is to be shut down and object is being destroyed.
|
||||||
*/
|
*/
|
||||||
@ -169,18 +143,6 @@ public class CompassListener implements SensorEventListener, Plugin{
|
|||||||
this.stop();
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -3,20 +3,13 @@ package com.phonegap;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
import android.util.Log;
|
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;
|
private static ContactAccessor contactAccessor;
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
private static final String LOG_TAG = "Contact Query";
|
private static final String LOG_TAG = "Contact Query";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,33 +19,14 @@ public class ContactManager implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
if (contactAccessor == null) {
|
if (contactAccessor == null) {
|
||||||
contactAccessor = ContactAccessor.getInstance(webView, ctx);
|
contactAccessor = ContactAccessor.getInstance(webView, ctx);
|
||||||
}
|
}
|
||||||
@ -83,45 +57,4 @@ public class ContactManager implements Plugin {
|
|||||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
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) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,7 @@ import org.json.JSONException;
|
|||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
import android.content.Intent;
|
public class CryptoHandler extends Plugin {
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
public class CryptoHandler implements Plugin {
|
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -21,33 +15,14 @@ public class CryptoHandler implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -64,47 +39,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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -113,7 +47,7 @@ public class CryptoHandler implements Plugin {
|
|||||||
try {
|
try {
|
||||||
String encrypted = SimpleCrypto.encrypt(pass,text);
|
String encrypted = SimpleCrypto.encrypt(pass,text);
|
||||||
// TODO: Why not just return text now?
|
// TODO: Why not just return text now?
|
||||||
this.ctx.sendJavascript("Crypto.gotCryptedString('" + text + "')");
|
this.sendJavascript("Crypto.gotCryptedString('" + text + "')");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -122,7 +56,7 @@ public class CryptoHandler implements Plugin {
|
|||||||
public void decrypt(String pass, String text) {
|
public void decrypt(String pass, String text) {
|
||||||
try {
|
try {
|
||||||
String decrypted = SimpleCrypto.decrypt(pass,text);
|
String decrypted = SimpleCrypto.decrypt(pass,text);
|
||||||
this.ctx.sendJavascript("Crypto.gotPlainString('" + text + "')");
|
this.sendJavascript("Crypto.gotPlainString('" + text + "')");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -29,19 +29,14 @@ import org.json.JSONObject;
|
|||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.TelephonyManager;
|
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 phonegapVersion = "pre-0.92 EDGE"; // PhoneGap version
|
||||||
public static String platform = "Android"; // Device OS
|
public static String platform = "Android"; // Device OS
|
||||||
public static String uuid; // Device UUID
|
public static String uuid; // Device UUID
|
||||||
private DroidGap ctx; // DroidGap object
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private WebView webView; // Webview object
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -56,28 +51,19 @@ public class Device implements Plugin {
|
|||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
super.setContext(ctx);
|
||||||
Device.uuid = getUuid();
|
Device.uuid = getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Executes the request and returns PluginResult.
|
||||||
* a PhoneGap app runs.
|
|
||||||
*
|
*
|
||||||
* @param webView The PhoneGap WebView
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setView(WebView webView) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
this.webView = webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the request and returns CommandResult.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -113,37 +99,6 @@ public class Device implements Plugin {
|
|||||||
return false;
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -275,15 +275,6 @@ public class DroidGap extends Activity {
|
|||||||
appView.addJavascriptInterface(this.callbackServer, "CallbackServer");
|
appView.addJavascriptInterface(this.callbackServer, "CallbackServer");
|
||||||
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
appView.addJavascriptInterface(new SplashScreen(this), "SplashScreen");
|
||||||
|
|
||||||
// Add in support for storage and location for Android 1.X devices
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addService("Geolocation", "com.phonegap.GeoBroker");
|
this.addService("Geolocation", "com.phonegap.GeoBroker");
|
||||||
this.addService("Device", "com.phonegap.Device");
|
this.addService("Device", "com.phonegap.Device");
|
||||||
@ -294,11 +285,21 @@ public class DroidGap extends Activity {
|
|||||||
this.addService("Contacts", "com.phonegap.ContactManager");
|
this.addService("Contacts", "com.phonegap.ContactManager");
|
||||||
this.addService("Crypto", "com.phonegap.CryptoHandler");
|
this.addService("Crypto", "com.phonegap.CryptoHandler");
|
||||||
this.addService("File", "com.phonegap.FileUtils");
|
this.addService("File", "com.phonegap.FileUtils");
|
||||||
this.addService("Location", "com.phonegap.GeoBroker");
|
this.addService("Location", "com.phonegap.GeoBroker"); // Always add Location, even though it is built-in on 2.x devices. Let JavaScript decide which one to use.
|
||||||
this.addService("Network Status", "com.phonegap.NetworkManager");
|
this.addService("Network Status", "com.phonegap.NetworkManager");
|
||||||
this.addService("Notification", "com.phonegap.Notification");
|
this.addService("Notification", "com.phonegap.Notification");
|
||||||
this.addService("Storage", "com.phonegap.Storage");
|
this.addService("Storage", "com.phonegap.Storage");
|
||||||
this.addService("Temperature", "com.phonegap.TempListener");
|
this.addService("Temperature", "com.phonegap.TempListener");
|
||||||
|
|
||||||
|
// Add in support for storage for Android 1.X devices
|
||||||
|
if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
|
||||||
|
System.out.println("Android 1.X device");
|
||||||
|
|
||||||
|
Package pack = this.getClass().getPackage();
|
||||||
|
String appPackage = pack.getName();
|
||||||
|
this.pluginManager.exec("Storage", "setStorage", null, "["+appPackage+"]", false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,14 +9,11 @@ import org.json.JSONException;
|
|||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides SD card file and directory services to JavaScript.
|
* This class provides SD card file and directory services to JavaScript.
|
||||||
* Only files on the SD card can be accessed.
|
* 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 NOT_FOUND_ERR = 8;
|
||||||
public static int SECURITY_ERR = 18;
|
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 NOT_READABLE_ERR = 24;
|
||||||
public static int ENCODING_ERR = 26;
|
public static int ENCODING_ERR = 26;
|
||||||
|
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
FileReader f_in;
|
FileReader f_in;
|
||||||
FileWriter f_out;
|
FileWriter f_out;
|
||||||
|
|
||||||
@ -40,33 +33,14 @@ public class FileUtils implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
//System.out.println("FileUtils.execute("+action+")");
|
//System.out.println("FileUtils.execute("+action+")");
|
||||||
@ -161,37 +135,6 @@ public class FileUtils implements Plugin {
|
|||||||
return true;
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -9,19 +9,13 @@ import org.json.JSONException;
|
|||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
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 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
|
* 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
|
// List of gGeolocation listeners
|
||||||
private HashMap<String, GeoListener> geoListeners;
|
private HashMap<String, GeoListener> geoListeners;
|
||||||
@ -35,33 +29,14 @@ public class GeoBroker implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -93,18 +68,6 @@ public class GeoBroker implements Plugin {
|
|||||||
return true;
|
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.
|
* Called when the activity is to be shut down.
|
||||||
* Stop listener.
|
* Stop listener.
|
||||||
@ -124,18 +87,6 @@ public class GeoBroker implements Plugin {
|
|||||||
this.global = null;
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -152,7 +103,7 @@ public class GeoBroker implements Plugin {
|
|||||||
|
|
||||||
// Create a geolocation listener just for getCurrentLocation and call it "global"
|
// Create a geolocation listener just for getCurrentLocation and call it "global"
|
||||||
if (this.global == null) {
|
if (this.global == null) {
|
||||||
this.global = new GeoListener("global", this.ctx, maximumAge, this.webView);
|
this.global = new GeoListener(this, "global", maximumAge);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.global.start(maximumAge);
|
this.global.start(maximumAge);
|
||||||
@ -173,7 +124,7 @@ public class GeoBroker implements Plugin {
|
|||||||
// Make sure this listener doesn't already exist
|
// Make sure this listener doesn't already exist
|
||||||
GeoListener listener = geoListeners.get(key);
|
GeoListener listener = geoListeners.get(key);
|
||||||
if (listener == null) {
|
if (listener == null) {
|
||||||
listener = new GeoListener(key, this.ctx, maximumAge, this.webView);
|
listener = new GeoListener(this, key, maximumAge);
|
||||||
geoListeners.put(key, listener);
|
geoListeners.put(key, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@ public class GeoListener {
|
|||||||
NetworkListener mNetwork; // Network listener
|
NetworkListener mNetwork; // Network listener
|
||||||
LocationManager mLocMan; // Location manager
|
LocationManager mLocMan; // Location manager
|
||||||
|
|
||||||
private DroidGap ctx; // DroidGap object
|
private GeoBroker broker; // GeoBroker object
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private WebView mAppView; // Webview object
|
|
||||||
|
|
||||||
int interval;
|
int interval;
|
||||||
|
|
||||||
@ -31,24 +29,23 @@ public class GeoListener {
|
|||||||
* @param time Sampling period in msec
|
* @param time Sampling period in msec
|
||||||
* @param appView
|
* @param appView
|
||||||
*/
|
*/
|
||||||
GeoListener(String id, DroidGap ctx, int time, WebView appView) {
|
GeoListener(GeoBroker broker, String id, int time) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.interval = time;
|
this.interval = time;
|
||||||
this.ctx = ctx;
|
this.broker = broker;
|
||||||
this.mGps = null;
|
this.mGps = null;
|
||||||
this.mNetwork = 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 GPS provider, then create and start GPS listener
|
||||||
if (this.mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) {
|
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 network provider, then create and start network listener
|
||||||
if (this.mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
|
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") {
|
if (id == "global") {
|
||||||
this.stop();
|
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
|
* @param msg The error message
|
||||||
*/
|
*/
|
||||||
void fail(int code, String msg) {
|
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();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,20 +9,14 @@ import com.phonegap.api.Plugin;
|
|||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.*;
|
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 NOT_REACHABLE = 0;
|
||||||
public static int REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
|
public static int REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
|
||||||
public static int REACHABLE_VIA_WIFI_NETWORK = 2;
|
public static int REACHABLE_VIA_WIFI_NETWORK = 2;
|
||||||
|
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
ConnectivityManager sockMan;
|
ConnectivityManager sockMan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,28 +32,19 @@ public class NetworkManager implements Plugin {
|
|||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
super.setContext(ctx);
|
||||||
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Executes the request and returns PluginResult.
|
||||||
* a PhoneGap app runs.
|
|
||||||
*
|
*
|
||||||
* @param webView The PhoneGap WebView
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setView(WebView webView) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
this.webView = webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the request and returns CommandResult.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
@ -92,37 +77,6 @@ public class NetworkManager implements Plugin {
|
|||||||
return false;
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -169,13 +123,13 @@ public class NetworkManager implements Plugin {
|
|||||||
uri = "http://" + uri;
|
uri = "http://" + uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAvailable()) {
|
if (this.isAvailable()) {
|
||||||
try {
|
try {
|
||||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||||
HttpGet httpget = new HttpGet(uri);
|
HttpGet httpget = new HttpGet(uri);
|
||||||
httpclient.execute(httpget);
|
httpclient.execute(httpget);
|
||||||
|
|
||||||
if (isWifiActive()) {
|
if (this.isWifiActive()) {
|
||||||
reachable = REACHABLE_VIA_WIFI_NETWORK;
|
reachable = REACHABLE_VIA_WIFI_NETWORK;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4,21 +4,18 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.DialogInterface;
|
||||||
import android.media.Ringtone;
|
import android.media.Ringtone;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to notifications on the device.
|
* This class provides access to notifications on the device.
|
||||||
*/
|
*/
|
||||||
public class Notification implements Plugin {
|
public class Notification extends Plugin {
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -27,33 +24,14 @@ public class Notification implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -64,6 +42,9 @@ public class Notification implements Plugin {
|
|||||||
else if (action.equals("vibrate")) {
|
else if (action.equals("vibrate")) {
|
||||||
this.vibrate(args.getLong(0));
|
this.vibrate(args.getLong(0));
|
||||||
}
|
}
|
||||||
|
else if (action.equals("alert")) {
|
||||||
|
this.alert(args.getString(0),args.getString(1),args.getString(2));
|
||||||
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
@ -77,40 +58,12 @@ public class Notification implements Plugin {
|
|||||||
* @return T=returns value
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
|
if(action.equals("alert"))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
return false;
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -154,4 +107,25 @@ public class Notification implements Plugin {
|
|||||||
vibrator.vibrate(time);
|
vibrator.vibrate(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds and shows a native Android alert with given Strings
|
||||||
|
* @param message The message the alert should display
|
||||||
|
* @param title The title of the alert
|
||||||
|
* @param buttonLabel The label of the button
|
||||||
|
*/
|
||||||
|
public synchronized void alert(String message,String title,String buttonLabel){
|
||||||
|
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
||||||
|
dlg.setMessage(message);
|
||||||
|
dlg.setTitle(title);
|
||||||
|
dlg.setCancelable(false);
|
||||||
|
dlg.setPositiveButton(buttonLabel,
|
||||||
|
new AlertDialog.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlg.create();
|
||||||
|
dlg.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
75
framework/src/com/phonegap/Storage.java
Normal file → Executable file
75
framework/src/com/phonegap/Storage.java
Normal file → Executable file
@ -6,19 +6,14 @@ import org.json.JSONException;
|
|||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.*;
|
import android.database.sqlite.*;
|
||||||
import android.util.Log;
|
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:";
|
private static final String LOG_TAG = "SQLite Storage:";
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
SQLiteDatabase myDb;
|
SQLiteDatabase myDb;
|
||||||
String path;
|
String path;
|
||||||
String txid = "";
|
String txid = "";
|
||||||
@ -30,33 +25,14 @@ public class Storage implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Executes the request and returns PluginResult.
|
||||||
* get file paths associated with the Activity.
|
|
||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -92,37 +68,6 @@ public class Storage implements Plugin {
|
|||||||
return false;
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -146,7 +91,7 @@ public class Storage implements Plugin {
|
|||||||
} catch (SQLiteException ex) {
|
} catch (SQLiteException ex) {
|
||||||
Log.d(LOG_TAG, ex.getMessage());
|
Log.d(LOG_TAG, ex.getMessage());
|
||||||
txid = "";
|
txid = "";
|
||||||
this.ctx.sendJavascript("droiddb.fail(" + ex.getMessage() + "," + txid + ");");
|
this.sendJavascript("droiddb.fail(" + ex.getMessage() + "," + txid + ");");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +112,9 @@ public class Storage implements Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
resultString += "}";
|
resultString += "}";
|
||||||
this.ctx.sendJavascript("droiddb.addResult('" + resultString + "', " + txid + ");");
|
this.sendJavascript("droiddb.addResult('" + resultString + "', " + txid + ");");
|
||||||
} while (cur.moveToNext());
|
} while (cur.moveToNext());
|
||||||
this.ctx.sendJavascript("droiddb.completeQuery(" + txid + ");");
|
this.sendJavascript("droiddb.completeQuery(" + txid + ");");
|
||||||
txid = "";
|
txid = "";
|
||||||
myDb.close();
|
myDb.close();
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,8 @@ import android.hardware.SensorEvent;
|
|||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
public class TempListener implements SensorEventListener, Plugin {
|
public class TempListener extends Plugin implements SensorEventListener {
|
||||||
|
|
||||||
WebView webView; // WebView object
|
|
||||||
DroidGap ctx; // DroidGap object
|
|
||||||
|
|
||||||
Sensor mSensor;
|
Sensor mSensor;
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
@ -36,28 +31,19 @@ public class TempListener implements SensorEventListener, Plugin {
|
|||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Executes the request and returns PluginResult.
|
||||||
* a PhoneGap app runs.
|
|
||||||
*
|
*
|
||||||
* @param webView The PhoneGap WebView
|
* @param action The action to execute.
|
||||||
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public void setView(WebView webView) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
this.webView = webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the request and returns CommandResult.
|
|
||||||
*
|
|
||||||
* @param action The command to execute.
|
|
||||||
* @param args JSONArry of arguments for the command.
|
|
||||||
* @return A CommandResult object with a status and message.
|
|
||||||
*/
|
|
||||||
public PluginResult execute(String action, JSONArray args) {
|
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
@ -70,28 +56,6 @@ public class TempListener implements SensorEventListener, Plugin {
|
|||||||
return new PluginResult(status, result);
|
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.
|
* Called by AccelBroker when listener is to be shut down.
|
||||||
* Stop listener.
|
* Stop listener.
|
||||||
@ -100,18 +64,6 @@ public class TempListener implements SensorEventListener, Plugin {
|
|||||||
this.stop();
|
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
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -135,7 +87,7 @@ public class TempListener implements SensorEventListener, Plugin {
|
|||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
// We want to know what temp this is.
|
// We want to know what temp this is.
|
||||||
float temp = event.values[0];
|
float temp = event.values[0];
|
||||||
this.ctx.sendJavascript("gotTemp(" + temp + ");");
|
this.sendJavascript("gotTemp(" + temp + ");");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
75
framework/src/com/phonegap/api/IPlugin.java
Executable file
75
framework/src/com/phonegap/api/IPlugin.java
Executable file
@ -0,0 +1,75 @@
|
|||||||
|
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.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
|
*/
|
||||||
|
PluginResult execute(String action, JSONArray args, String callbackId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,7 @@
|
|||||||
package com.phonegap.api;
|
package com.phonegap.api;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
|
||||||
import com.phonegap.DroidGap;
|
import com.phonegap.DroidGap;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
@ -13,15 +10,20 @@ import android.webkit.WebView;
|
|||||||
*
|
*
|
||||||
* The execute method is called by the PluginManager.
|
* 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.
|
* Executes the request and returns PluginResult.
|
||||||
*
|
*
|
||||||
* @param action The action to execute.
|
* @param action The action to execute.
|
||||||
* @param args JSONArry of arguments for the plugin.
|
* @param args JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
* @return A PluginResult object with a status and message.
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
PluginResult execute(String action, JSONArray args);
|
public abstract PluginResult execute(String action, JSONArray args, String callbackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||||
@ -29,7 +31,9 @@ public interface Plugin {
|
|||||||
* @param action The action to execute
|
* @param action The action to execute
|
||||||
* @return T=returns value
|
* @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
|
* Sets the context of the Plugin. This can then be used to do things like
|
||||||
@ -37,7 +41,9 @@ public interface Plugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @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
|
* Sets the main View of the application, this is the WebView within which
|
||||||
@ -45,22 +51,27 @@ public interface Plugin {
|
|||||||
*
|
*
|
||||||
* @param webView The PhoneGap WebView
|
* @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.
|
* 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.
|
* 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.
|
* 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,
|
* Called when an activity you launched exits, giving you the requestCode you started it with,
|
||||||
@ -71,6 +82,40 @@ public interface Plugin {
|
|||||||
* @param resultCode The integer result code returned by the child activity through its setResult().
|
* @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").
|
* @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 generic JavaScript statement back to JavaScript.
|
||||||
|
* success(...) and error(...) should be used instead where possible.
|
||||||
|
*
|
||||||
|
* @param statement
|
||||||
|
*/
|
||||||
|
public void sendJavascript(String statement) {
|
||||||
|
this.ctx.callbackServer.sendJavascript(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the JavaScript success callback for this plugin.
|
||||||
|
*
|
||||||
|
* This can be used if the execute code for the plugin is asynchronous meaning
|
||||||
|
* that execute should return null and the callback from the async operation can
|
||||||
|
* call success(...) or error(...)
|
||||||
|
*
|
||||||
|
* @param pluginResult The result to return.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
*/
|
||||||
|
public void success(PluginResult pluginResult, String callbackId) {
|
||||||
|
this.ctx.callbackServer.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the JavaScript error callback for this plugin.
|
||||||
|
*
|
||||||
|
* @param pluginResult The result to return.
|
||||||
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
|
*/
|
||||||
|
public void error(PluginResult pluginResult, String callbackId) {
|
||||||
|
this.ctx.callbackServer.sendJavascript(pluginResult.toErrorCallbackString(callbackId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ public final class PluginManager {
|
|||||||
*
|
*
|
||||||
* @return JSON encoded string with a response message and status.
|
* @return JSON encoded string with a response message and status.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
|
public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
|
||||||
System.out.println("PluginManager.exec("+service+", "+action+", "+callbackId+", "+jsonArgs+", "+async+")");
|
System.out.println("PluginManager.exec("+service+", "+action+", "+callbackId+", "+jsonArgs+", "+async+")");
|
||||||
PluginResult cr = null;
|
PluginResult cr = null;
|
||||||
@ -68,29 +69,34 @@ public final class PluginManager {
|
|||||||
if (clazz != null) {
|
if (clazz != null) {
|
||||||
c = getClassByName(clazz);
|
c = getClassByName(clazz);
|
||||||
}
|
}
|
||||||
if ((c == null) || isPhoneGapPlugin(c)) {
|
if (isPhoneGapPlugin(c)) {
|
||||||
final Plugin plugin = this.addPlugin(clazz);
|
final Plugin plugin = this.addPlugin(clazz, c);
|
||||||
final DroidGap ctx = this.ctx;
|
final DroidGap ctx = this.ctx;
|
||||||
runAsync = async && !plugin.isSynch(action);
|
runAsync = async && !plugin.isSynch(action);
|
||||||
if (async && !plugin.isSynch(action)) {
|
if (runAsync) {
|
||||||
// Run this on a different thread so that this one can return back to JS
|
// Run this on a different thread so that this one can return back to JS
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
// Call execute on the plugin so that it can do it's thing
|
// Call execute on the plugin so that it can do it's thing
|
||||||
PluginResult cr = plugin.execute(action, args);
|
PluginResult cr = plugin.execute(action, args, callbackId);
|
||||||
// Check the status for 0 (success) or otherwise
|
// Check the status for 0 (success) or otherwise
|
||||||
if (cr.getStatus() == 0) {
|
if (cr.getStatus() == 0) {
|
||||||
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
||||||
} else {
|
} else {
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
PluginResult cr = new PluginResult(PluginResult.Status.ERROR);
|
||||||
|
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
thread.start();
|
thread.start();
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
// Call execute on the plugin so that it can do it's thing
|
// Call execute on the plugin so that it can do it's thing
|
||||||
cr = plugin.execute(action, args);
|
cr = plugin.execute(action, args, callbackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -101,6 +107,9 @@ public final class PluginManager {
|
|||||||
}
|
}
|
||||||
// if async we have already returned at this point unless there was an error...
|
// if async we have already returned at this point unless there was an error...
|
||||||
if (runAsync) {
|
if (runAsync) {
|
||||||
|
if (cr == null) {
|
||||||
|
cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
|
||||||
|
}
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
if (cr != null) {
|
if (cr != null) {
|
||||||
@ -116,6 +125,7 @@ public final class PluginManager {
|
|||||||
* @return
|
* @return
|
||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private Class getClassByName(final String clazz) throws ClassNotFoundException {
|
private Class getClassByName(final String clazz) throws ClassNotFoundException {
|
||||||
return Class.forName(clazz);
|
return Class.forName(clazz);
|
||||||
}
|
}
|
||||||
@ -127,32 +137,56 @@ public final class PluginManager {
|
|||||||
* @param c The class to check the interfaces of.
|
* @param c The class to check the interfaces of.
|
||||||
* @return Boolean indicating if the class implements com.phonegap.api.Plugin
|
* @return Boolean indicating if the class implements com.phonegap.api.Plugin
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private boolean isPhoneGapPlugin(Class c) {
|
private boolean isPhoneGapPlugin(Class c) {
|
||||||
boolean isPlugin = false;
|
if (c != null) {
|
||||||
|
if (c.getSuperclass().getName().equals("com.phonegap.api.Plugin")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Class[] interfaces = c.getInterfaces();
|
Class[] interfaces = c.getInterfaces();
|
||||||
for (int j=0; j<interfaces.length; j++) {
|
for (int j=0; j<interfaces.length; j++) {
|
||||||
if (interfaces[j].getName().equals("com.phonegap.api.Plugin")) {
|
if (interfaces[j].getName().equals("com.phonegap.api.IPlugin")) {
|
||||||
isPlugin = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isPlugin;
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add plugin to be loaded and cached.
|
* Add plugin to be loaded and cached. This creates an instance of the plugin.
|
||||||
* If plugin is already created, then just return it.
|
* If plugin is already created, then just return it.
|
||||||
*
|
*
|
||||||
* @param className The class to load
|
* @param className The class to load
|
||||||
* @return The plugin
|
* @return The plugin
|
||||||
*/
|
*/
|
||||||
public Plugin addPlugin(String className) {
|
public Plugin addPlugin(String className) {
|
||||||
|
try {
|
||||||
|
return this.addPlugin(className, this.getClassByName(className));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("Error adding plugin "+className+".");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add plugin to be loaded and cached. This creates an instance of the plugin.
|
||||||
|
* If plugin is already created, then just return it.
|
||||||
|
*
|
||||||
|
* @param className The class to load
|
||||||
|
* @param clazz The class object (must be a class object of the className)
|
||||||
|
* @param callbackId The callback id to use when calling back into JavaScript
|
||||||
|
* @return The plugin
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Plugin addPlugin(String className, Class clazz) {
|
||||||
if (this.plugins.containsKey(className)) {
|
if (this.plugins.containsKey(className)) {
|
||||||
return this.getPlugin(className);
|
return this.getPlugin(className);
|
||||||
}
|
}
|
||||||
System.out.println("PluginManager.addPlugin("+className+")");
|
System.out.println("PluginManager.addPlugin("+className+")");
|
||||||
try {
|
try {
|
||||||
Plugin plugin = (Plugin)Class.forName(className).newInstance();
|
Plugin plugin = (Plugin)clazz.newInstance();
|
||||||
this.plugins.put(className, plugin);
|
this.plugins.put(className, plugin);
|
||||||
plugin.setContext((DroidGap)this.ctx);
|
plugin.setContext((DroidGap)this.ctx);
|
||||||
plugin.setView(this.app);
|
plugin.setView(this.app);
|
||||||
@ -171,13 +205,14 @@ public final class PluginManager {
|
|||||||
* @param className The class of the loaded plugin.
|
* @param className The class of the loaded plugin.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Plugin getPlugin(String className) {
|
private Plugin getPlugin(String className) {
|
||||||
Plugin plugin = this.plugins.get(className);
|
Plugin plugin = this.plugins.get(className);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a class that implements a service.
|
* Add a class that implements a service.
|
||||||
|
* This does not create the class instance. It just maps service name to class name.
|
||||||
*
|
*
|
||||||
* @param serviceType
|
* @param serviceType
|
||||||
* @param className
|
* @param className
|
||||||
@ -186,16 +221,6 @@ public final class PluginManager {
|
|||||||
this.services.put(serviceType, className);
|
this.services.put(serviceType, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the class that implements a service.
|
|
||||||
*
|
|
||||||
* @param serviceType
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getClassForService(String serviceType) {
|
|
||||||
return this.services.get(serviceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the system is about to start resuming a previous activity.
|
* Called when the system is about to start resuming a previous activity.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user