From b197526b0df80a0f086c5ac94485b35d09d4eb02 Mon Sep 17 00:00:00 2001 From: Dmitriy Dovbnya Date: Wed, 19 Apr 2017 14:36:34 +0300 Subject: [PATCH] offsets by X and Y were passed through result intent --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 8 ++++---- ucrop/build.gradle | 8 ++++---- ucrop/src/main/java/com/yalantis/ucrop/UCrop.java | 2 ++ .../main/java/com/yalantis/ucrop/UCropActivity.java | 8 +++++--- .../yalantis/ucrop/callback/BitmapCropCallback.java | 2 +- .../java/com/yalantis/ucrop/task/BitmapCropTask.java | 10 ++++++---- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 4f31b868b..09d666277 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:2.3.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fc482eb61..8f22dfc25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Sep 08 12:21:35 EEST 2016 +#Wed Apr 19 14:09:28 EEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 2b8a86753..61e764b5b 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 25 + buildToolsVersion "25.0.2" defaultConfig { applicationId "com.yalantis.ucrop.sample" minSdkVersion 14 - targetSdkVersion 24 + targetSdkVersion 25 versionCode 10 versionName "1.2.2" } @@ -28,7 +28,7 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:appcompat-v7:25.3.1' compile project (':ucrop') } \ No newline at end of file diff --git a/ucrop/build.gradle b/ucrop/build.gradle index e706f352c..46fced490 100644 --- a/ucrop/build.gradle +++ b/ucrop/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.library' apply from: '../mavenpush.gradle' android { - compileSdkVersion 24 - buildToolsVersion '24.0.2' + compileSdkVersion 25 + buildToolsVersion '25.0.2' defaultConfig { minSdkVersion 14 - targetSdkVersion 24 + targetSdkVersion 25 versionCode 22 versionName "2.2.0-native" @@ -32,6 +32,6 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.squareup.okhttp3:okhttp:3.4.1' } diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java index 847bf98ed..bd1e3ded4 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java @@ -39,6 +39,8 @@ public class UCrop { public static final String EXTRA_OUTPUT_CROP_ASPECT_RATIO = EXTRA_PREFIX + ".CropAspectRatio"; public static final String EXTRA_OUTPUT_IMAGE_WIDTH = EXTRA_PREFIX + ".ImageWidth"; 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_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 067c33aad..d842f48a2 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java @@ -604,8 +604,8 @@ protected void cropAndSaveImage() { mGestureCropImageView.cropAndSaveImage(mCompressFormat, mCompressQuality, new BitmapCropCallback() { @Override - public void onBitmapCropped(@NonNull Uri resultUri, int imageWidth, int imageHeight) { - setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), imageWidth, imageHeight); + public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight) { + setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight); finish(); } @@ -617,12 +617,14 @@ public void onCropFailure(@NonNull Throwable t) { }); } - protected void setResultUri(Uri uri, float resultAspectRatio, int imageWidth, int imageHeight) { + protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight) { setResult(RESULT_OK, new Intent() .putExtra(UCrop.EXTRA_OUTPUT_URI, uri) .putExtra(UCrop.EXTRA_OUTPUT_CROP_ASPECT_RATIO, resultAspectRatio) .putExtra(UCrop.EXTRA_OUTPUT_IMAGE_WIDTH, imageWidth) .putExtra(UCrop.EXTRA_OUTPUT_IMAGE_HEIGHT, imageHeight) + .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_X, offsetX) + .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_Y, offsetY) ); } 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 3e4b23a6c..afe82e43d 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java @@ -5,7 +5,7 @@ public interface BitmapCropCallback { - void onBitmapCropped(@NonNull Uri resultUri, int imageWidth, int imageHeight); + void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight); 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 9ad68035d..bfe484f1f 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java @@ -53,6 +53,7 @@ public class BitmapCropTask extends AsyncTask { private final BitmapCropCallback mCropCallback; private int mCroppedImageWidth, mCroppedImageHeight; + private int cropOffsetX, cropOffsetY; public BitmapCropTask(@NonNull Context context, @Nullable Bitmap viewBitmap, @NonNull ImageState imageState, @NonNull CropParameters cropParameters, @Nullable BitmapCropCallback cropCallback) { @@ -138,8 +139,8 @@ private boolean crop() throws IOException { mViewBitmap = rotatedBitmap; } - int top = Math.round((mCropRect.top - mCurrentImageRect.top) / mCurrentScale); - int left = Math.round((mCropRect.left - mCurrentImageRect.left) / mCurrentScale); + cropOffsetX = Math.round((mCropRect.left - mCurrentImageRect.left) / mCurrentScale); + cropOffsetY = Math.round((mCropRect.top - mCurrentImageRect.top) / mCurrentScale); mCroppedImageWidth = Math.round(mCropRect.width() / mCurrentScale); mCroppedImageHeight = Math.round(mCropRect.height() / mCurrentScale); @@ -148,7 +149,7 @@ private boolean crop() throws IOException { if (shouldCrop) { ExifInterface originalExif = new ExifInterface(mImageInputPath); - saveImage(Bitmap.createBitmap(mViewBitmap, left, top, mCroppedImageWidth, mCroppedImageHeight)); + saveImage(Bitmap.createBitmap(mViewBitmap, cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight)); if (mCompressFormat.equals(Bitmap.CompressFormat.JPEG)) { ImageHeaderParser.copyExif(originalExif, mCroppedImageWidth, mCroppedImageHeight, mImageOutputPath); } @@ -197,7 +198,8 @@ private boolean shouldCrop(int width, int height) { protected void onPostExecute(@Nullable Throwable t) { if (mCropCallback != null) { if (t == null) { - mCropCallback.onBitmapCropped(Uri.fromFile(new File(mImageOutputPath)), mCroppedImageWidth, mCroppedImageHeight); + Uri uri = Uri.fromFile(new File(mImageOutputPath)); + mCropCallback.onBitmapCropped(uri, cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight); } else { mCropCallback.onCropFailure(t); }