From 4b36dbacecf3bec45cf3e188e4b74cb9a5098e92 Mon Sep 17 00:00:00 2001 From: Matt Oakes Date: Mon, 16 Dec 2019 12:54:44 +0000 Subject: [PATCH] Send the angle back when cropping an image --- ucrop/src/main/java/com/yalantis/ucrop/UCrop.java | 1 + ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java | 7 ++++--- ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java | 7 ++++--- .../com/yalantis/ucrop/callback/BitmapCropCallback.java | 2 +- .../main/java/com/yalantis/ucrop/task/BitmapCropTask.java | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java index 357ace2d9..addbbeff5 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java @@ -44,6 +44,7 @@ public class UCrop { public static final String EXTRA_OUTPUT_IMAGE_HEIGHT = EXTRA_PREFIX + ".ImageHeight"; public static final String EXTRA_OUTPUT_OFFSET_X = EXTRA_PREFIX + ".OffsetX"; public static final String EXTRA_OUTPUT_OFFSET_Y = EXTRA_PREFIX + ".OffsetY"; + public static final String EXTRA_OUTPUT_ANGLE = EXTRA_PREFIX + ".Angle"; public static final String EXTRA_ERROR = EXTRA_PREFIX + ".Error"; public static final String EXTRA_ASPECT_RATIO_X = EXTRA_PREFIX + ".AspectRatioX"; diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java index a48969fcc..3a318854a 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java @@ -645,8 +645,8 @@ protected void cropAndSaveImage() { mGestureCropImageView.cropAndSaveImage(mCompressFormat, mCompressQuality, new BitmapCropCallback() { @Override - public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight) { - setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight); + public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight, float angle) { + setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight, angle); finish(); } @@ -658,7 +658,7 @@ public void onCropFailure(@NonNull Throwable t) { }); } - protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight) { + protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight, float angle) { setResult(RESULT_OK, new Intent() .putExtra(UCrop.EXTRA_OUTPUT_URI, uri) .putExtra(UCrop.EXTRA_OUTPUT_CROP_ASPECT_RATIO, resultAspectRatio) @@ -666,6 +666,7 @@ protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int o .putExtra(UCrop.EXTRA_OUTPUT_IMAGE_HEIGHT, imageHeight) .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_X, offsetX) .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_Y, offsetY) + .putExtra(UCrop.EXTRA_OUTPUT_ANGLE, angle) ); } diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java index 9d33f8089..90e36352f 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java @@ -527,8 +527,8 @@ public void cropAndSaveImage() { mGestureCropImageView.cropAndSaveImage(mCompressFormat, mCompressQuality, new BitmapCropCallback() { @Override - public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight) { - callback.onCropFinish(getResult(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight)); + public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight, float angle) { + callback.onCropFinish(getResult(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight, angle)); callback.loadingProgress(false); } @@ -539,7 +539,7 @@ public void onCropFailure(@NonNull Throwable t) { }); } - protected UCropResult getResult(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight) { + protected UCropResult getResult(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight, float angle) { return new UCropResult(RESULT_OK, new Intent() .putExtra(UCrop.EXTRA_OUTPUT_URI, uri) .putExtra(UCrop.EXTRA_OUTPUT_CROP_ASPECT_RATIO, resultAspectRatio) @@ -547,6 +547,7 @@ protected UCropResult getResult(Uri uri, float resultAspectRatio, int offsetX, i .putExtra(UCrop.EXTRA_OUTPUT_IMAGE_HEIGHT, imageHeight) .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_X, offsetX) .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_Y, offsetY) + .putExtra(UCrop.EXTRA_OUTPUT_ANGLE, angle) ); } diff --git a/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java b/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java index c3a712767..a773e9003 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java @@ -6,7 +6,7 @@ public interface BitmapCropCallback { - void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight); + void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight, float angle); void onCropFailure(@NonNull Throwable t); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java index e779c28d3..67cb9293b 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java @@ -186,7 +186,7 @@ protected void onPostExecute(@Nullable Throwable t) { if (mCropCallback != null) { if (t == null) { Uri uri = Uri.fromFile(new File(mImageOutputPath)); - mCropCallback.onBitmapCropped(uri, cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight); + mCropCallback.onBitmapCropped(uri, cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight, mCurrentAngle); } else { mCropCallback.onCropFailure(t); }