mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-04-22 11:03:27 +08:00
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:
parent
c7d88e8b34
commit
d899d7a4b8
@ -95,6 +95,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
|
|
||||||
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
|
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 scanMe; // Uri of image to be added to content store
|
||||||
|
private Uri croppedUri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* 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) {
|
public void getImage(int srcType, int returnType, int encodingType) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
String title = GET_PICTURE;
|
String title = GET_PICTURE;
|
||||||
|
croppedUri = null;
|
||||||
if (this.mediaType == PICTURE) {
|
if (this.mediaType == PICTURE) {
|
||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
if (this.allowEdit) {
|
if (this.allowEdit) {
|
||||||
intent.setAction(Intent.ACTION_PICK);
|
intent.setAction(Intent.ACTION_PICK);
|
||||||
intent.putExtra("crop", "true");
|
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("aspectX", 1);
|
||||||
intent.putExtra("aspectY", 1);
|
intent.putExtra("aspectY", 1);
|
||||||
}
|
}
|
||||||
intent.putExtra("outputX", this.targetWidth);
|
|
||||||
intent.putExtra("outputY", this.targetHeight);
|
|
||||||
File photo = createCaptureFile(encodingType);
|
File photo = createCaptureFile(encodingType);
|
||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
|
croppedUri = Uri.fromFile(photo);
|
||||||
Uri.fromFile(photo));
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
|
||||||
} else {
|
} else {
|
||||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
@ -297,13 +303,17 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
cropIntent.setDataAndType(picUri, "image/*");
|
cropIntent.setDataAndType(picUri, "image/*");
|
||||||
// set crop properties
|
// set crop properties
|
||||||
cropIntent.putExtra("crop", "true");
|
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("aspectX", 1);
|
||||||
cropIntent.putExtra("aspectY", 1);
|
cropIntent.putExtra("aspectY", 1);
|
||||||
}
|
}
|
||||||
// indicate output X and Y
|
|
||||||
cropIntent.putExtra("outputX", this.targetWidth);
|
|
||||||
cropIntent.putExtra("outputY", this.targetHeight);
|
|
||||||
// retrieve data on return
|
// retrieve data on return
|
||||||
cropIntent.putExtra("return-data", true);
|
cropIntent.putExtra("return-data", true);
|
||||||
// start the activity - we handle returning in onActivityResult
|
// 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) {
|
private void processResultFromGallery(int destType, Intent intent) {
|
||||||
Uri uri = intent.getData();
|
Uri uri = intent.getData();
|
||||||
|
if (uri == null) {
|
||||||
|
if (croppedUri != null) {
|
||||||
|
uri = croppedUri;
|
||||||
|
} else {
|
||||||
|
this.failPicture("null data from photo library");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
int rotate = 0;
|
int rotate = 0;
|
||||||
|
|
||||||
// If you ask for video or all media type you will automatically get back a file URI
|
// 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();
|
Bundle extras = intent.getExtras();
|
||||||
// get the cropped bitmap
|
// get the cropped bitmap
|
||||||
Bitmap thePic = extras.getParcelable("data");
|
Bitmap thePic = extras.getParcelable("data");
|
||||||
|
if (thePic == null) {
|
||||||
|
this.failPicture("Crop returned no data.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// now save the bitmap to a file
|
// now save the bitmap to a file
|
||||||
OutputStream fOut = null;
|
OutputStream fOut = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user