Remove manual catching of JSONException where possible.

Delegate the catching to caller instead. Related to refactoring of
Plugin->CordovaPlugin.
This commit is contained in:
Andrew Grieve 2012-10-15 13:58:44 -04:00
parent 1bc032853c
commit dc5078306d
10 changed files with 290 additions and 340 deletions

View File

@ -63,64 +63,59 @@ public class AudioHandler extends CordovaPlugin {
* @param callbackContext The callback context used when calling back into JavaScript. * @param callbackContext The callback context used when calling back into JavaScript.
* @return A PluginResult object with a status and message. * @return A PluginResult object with a status and message.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
PluginResult.Status status = PluginResult.Status.OK; PluginResult.Status status = PluginResult.Status.OK;
String result = ""; String result = "";
try { if (action.equals("startRecordingAudio")) {
if (action.equals("startRecordingAudio")) { this.startRecordingAudio(args.getString(0), FileUtils.stripFileProtocol(args.getString(1)));
this.startRecordingAudio(args.getString(0), FileUtils.stripFileProtocol(args.getString(1)));
}
else if (action.equals("stopRecordingAudio")) {
this.stopRecordingAudio(args.getString(0));
}
else if (action.equals("startPlayingAudio")) {
this.startPlayingAudio(args.getString(0), FileUtils.stripFileProtocol(args.getString(1)));
}
else if (action.equals("seekToAudio")) {
this.seekToAudio(args.getString(0), args.getInt(1));
}
else if (action.equals("pausePlayingAudio")) {
this.pausePlayingAudio(args.getString(0));
}
else if (action.equals("stopPlayingAudio")) {
this.stopPlayingAudio(args.getString(0));
} else if (action.equals("setVolume")) {
try {
this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
} catch (NumberFormatException nfe) {
//no-op
}
} else if (action.equals("getCurrentPositionAudio")) {
float f = this.getCurrentPositionAudio(args.getString(0));
callbackContext.sendPluginResult(new PluginResult(status, f));
return true;
}
else if (action.equals("getDurationAudio")) {
float f = this.getDurationAudio(args.getString(0), args.getString(1));
callbackContext.sendPluginResult(new PluginResult(status, f));
return true;
}
else if (action.equals("create")) {
String id = args.getString(0);
String src = FileUtils.stripFileProtocol(args.getString(1));
AudioPlayer audio = new AudioPlayer(this, id, src);
this.players.put(id, audio);
}
else if (action.equals("release")) {
boolean b = this.release(args.getString(0));
callbackContext.sendPluginResult(new PluginResult(status, b));
return true;
}
else { // Unrecognized action.
return false;
}
callbackContext.sendPluginResult(new PluginResult(status, result));
} catch (JSONException e) {
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
else if (action.equals("stopRecordingAudio")) {
this.stopRecordingAudio(args.getString(0));
}
else if (action.equals("startPlayingAudio")) {
this.startPlayingAudio(args.getString(0), FileUtils.stripFileProtocol(args.getString(1)));
}
else if (action.equals("seekToAudio")) {
this.seekToAudio(args.getString(0), args.getInt(1));
}
else if (action.equals("pausePlayingAudio")) {
this.pausePlayingAudio(args.getString(0));
}
else if (action.equals("stopPlayingAudio")) {
this.stopPlayingAudio(args.getString(0));
} else if (action.equals("setVolume")) {
try {
this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
} catch (NumberFormatException nfe) {
//no-op
}
} else if (action.equals("getCurrentPositionAudio")) {
float f = this.getCurrentPositionAudio(args.getString(0));
callbackContext.sendPluginResult(new PluginResult(status, f));
return true;
}
else if (action.equals("getDurationAudio")) {
float f = this.getDurationAudio(args.getString(0), args.getString(1));
callbackContext.sendPluginResult(new PluginResult(status, f));
return true;
}
else if (action.equals("create")) {
String id = args.getString(0);
String src = FileUtils.stripFileProtocol(args.getString(1));
AudioPlayer audio = new AudioPlayer(this, id, src);
this.players.put(id, audio);
}
else if (action.equals("release")) {
boolean b = this.release(args.getString(0));
callbackContext.sendPluginResult(new PluginResult(status, b));
return true;
}
else { // Unrecognized action.
return false;
}
callbackContext.sendPluginResult(new PluginResult(status, result));
return true; return true;
} }

View File

@ -116,57 +116,51 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* @param callbackContext The callback id used when calling back into JavaScript. * @param callbackContext 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.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext; this.callbackContext = callbackContext;
try { if (action.equals("takePicture")) {
if (action.equals("takePicture")) { int srcType = CAMERA;
int srcType = CAMERA; int destType = FILE_URI;
int destType = FILE_URI; this.saveToPhotoAlbum = false;
this.saveToPhotoAlbum = false; this.targetHeight = 0;
this.targetHeight = 0; this.targetWidth = 0;
this.targetWidth = 0; this.encodingType = JPEG;
this.encodingType = JPEG; this.mediaType = PICTURE;
this.mediaType = PICTURE; this.mQuality = 80;
this.mQuality = 80;
this.mQuality = args.getInt(0); this.mQuality = args.getInt(0);
destType = args.getInt(1); destType = args.getInt(1);
srcType = args.getInt(2); srcType = args.getInt(2);
this.targetWidth = args.getInt(3); this.targetWidth = args.getInt(3);
this.targetHeight = args.getInt(4); this.targetHeight = args.getInt(4);
this.encodingType = args.getInt(5); this.encodingType = args.getInt(5);
this.mediaType = args.getInt(6); this.mediaType = args.getInt(6);
//this.allowEdit = args.getBoolean(7); // This field is unused. //this.allowEdit = args.getBoolean(7); // This field is unused.
this.correctOrientation = args.getBoolean(8); this.correctOrientation = args.getBoolean(8);
this.saveToPhotoAlbum = args.getBoolean(9); this.saveToPhotoAlbum = args.getBoolean(9);
// If the user specifies a 0 or smaller width/height // If the user specifies a 0 or smaller width/height
// make it -1 so later comparisons succeed // make it -1 so later comparisons succeed
if (this.targetWidth < 1) { if (this.targetWidth < 1) {
this.targetWidth = -1; this.targetWidth = -1;
}
if (this.targetHeight < 1) {
this.targetHeight = -1;
}
if (srcType == CAMERA) {
this.takePicture(destType, encodingType);
}
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
this.getImage(srcType, destType);
}
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);
return true;
} }
return false; if (this.targetHeight < 1) {
} catch (JSONException e) { this.targetHeight = -1;
e.printStackTrace(); }
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
if (srcType == CAMERA) {
this.takePicture(destType, encodingType);
}
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
this.getImage(srcType, destType);
}
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);
return true; return true;
} }
return false;
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------

View File

@ -76,7 +76,7 @@ public class Capture extends CordovaPlugin {
// } // }
@Override @Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext; this.callbackContext = callbackContext;
this.limit = 1; this.limit = 1;
this.duration = 0.0f; this.duration = 0.0f;
@ -89,12 +89,8 @@ public class Capture extends CordovaPlugin {
} }
if (action.equals("getFormatData")) { if (action.equals("getFormatData")) {
try { JSONObject obj = getFormatData(args.getString(0), args.getString(1));
JSONObject obj = getFormatData(args.getString(0), args.getString(1)); callbackContext.success(obj);
callbackContext.success(obj);
} catch (JSONException e) {
callbackContext.error("");
}
return true; return true;
} }
else if (action.equals("captureAudio")) { else if (action.equals("captureAudio")) {
@ -120,34 +116,30 @@ public class Capture extends CordovaPlugin {
* @param mimeType of the file * @param mimeType of the file
* @return a MediaFileData object * @return a MediaFileData object
*/ */
private JSONObject getFormatData(String filePath, String mimeType) { private JSONObject getFormatData(String filePath, String mimeType) throws JSONException {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
try { // setup defaults
// setup defaults obj.put("height", 0);
obj.put("height", 0); obj.put("width", 0);
obj.put("width", 0); obj.put("bitrate", 0);
obj.put("bitrate", 0); obj.put("duration", 0);
obj.put("duration", 0); obj.put("codecs", "");
obj.put("codecs", "");
// If the mimeType isn't set the rest will fail // If the mimeType isn't set the rest will fail
// so let's see if we can determine it. // so let's see if we can determine it.
if (mimeType == null || mimeType.equals("")) { if (mimeType == null || mimeType.equals("")) {
mimeType = FileUtils.getMimeType(filePath); mimeType = FileUtils.getMimeType(filePath);
} }
Log.d(LOG_TAG, "Mime type = " + mimeType); Log.d(LOG_TAG, "Mime type = " + mimeType);
if (mimeType.equals(IMAGE_JPEG) || filePath.endsWith(".jpg")) { if (mimeType.equals(IMAGE_JPEG) || filePath.endsWith(".jpg")) {
obj = getImageData(filePath, obj); obj = getImageData(filePath, obj);
} }
else if (mimeType.endsWith(AUDIO_3GPP)) { else if (mimeType.endsWith(AUDIO_3GPP)) {
obj = getAudioVideoData(filePath, obj, false); obj = getAudioVideoData(filePath, obj, false);
} }
else if (mimeType.equals(VIDEO_3GPP) || mimeType.equals(VIDEO_MP4)) { else if (mimeType.equals(VIDEO_3GPP) || mimeType.equals(VIDEO_MP4)) {
obj = getAudioVideoData(filePath, obj, true); obj = getAudioVideoData(filePath, obj, true);
}
} catch (JSONException e) {
Log.d(LOG_TAG, "Error: setting media file data object");
} }
return obj; return obj;
} }

View File

@ -88,50 +88,46 @@ public class CompassListener extends CordovaPlugin implements SensorEventListene
* @param args JSONArry of arguments for the plugin. * @param args JSONArry of arguments for the plugin.
* @param callbackS=Context The callback id used when calling back into JavaScript. * @param callbackS=Context The callback id used when calling back into JavaScript.
* @return True if the action was valid. * @return True if the action was valid.
* @throws JSONException
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try { if (action.equals("start")) {
if (action.equals("start")) { this.start();
this.start(); }
} else if (action.equals("stop")) {
else if (action.equals("stop")) { this.stop();
this.stop(); }
} else if (action.equals("getStatus")) {
else if (action.equals("getStatus")) { int i = this.getStatus();
int i = this.getStatus(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i)); }
} else if (action.equals("getHeading")) {
else if (action.equals("getHeading")) { // If not running, then this is an async call, so don't worry about waiting
// If not running, then this is an async call, so don't worry about waiting if (this.status != CompassListener.RUNNING) {
if (this.status != CompassListener.RUNNING) { int r = this.start();
int r = this.start(); if (r == CompassListener.ERROR_FAILED_TO_START) {
if (r == CompassListener.ERROR_FAILED_TO_START) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START)); return true;
return true;
}
// Set a timeout callback on the main thread.
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
public void run() {
CompassListener.this.timeout();
}
}, 2000);
} }
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getCompassHeading())); // Set a timeout callback on the main thread.
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
public void run() {
CompassListener.this.timeout();
}
}, 2000);
} }
else if (action.equals("setTimeout")) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getCompassHeading()));
this.setTimeout(args.getLong(0)); }
} else if (action.equals("setTimeout")) {
else if (action.equals("getTimeout")) { this.setTimeout(args.getLong(0));
long l = this.getTimeout(); }
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l)); else if (action.equals("getTimeout")) {
} else { long l = this.getTimeout();
// Unsupported action callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l));
return false; } else {
} // Unsupported action
} catch (JSONException e) { return false;
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
return true; return true;
} }
@ -281,19 +277,15 @@ public class CompassListener extends CordovaPlugin implements SensorEventListene
* *
* @return a compass heading * @return a compass heading
*/ */
private JSONObject getCompassHeading() { private JSONObject getCompassHeading() throws JSONException {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
try { obj.put("magneticHeading", this.getHeading());
obj.put("magneticHeading", this.getHeading()); obj.put("trueHeading", this.getHeading());
obj.put("trueHeading", this.getHeading()); // Since the magnetic and true heading are always the same our and accuracy
// Since the magnetic and true heading are always the same our and accuracy // is defined as the difference between true and magnetic always return zero
// is defined as the difference between true and magnetic always return zero obj.put("headingAccuracy", 0);
obj.put("headingAccuracy", 0); obj.put("timestamp", this.timeStamp);
obj.put("timestamp", this.timeStamp);
} catch (JSONException e) {
// Should never happen
}
return obj; return obj;
} }

View File

@ -53,7 +53,7 @@ public class ContactManager extends CordovaPlugin {
* @param callbackContext The callback context used when calling back into JavaScript. * @param callbackContext The callback context used when calling back into JavaScript.
* @return True if the action was valid, false otherwise. * @return True if the action was valid, false otherwise.
*/ */
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
/** /**
* Check to see if we are on an Android 1.X device. If we are return an error as we * Check to see if we are on an Android 1.X device. If we are return an error as we
* do not support this as of Cordova 1.0. * do not support this as of Cordova 1.0.
@ -71,56 +71,51 @@ public class ContactManager extends CordovaPlugin {
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.cordova); this.contactAccessor = new ContactAccessorSdk5(this.webView, this.cordova);
} }
try { if (action.equals("search")) {
if (action.equals("search")) { final JSONArray filter = args.getJSONArray(0);
final JSONArray filter = args.getJSONArray(0); final JSONObject options = args.getJSONObject(1);
final JSONObject options = args.getJSONObject(1); this.cordova.getThreadPool().execute(new Runnable() {
this.cordova.getThreadPool().execute(new Runnable() { public void run() {
public void run() { JSONArray res = contactAccessor.search(filter, options);
JSONArray res = contactAccessor.search(filter, options); callbackContext.success(res);
}
});
}
else if (action.equals("save")) {
final JSONObject contact = args.getJSONObject(0);
this.cordova.getThreadPool().execute(new Runnable() {
public void run() {
JSONObject res = null;
String id = contactAccessor.save(contact);
if (id != null) {
try {
res = contactAccessor.getContactById(id);
} catch (JSONException e) {
Log.e(LOG_TAG, "JSON fail.", e);
}
}
if (res != null) {
callbackContext.success(res); callbackContext.success(res);
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
} }
}); }
} });
else if (action.equals("save")) { }
final JSONObject contact = args.getJSONObject(0); else if (action.equals("remove")) {
this.cordova.getThreadPool().execute(new Runnable() { final String contactId = args.getString(0);
public void run() { this.cordova.getThreadPool().execute(new Runnable() {
JSONObject res = null; public void run() {
String id = contactAccessor.save(contact); if (contactAccessor.remove(contactId)) {
if (id != null) { callbackContext.success();
try { } else {
res = contactAccessor.getContactById(id); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
} catch (JSONException e) {
Log.e(LOG_TAG, "JSON fail.", e);
}
}
if (res != null) {
callbackContext.success(res);
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
}
} }
}); }
} });
else if (action.equals("remove")) { }
final String contactId = args.getString(0); else {
this.cordova.getThreadPool().execute(new Runnable() { return false;
public void run() {
if (contactAccessor.remove(contactId)) {
callbackContext.success();
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
}
}
});
}
else {
return false;
}
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
return true; return true;
} }

View File

@ -72,25 +72,21 @@ public class Device extends CordovaPlugin {
* @param callbackContext The callback id used when calling back into JavaScript. * @param callbackContext The callback id used when calling back into JavaScript.
* @return True if the action was valid, false if not. * @return True if the action was valid, false if not.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try { if (action.equals("getDeviceInfo")) {
if (action.equals("getDeviceInfo")) { JSONObject r = new JSONObject();
JSONObject r = new JSONObject(); r.put("uuid", Device.uuid);
r.put("uuid", Device.uuid); r.put("version", this.getOSVersion());
r.put("version", this.getOSVersion()); r.put("platform", Device.platform);
r.put("platform", Device.platform); r.put("name", this.getProductName());
r.put("name", this.getProductName()); r.put("cordova", Device.cordovaVersion);
r.put("cordova", Device.cordovaVersion); //JSONObject pg = new JSONObject();
//JSONObject pg = new JSONObject(); //pg.put("version", Device.CordovaVersion);
//pg.put("version", Device.CordovaVersion); //r.put("cordova", pg);
//r.put("cordova", pg); callbackContext.success(r);
callbackContext.success(r); }
} else {
else { return false;
return false;
}
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
return true; return true;
} }

View File

@ -92,7 +92,7 @@ public class FileUtils extends CordovaPlugin {
* @param callbackContext The callback context used when calling back into JavaScript. * @param callbackContext The callback context used when calling back into JavaScript.
* @return True if the action was valid, false otherwise. * @return True if the action was valid, false otherwise.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try { try {
if (action.equals("testSaveLocationExists")) { if (action.equals("testSaveLocationExists")) {
boolean b = DirectoryManager.testSaveLocationExists(); boolean b = DirectoryManager.testSaveLocationExists();
@ -199,8 +199,6 @@ public class FileUtils extends CordovaPlugin {
callbackContext.error(FileUtils.PATH_EXISTS_ERR); callbackContext.error(FileUtils.PATH_EXISTS_ERR);
} catch (NoModificationAllowedException e) { } catch (NoModificationAllowedException e) {
callbackContext.error(FileUtils.NO_MODIFICATION_ALLOWED_ERR); callbackContext.error(FileUtils.NO_MODIFICATION_ALLOWED_ERR);
} catch (JSONException e) {
callbackContext.error(FileUtils.NO_MODIFICATION_ALLOWED_ERR);
} catch (InvalidModificationException e) { } catch (InvalidModificationException e) {
callbackContext.error(FileUtils.INVALID_MODIFICATION_ERR); callbackContext.error(FileUtils.INVALID_MODIFICATION_ERR);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {

View File

@ -54,7 +54,7 @@ public class GeoBroker extends CordovaPlugin {
* @param callbackContext The callback id used when calling back into JavaScript. * @param callbackContext The callback id used when calling back into JavaScript.
* @return True if the action was valid, or false if not. * @return True if the action was valid, or false if not.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (this.locationManager == null) { if (this.locationManager == null) {
this.locationManager = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE); this.locationManager = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
this.networkListener = new NetworkListener(this.locationManager, this); this.networkListener = new NetworkListener(this.locationManager, this);
@ -70,32 +70,28 @@ public class GeoBroker extends CordovaPlugin {
result.setKeepCallback(true); result.setKeepCallback(true);
try { if (action.equals("getLocation")) {
if (action.equals("getLocation")) { boolean enableHighAccuracy = args.getBoolean(0);
boolean enableHighAccuracy = args.getBoolean(0); int maximumAge = args.getInt(1);
int maximumAge = args.getInt(1); Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER));
Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER)); // Check if we can use lastKnownLocation to get a quick reading and use less battery
// Check if we can use lastKnownLocation to get a quick reading and use less battery if (last != null && (System.currentTimeMillis() - last.getTime()) <= maximumAge) {
if (last != null && (System.currentTimeMillis() - last.getTime()) <= maximumAge) { result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last));
result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last)); } else {
} else { this.getCurrentLocation(callbackContext, enableHighAccuracy);
this.getCurrentLocation(callbackContext, enableHighAccuracy);
}
} }
else if (action.equals("addWatch")) { }
String id = args.getString(0); else if (action.equals("addWatch")) {
boolean enableHighAccuracy = args.getBoolean(1); String id = args.getString(0);
this.addWatch(id, callbackContext, enableHighAccuracy); boolean enableHighAccuracy = args.getBoolean(1);
} this.addWatch(id, callbackContext, enableHighAccuracy);
else if (action.equals("clearWatch")) { }
String id = args.getString(0); else if (action.equals("clearWatch")) {
this.clearWatch(id); String id = args.getString(0);
} this.clearWatch(id);
else { }
return false; else {
} return false;
} catch (JSONException e) {
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
} }
} }
callbackContext.sendPluginResult(result); callbackContext.sendPluginResult(result);

View File

@ -56,46 +56,42 @@ public class Notification extends CordovaPlugin {
* @param callbackContext The callback context used when calling back into JavaScript. * @param callbackContext The callback context used when calling back into JavaScript.
* @return True when the action was valid, false otherwise. * @return True when the action was valid, false otherwise.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try { if (action.equals("beep")) {
if (action.equals("beep")) { this.beep(args.getLong(0));
this.beep(args.getLong(0));
}
else if (action.equals("vibrate")) {
this.vibrate(args.getLong(0));
}
else if (action.equals("alert")) {
this.alert(args.getString(0), args.getString(1), args.getString(2), callbackContext);
return true;
}
else if (action.equals("confirm")) {
this.confirm(args.getString(0), args.getString(1), args.getString(2), callbackContext);
return true;
}
else if (action.equals("activityStart")) {
this.activityStart(args.getString(0), args.getString(1));
}
else if (action.equals("activityStop")) {
this.activityStop();
}
else if (action.equals("progressStart")) {
this.progressStart(args.getString(0), args.getString(1));
}
else if (action.equals("progressValue")) {
this.progressValue(args.getInt(0));
}
else if (action.equals("progressStop")) {
this.progressStop();
}
else {
return false;
}
// Only alert and confirm are async.
callbackContext.success();
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
else if (action.equals("vibrate")) {
this.vibrate(args.getLong(0));
}
else if (action.equals("alert")) {
this.alert(args.getString(0), args.getString(1), args.getString(2), callbackContext);
return true;
}
else if (action.equals("confirm")) {
this.confirm(args.getString(0), args.getString(1), args.getString(2), callbackContext);
return true;
}
else if (action.equals("activityStart")) {
this.activityStart(args.getString(0), args.getString(1));
}
else if (action.equals("activityStop")) {
this.activityStop();
}
else if (action.equals("progressStart")) {
this.progressStart(args.getString(0), args.getString(1));
}
else if (action.equals("progressValue")) {
this.progressValue(args.getInt(0));
}
else if (action.equals("progressStop")) {
this.progressStop();
}
else {
return false;
}
// Only alert and confirm are async.
callbackContext.success();
return true; return true;
} }

View File

@ -65,32 +65,28 @@ public class Storage extends CordovaPlugin {
* The callback context used when calling back into JavaScript. * The callback context used when calling back into JavaScript.
* @return True if the action was valid, false otherwise. * @return True if the action was valid, false otherwise.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try { if (action.equals("openDatabase")) {
if (action.equals("openDatabase")) { this.openDatabase(args.getString(0), args.getString(1),
this.openDatabase(args.getString(0), args.getString(1), args.getString(2), args.getLong(3));
args.getString(2), args.getLong(3)); } else if (action.equals("executeSql")) {
} else if (action.equals("executeSql")) { String[] s = null;
String[] s = null; if (args.isNull(1)) {
if (args.isNull(1)) { s = new String[0];
s = new String[0]; } else {
} else { JSONArray a = args.getJSONArray(1);
JSONArray a = args.getJSONArray(1); int len = a.length();
int len = a.length(); s = new String[len];
s = new String[len]; for (int i = 0; i < len; i++) {
for (int i = 0; i < len; i++) { s[i] = a.getString(i);
s[i] = a.getString(i);
}
} }
this.executeSql(args.getString(0), s, args.getString(2));
} }
else { this.executeSql(args.getString(0), s, args.getString(2));
return false;
}
callbackContext.success();
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
else {
return false;
}
callbackContext.success();
return true; return true;
} }