Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop native up version to 2.2.4 #566

Merged
merged 33 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
09573d7
Removed native part.
shliama Sep 8, 2016
dbd6321
Merge branch 'master' into feature/non_native
shliama Sep 8, 2016
2bfb255
Merge branch 'master' into feature/non_native
shliama Sep 8, 2016
b197526
offsets by X and Y were passed through result intent
Apr 19, 2017
8a4e70e
Merge pull request #287 from Yalantis/offsets_non_native
Cool04ek Apr 19, 2017
88d7f8f
Merge branch 'round_cut' into feature/non_native
Legementarion Mar 29, 2018
5444c55
ucrop attach callback + some fix
Legementarion Apr 5, 2018
dc1f5ae
log fix
Legementarion Apr 5, 2018
5c42879
Merge pull request #396 from Legementarion/feature/non_native
PenzK Apr 5, 2018
b9565d7
versions
Legementarion Apr 5, 2018
ee18cf1
Merge pull request #403 from Legementarion/feature/non_native
PenzK Apr 5, 2018
065ae11
Update README.md
PenzK Apr 9, 2018
9ed7790
Add support exifinterface lib
LithiumSheep Apr 18, 2018
4c212f9
Use support ExifInterface
LithiumSheep Apr 18, 2018
c3df5cd
Update deprecated tag
LithiumSheep Apr 18, 2018
b9055ce
Optimize imports
LithiumSheep Apr 18, 2018
bc8a5be
Merge pull request #411 from lolsheeplol/support-exifinterface-non-na…
Legementarion Apr 18, 2018
9cf77f5
Updated dependencies and migration to androidx
Mar 18, 2019
5721b43
Updated dependencies and migration to androidx
Mar 18, 2019
b05cee9
Updated dependencies and migration to androidx
Mar 18, 2019
08e7c4a
Updated gradle version
OleksandNekrasov Sep 6, 2019
f7929c0
Updated androidX dependencies versions
OleksandNekrasov Sep 6, 2019
8f58da6
Updated version code
OleksandNekrasov Sep 6, 2019
60c405f
Merge branch 'develop' into feature/develop_to_androidx
ukevgen Sep 6, 2019
f4d0d7c
Merge pull request #494 from Yalantis/feature/develop_to_androidx
ukevgen Sep 6, 2019
e4c30d9
Fixed androidx transition dependencies
OleksandNekrasov Sep 9, 2019
f808347
Applied new color schema to uCrop controls
OleksandNekrasov Sep 10, 2019
24adeff
Added ripple effect to rotate controls
OleksandNekrasov Sep 11, 2019
81b881f
Apply UI improvements
OleksandNekrasov Sep 11, 2019
52bf6ce
Merge pull request #561 from Yalantis/fix/native_fix_androidx_transition
ukevgen Sep 12, 2019
0824cfc
Execute AsyncTask in a parallel manner
OleksandNekrasov Sep 12, 2019
aae1263
Merge pull request #563 from Yalantis/feature/native_asynctask_in_par…
ukevgen Sep 13, 2019
f876977
up version to 2.2.4
Sep 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Removed native part.
  • Loading branch information
shliama committed Sep 8, 2016
commit 09573d72b51c44daff3dceefa048c627c69c951c
4 changes: 0 additions & 4 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ android {

resourcePrefix 'ucrop_'

sourceSets.main {
jni.srcDirs = [];
}

}

dependencies {
Expand Down
97 changes: 56 additions & 41 deletions ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.yalantis.ucrop.task;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.media.ExifInterface;
import android.net.Uri;
Expand All @@ -14,11 +15,15 @@
import com.yalantis.ucrop.model.CropParameters;
import com.yalantis.ucrop.model.ExifInfo;
import com.yalantis.ucrop.model.ImageState;
import com.yalantis.ucrop.util.BitmapLoadUtils;
import com.yalantis.ucrop.util.FileUtils;
import com.yalantis.ucrop.util.ImageHeaderParser;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.ref.WeakReference;

/**
* Crops part of image that fills the crop bounds.
Expand All @@ -31,9 +36,7 @@ public class BitmapCropTask extends AsyncTask<Void, Void, Throwable> {

private static final String TAG = "BitmapCropTask";

static {
System.loadLibrary("ucrop");
}
private final WeakReference<Context> mContext;

private Bitmap mViewBitmap;

Expand All @@ -51,9 +54,11 @@ public class BitmapCropTask extends AsyncTask<Void, Void, Throwable> {

private int mCroppedImageWidth, mCroppedImageHeight;

public BitmapCropTask(@Nullable Bitmap viewBitmap, @NonNull ImageState imageState, @NonNull CropParameters cropParameters,
public BitmapCropTask(@NonNull Context context, @Nullable Bitmap viewBitmap, @NonNull ImageState imageState, @NonNull CropParameters cropParameters,
@Nullable BitmapCropCallback cropCallback) {

mContext = new WeakReference<>(context);

mViewBitmap = viewBitmap;
mCropRect = imageState.getCropRect();
mCurrentImageRect = imageState.getCurrentImageRect();
Expand Down Expand Up @@ -84,10 +89,9 @@ protected Throwable doInBackground(Void... params) {
return new NullPointerException("CurrentImageRect is empty");
}

float resizeScale = resize();

try {
crop(resizeScale);
crop();
mViewBitmap = null;
} catch (Throwable throwable) {
return throwable;
Expand All @@ -96,38 +100,43 @@ protected Throwable doInBackground(Void... params) {
return null;
}

private float resize() {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mImageInputPath, options);

boolean swapSides = mExifInfo.getExifDegrees() == 90 || mExifInfo.getExifDegrees() == 270;
float scaleX = (swapSides ? options.outHeight : options.outWidth) / (float) mViewBitmap.getWidth();
float scaleY = (swapSides ? options.outWidth : options.outHeight) / (float) mViewBitmap.getHeight();

float resizeScale = Math.min(scaleX, scaleY);

mCurrentScale /= resizeScale;

resizeScale = 1;
private boolean crop() throws IOException {
// Downsize if needed
if (mMaxResultImageSizeX > 0 && mMaxResultImageSizeY > 0) {
float cropWidth = mCropRect.width() / mCurrentScale;
float cropHeight = mCropRect.height() / mCurrentScale;

if (cropWidth > mMaxResultImageSizeX || cropHeight > mMaxResultImageSizeY) {

scaleX = mMaxResultImageSizeX / cropWidth;
scaleY = mMaxResultImageSizeY / cropHeight;
resizeScale = Math.min(scaleX, scaleY);
float scaleX = mMaxResultImageSizeX / cropWidth;
float scaleY = mMaxResultImageSizeY / cropHeight;
float resizeScale = Math.min(scaleX, scaleY);

Bitmap resizedBitmap = Bitmap.createScaledBitmap(mViewBitmap,
Math.round(mViewBitmap.getWidth() * resizeScale),
Math.round(mViewBitmap.getHeight() * resizeScale), false);
if (mViewBitmap != resizedBitmap) {
mViewBitmap.recycle();
}
mViewBitmap = resizedBitmap;

mCurrentScale /= resizeScale;
}
}
return resizeScale;
}

private boolean crop(float resizeScale) throws IOException {
ExifInterface originalExif = new ExifInterface(mImageInputPath);
// Rotate if needed
if (mCurrentAngle != 0) {
Matrix tempMatrix = new Matrix();
tempMatrix.setRotate(mCurrentAngle, mViewBitmap.getWidth() / 2, mViewBitmap.getHeight() / 2);

Bitmap rotatedBitmap = Bitmap.createBitmap(mViewBitmap, 0, 0, mViewBitmap.getWidth(), mViewBitmap.getHeight(),
tempMatrix, true);
if (mViewBitmap != rotatedBitmap) {
mViewBitmap.recycle();
}
mViewBitmap = rotatedBitmap;
}

int top = Math.round((mCropRect.top - mCurrentImageRect.top) / mCurrentScale);
int left = Math.round((mCropRect.left - mCurrentImageRect.left) / mCurrentScale);
Expand All @@ -138,20 +147,34 @@ private boolean crop(float resizeScale) throws IOException {
Log.i(TAG, "Should crop: " + shouldCrop);

if (shouldCrop) {
boolean cropped = cropCImg(mImageInputPath, mImageOutputPath,
left, top, mCroppedImageWidth, mCroppedImageHeight, mCurrentAngle, resizeScale,
mCompressFormat.ordinal(), mCompressQuality,
mExifInfo.getExifDegrees(), mExifInfo.getExifTranslation());
if (cropped && mCompressFormat.equals(Bitmap.CompressFormat.JPEG)) {
ExifInterface originalExif = new ExifInterface(mImageInputPath);
saveImage(Bitmap.createBitmap(mViewBitmap, left, top, mCroppedImageWidth, mCroppedImageHeight));
if (mCompressFormat.equals(Bitmap.CompressFormat.JPEG)) {
ImageHeaderParser.copyExif(originalExif, mCroppedImageWidth, mCroppedImageHeight, mImageOutputPath);
}
return cropped;
return true;
} else {
FileUtils.copyFile(mImageInputPath, mImageOutputPath);
return false;
}
}

private void saveImage(@NonNull Bitmap croppedBitmap) throws FileNotFoundException {
Context context = mContext.get();
if (context == null) {
return;
}

OutputStream outputStream = null;
try {
outputStream = context.getContentResolver().openOutputStream(Uri.fromFile(new File(mImageOutputPath)));
croppedBitmap.compress(mCompressFormat, mCompressQuality, outputStream);
croppedBitmap.recycle();
} finally {
BitmapLoadUtils.close(outputStream);
}
}

/**
* Check whether an image should be cropped at all or just file can be copied to the destination path.
* For each 1000 pixels there is one pixel of error due to matrix calculations etc.
Expand All @@ -170,14 +193,6 @@ private boolean shouldCrop(int width, int height) {
|| Math.abs(mCropRect.right - mCurrentImageRect.right) > pixelError;
}

@SuppressWarnings("JniMissingFunction")
native public boolean
cropCImg(String inputPath, String outputPath,
int left, int top, int width, int height,
float angle, float resizeScale,
int format, int quality,
int exifDegrees, int exifTranslation) throws IOException, OutOfMemoryError;

@Override
protected void onPostExecute(@Nullable Throwable t) {
if (mCropCallback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void cropAndSaveImage(@NonNull Bitmap.CompressFormat compressFormat, int
compressFormat, compressQuality,
getImageInputPath(), getImageOutputPath(), getExifInfo());

new BitmapCropTask(getViewBitmap(), imageState, cropParameters, cropCallback).execute();
new BitmapCropTask(getContext(), getViewBitmap(), imageState, cropParameters, cropCallback).execute();
}

/**
Expand Down
14 changes: 0 additions & 14 deletions ucrop/src/main/jni/Android.mk

This file was deleted.

6 changes: 0 additions & 6 deletions ucrop/src/main/jni/Application.mk

This file was deleted.

Loading