Skip to content

Commit

Permalink
Merge pull request #287 from Yalantis/offsets_non_native
Browse files Browse the repository at this point in the history
Offsets by X and Y were passed through result intent
  • Loading branch information
Cool04ek authored Apr 19, 2017
2 parents 2bfb255 + b197526 commit 8a4e70e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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')
}
8 changes: 4 additions & 4 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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'
}
2 changes: 2 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 5 additions & 3 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class BitmapCropTask extends AsyncTask<Void, Void, Throwable> {
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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8a4e70e

Please sign in to comment.