mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Modify camera to use NO_RESULT, thus eliminating extra JS callback methods.
This commit is contained in:
parent
37a9307681
commit
831670e4ae
@ -70,8 +70,6 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
||||
return;
|
||||
}
|
||||
|
||||
this.successCallback = successCallback;
|
||||
this.errorCallback = errorCallback;
|
||||
this.options = options;
|
||||
var quality = 80;
|
||||
if (options.quality) {
|
||||
@ -85,40 +83,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
||||
if (typeof this.options.sourceType == "number") {
|
||||
sourceType = this.options.sourceType;
|
||||
}
|
||||
PhoneGap.exec(null, null, "Camera", "takePicture", [quality, destinationType, sourceType]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function from native code that is called when image has been captured.
|
||||
*
|
||||
* @param picture The base64 encoded string of the image
|
||||
*/
|
||||
Camera.prototype.success = function(picture) {
|
||||
if (this.successCallback) {
|
||||
try {
|
||||
this.successCallback(picture);
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Camera error calling user's success callback: " + e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function from native code that is called when there is an error
|
||||
* capturing an image, or the capture is cancelled.
|
||||
*
|
||||
* @param err The error message
|
||||
*/
|
||||
Camera.prototype.error = function(err) {
|
||||
if (this.errorCallback) {
|
||||
try {
|
||||
this.errorCallback(err);
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Camera error calling user's error callback: " + e);
|
||||
}
|
||||
}
|
||||
PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType]);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
|
@ -45,6 +45,7 @@ public class CameraLauncher extends Plugin {
|
||||
|
||||
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
|
||||
public String callbackId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -63,6 +64,7 @@ public class CameraLauncher extends Plugin {
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
this.callbackId = callbackId;
|
||||
|
||||
try {
|
||||
if (action.equals("takePicture")) {
|
||||
@ -80,6 +82,9 @@ public class CameraLauncher extends Plugin {
|
||||
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
||||
this.getImage(srcType, destType);
|
||||
}
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
@ -190,7 +195,7 @@ public class CameraLauncher extends Plugin {
|
||||
os.close();
|
||||
|
||||
// Send Uri back to JavaScript for viewing image
|
||||
this.sendJavascript("navigator.camera.success('" + uri.toString() + "');");
|
||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -227,7 +232,7 @@ public class CameraLauncher extends Plugin {
|
||||
|
||||
// If sending filename back
|
||||
else if (destType == FILE_URI) {
|
||||
this.sendJavascript("navigator.camera.success('" + uri + "');");
|
||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||
}
|
||||
}
|
||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
@ -251,7 +256,7 @@ public class CameraLauncher extends Plugin {
|
||||
byte[] code = jpeg_data.toByteArray();
|
||||
byte[] output = Base64.encodeBase64(code);
|
||||
String js_out = new String(output);
|
||||
this.sendJavascript("navigator.camera.success('" + js_out + "');");
|
||||
this.success(new PluginResult(PluginResult.Status.OK, js_out), this.callbackId);
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
@ -265,6 +270,6 @@ public class CameraLauncher extends Plugin {
|
||||
* @param err
|
||||
*/
|
||||
public void failPicture(String err) {
|
||||
this.sendJavascript("navigator.camera.error('" + err + "');");
|
||||
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user