From 53fca124ab76c6fec93e15736952b77aa80bdd86 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Fri, 10 Sep 2010 14:45:32 -0500 Subject: [PATCH] Modify camera capture to use async plugin. Use option instead of method to specify capture type (base64 or file). --- framework/assets/js/camera.js | 21 ++++-------- .../src/com/phonegap/CameraLauncher.java | 34 +++++++------------ 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/framework/assets/js/camera.js b/framework/assets/js/camera.js index ba3668ac..4b42470f 100644 --- a/framework/assets/js/camera.js +++ b/framework/assets/js/camera.js @@ -1,13 +1,3 @@ -com.phonegap.CameraLauncherProxy = function() { - this.className = "com.phonegap.CameraLauncher"; -}; -com.phonegap.CameraLauncherProxy.prototype.setBase64 = function(b) { - return PhoneGap.exec(this.className, "setBase64", [b]); -}; -com.phonegap.CameraLauncherProxy.prototype.takePicture = function(quality) { - return PhoneGap.exec(this.className, "takePicture", [quality]); -}; -com.phonegap.CameraLauncher = new com.phonegap.CameraLauncherProxy(); /** * This class provides access to the device camera. @@ -44,12 +34,15 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) this.successCallback = successCallback; this.errorCallback = errorCallback; this.options = options; + var capturetype = "base64"; + var quality = 80; + if (this.options.capturetype) { + capturetype = this.options.capturetype; + } if (options.quality) { - com.phonegap.CameraLauncher.takePicture(options.quality); - } - else { - com.phonegap.CameraLauncher.takePicture(80); + quality = this.options.quality; } + PhoneGap.execAsync(null, null, "Camera", "takePicture", [quality, capturetype]); }; /** diff --git a/framework/src/com/phonegap/CameraLauncher.java b/framework/src/com/phonegap/CameraLauncher.java index 8e31b010..b22f6e07 100755 --- a/framework/src/com/phonegap/CameraLauncher.java +++ b/framework/src/com/phonegap/CameraLauncher.java @@ -10,12 +10,10 @@ import org.json.JSONArray; import org.json.JSONException; import com.phonegap.api.Plugin; -import com.phonegap.api.PluginManager; import com.phonegap.api.PluginResult; import android.app.Activity; import android.content.ContentValues; -import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; @@ -75,11 +73,8 @@ public class CameraLauncher implements Plugin { String result = ""; try { - if (action.equals("setBase64")) { - this.setBase64(args.getBoolean(0)); - } - else if (action.equals("takePicture")) { - this.takePicture(args.getInt(0)); + if (action.equals("takePicture")) { + this.takePicture(args.getInt(0), args.getString(1)); } return new PluginResult(status, result); } catch (JSONException e) { @@ -122,28 +117,25 @@ public class CameraLauncher implements Plugin { //-------------------------------------------------------------------------- /** - * Set the type of data to return. The data can either be returned - * as a base64 string or a URI that points to the file. + * Take a picture with the camera. + * When an image is captured or the camera view is cancelled, the result is returned + * in DroidGap.onActivityResult, which forwards the result to this.onActivityResult. + * + * The image can either be returned as a base64 string or a URI that points to the file. * To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; * or to display URI in an img tag * img.src=result; * - * @param b T=return base64 string (default), F=return URI - */ - public void setBase64(boolean b) { - this.base64 = b; - } - - /** - * Take a picture with the camera. - * When an image is captured or the camera view is cancelled, the result is returned - * in DroidGap.onActivityResult, which forwards the result to this.onActivityResult. - * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) + * @param returnType Set the type of image to return. */ - public void takePicture(int quality) { + public void takePicture(int quality, String returnType) { this.mQuality = quality; + this.base64 = false; + if (returnType.equals("base64")) { + this.base64 = true; + } // Display camera Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");