CB-6546 android: Fix a couple bugs with allowEdit pull request

- Don't set width/height when they are not specified
- photolibrary returns null from getData when image is cropped
This commit is contained in:
Andrew Grieve 2014-04-29 00:51:09 -04:00
parent c7d88e8b34
commit d899d7a4b8

View File

@ -95,6 +95,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
private Uri scanMe; // Uri of image to be added to content store
private Uri croppedUri;
/**
* Executes the request and returns PluginResult.
@ -248,20 +249,25 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
public void getImage(int srcType, int returnType, int encodingType) {
Intent intent = new Intent();
String title = GET_PICTURE;
croppedUri = null;
if (this.mediaType == PICTURE) {
intent.setType("image/*");
if (this.allowEdit) {
intent.setAction(Intent.ACTION_PICK);
intent.putExtra("crop", "true");
if (this.targetHeight == this.targetWidth) {
if (targetWidth > 0) {
intent.putExtra("outputX", targetWidth);
}
if (targetHeight > 0) {
intent.putExtra("outputY", targetHeight);
}
if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
}
intent.putExtra("outputX", this.targetWidth);
intent.putExtra("outputY", this.targetHeight);
File photo = createCaptureFile(encodingType);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
croppedUri = Uri.fromFile(photo);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
} else {
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
@ -297,13 +303,17 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
if (this.targetHeight == this.targetWidth) {
// indicate output X and Y
if (targetWidth > 0) {
cropIntent.putExtra("outputX", targetWidth);
}
if (targetHeight > 0) {
cropIntent.putExtra("outputY", targetHeight);
}
if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
}
// indicate output X and Y
cropIntent.putExtra("outputX", this.targetWidth);
cropIntent.putExtra("outputY", this.targetHeight);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
@ -459,6 +469,14 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
*/
private void processResultFromGallery(int destType, Intent intent) {
Uri uri = intent.getData();
if (uri == null) {
if (croppedUri != null) {
uri = croppedUri;
} else {
this.failPicture("null data from photo library");
return;
}
}
int rotate = 0;
// If you ask for video or all media type you will automatically get back a file URI
@ -561,6 +579,10 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
Bundle extras = intent.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
if (thePic == null) {
this.failPicture("Crop returned no data.");
return;
}
// now save the bitmap to a file
OutputStream fOut = null;