Modify camera capture to use async plugin. Use option instead of method to specify capture type (base64 or file).

This commit is contained in:
Bryce Curtis 2010-09-10 14:45:32 -05:00
parent d72c77d6f3
commit 53fca124ab
2 changed files with 20 additions and 35 deletions

View File

@ -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. * This class provides access to the device camera.
@ -44,12 +34,15 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
this.successCallback = successCallback; this.successCallback = successCallback;
this.errorCallback = errorCallback; this.errorCallback = errorCallback;
this.options = options; this.options = options;
var capturetype = "base64";
var quality = 80;
if (this.options.capturetype) {
capturetype = this.options.capturetype;
}
if (options.quality) { if (options.quality) {
com.phonegap.CameraLauncher.takePicture(options.quality); quality = this.options.quality;
}
else {
com.phonegap.CameraLauncher.takePicture(80);
} }
PhoneGap.execAsync(null, null, "Camera", "takePicture", [quality, capturetype]);
}; };
/** /**

View File

@ -10,12 +10,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.app.Activity; import android.app.Activity;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.CompressFormat;
@ -75,11 +73,8 @@ public class CameraLauncher implements Plugin {
String result = ""; String result = "";
try { try {
if (action.equals("setBase64")) { if (action.equals("takePicture")) {
this.setBase64(args.getBoolean(0)); this.takePicture(args.getInt(0), args.getString(1));
}
else if (action.equals("takePicture")) {
this.takePicture(args.getInt(0));
} }
return new PluginResult(status, result); return new PluginResult(status, result);
} catch (JSONException e) { } 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 * Take a picture with the camera.
* as a base64 string or a URI that points to the file. * 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: * To display base64 string in an img tag, set the source to:
* img.src="data:image/jpeg;base64,"+result; * img.src="data:image/jpeg;base64,"+result;
* or to display URI in an img tag * or to display URI in an img tag
* img.src=result; * 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 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.mQuality = quality;
this.base64 = false;
if (returnType.equals("base64")) {
this.base64 = true;
}
// Display camera // Display camera
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");