Skip to content

Commit

Permalink
Merge pull request #811 from Yalantis/improve/native/2.2.8-prs_integr…
Browse files Browse the repository at this point in the history
…ation

Improve/native/2.2.8 prs integration
  • Loading branch information
severianremi authored Jan 27, 2022
2 parents 4d3623e + 5f6f375 commit 03e8295
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 53 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<a href="https://play.google.com/store/apps/details?id=com.yalantis.ucrop.sample&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-AC-global-none-all-co-pr-py-PartBadges-Oct1515-1"><img alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png" width="185" height="70"/></a>

1. Include the library as local library project.
1. Include the library as a local library project.

```
allprojects {
Expand All @@ -25,9 +25,9 @@
```

``` implementation 'com.github.yalantis:ucrop:2.2.6' ``` - lightweight general solution

``` implementation 'com.github.yalantis:ucrop:2.2.6-native' ``` - get power of the native code to preserve image quality (+ about 1.5 MB to an apk size)

2. Add UCropActivity into your AndroidManifest.xml

```
Expand Down Expand Up @@ -73,24 +73,24 @@ If you want to let your users choose crop ratio dynamically, just do not call `w

uCrop builder class has method `withOptions(UCrop.Options options)` which extends library configurations.

Currently you can change:
Currently, you can change:

* image compression format (e.g. PNG, JPEG, WEBP), compression
* image compression quality [0 - 100]. PNG which is lossless, will ignore the quality setting.
* whether all gestures are enabled simultaneously
* maximum size for Bitmap that is decoded from source Uri and used within crop view. If you want to override default behaviour.
* maximum size for Bitmap that is decoded from source Uri and used within crop view. If you want to override the default behaviour.
* toggle whether to show crop frame/guidelines
* setup color/width/count of crop frame/rows/columns
* choose whether you want rectangle or oval crop area
* choose whether you want rectangle or oval(`options.setCircleDimmedLayer(true)`) crop area
* the UI colors (Toolbar, StatusBar, active widget state)
* and more...

# Compatibility

* Library - Android ICS 4.0+ (API 14) (Android GINGERBREAD 2.3+ (API 10) for versions <= 1.3.2)
* Sample - Android ICS 4.0+ (API 14)
* CPU - armeabi armeabi-v7a x86 x86_64 arm64-v8a (for versions >= 2.1.2)

# Changelog

### Version: 2.2.5
Expand All @@ -106,13 +106,13 @@ Currently you can change:
* **AndroidX migration**
* Redesign
* Several fixes including [#550](https://github.com/Yalantis/uCrop/issues/550)

### Version: 2.2.3

* Several fixes including [#445](https://github.com/Yalantis/uCrop/issues/445), [#465](https://github.com/Yalantis/uCrop/issues/465) and more!
* Material design support
* Several fixes including [#445](https://github.com/Yalantis/uCrop/issues/445), [#465](https://github.com/Yalantis/uCrop/issues/465) and more!
* Material design support
* uCrop fragment as child fragment
* Added Italian language
* Added the Italian language

### Version: 2.2.2

Expand All @@ -131,7 +131,7 @@ Currently you can change:
### Version: 2.1

* Fixes issue with EXIF data (images taken on front camera with Samsung devices mostly) [#130](https://github.com/Yalantis/uCrop/issues/130) [#111](https://github.com/Yalantis/uCrop/issues/111)
* Added API to set custom set of aspect ratio options for user. [#131](https://github.com/Yalantis/uCrop/issues/131)
* Added API to set custom set of aspect ratio options for the user. [#131](https://github.com/Yalantis/uCrop/issues/131)
* Added API to set all configs via UCrop.Options class. [#126](https://github.com/Yalantis/uCrop/issues/126)
* Added ABI x86_64 support. [#105](https://github.com/Yalantis/uCrop/issues/105)

Expand All @@ -140,7 +140,7 @@ Currently you can change:
* Native image crop (able to crop high-resolution images, e.g. 16MP & 32MP images on Nexus 5X).
* WebP compression format is not supported at the moment (choose JPEG or PNG).
* Now library copies EXIF data to cropped image (size and orientation are updated).

### Version: 1.5

* Introduced "Freestyle" crop (you can resize crop rectangle by dragging it corners) [#32](https://github.com/Yalantis/uCrop/issues/32)
Expand All @@ -149,21 +149,21 @@ Currently you can change:

### Version: 1.4

* Introduced http(s) Uri support!
* Image is cropped in background thread.
* Introduced HTTP(s) Uri support!
* Image is cropped in a background thread.
* Showing loader while Bitmap is processed (both loading and cropping).
* Several bug fixes.
* Couple new things to configure.
* Updated minSdkVersion to Android ICS 4.0 (no reason to support couple percents of old phones).

### Version: 1.3

* Image is loaded in background thread. Better error-handling for image decoding.
* Image is loaded in a background thread. Better error-handling for image decoding.
* Improved EXIF data support (rotation and mirror).
* Small UI updates.
* Couple new things to configure.
* Sample updated with possibility to choose custom aspect ratio.

* Sample updated with the possibility to choose custom aspect ratio.

### Version: 1.2

Expand All @@ -179,7 +179,7 @@ Currently you can change:

### Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to github@yalantis.com And do let us know if you have any questions or suggestion regarding the library.
We’d be really happy if you sent us links to your projects where you use our component. Just send an email to github@yalantis.com And do let us know if you have any questions or suggestion regarding the library.

#### Apps using uCrop

Expand Down
7 changes: 4 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion '28.0.3'
compileSdkVersion 31
buildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.yalantis.ucrop.sample"
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 31
versionCode 13
versionName "1.2.4"
}
Expand Down Expand Up @@ -38,5 +38,6 @@ dependencies {
implementation "androidx.appcompat:appcompat:${androidx_appcompat_version}"
implementation "androidx.core:core:${androidx_core_version}"
implementation "androidx.constraintlayout:constraintlayout:${constraintlayout_version}"
implementation "com.squareup.okhttp3:okhttp:3.12.13"
implementation project(':ucrop')
}
4 changes: 3 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".SampleApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
Expand All @@ -24,7 +25,8 @@

<activity
android:name=".SampleActivity"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,14 @@ Tune everything (ノ◕ヮ◕)ノ*:・゚✧
options.setActiveControlsWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
// Aspect ratio options
options.setAspectRatioOptions(1,
options.setAspectRatioOptions(2,
new AspectRatio("WOW", 1, 2),
new AspectRatio("MUCH", 3, 4),
new AspectRatio("RATIO", CropImageView.DEFAULT_ASPECT_RATIO, CropImageView.DEFAULT_ASPECT_RATIO),
new AspectRatio("SO", 16, 9),
new AspectRatio("ASPECT", 1, 1));
options.withAspectRatio(CropImageView.DEFAULT_ASPECT_RATIO, CropImageView.DEFAULT_ASPECT_RATIO);
options.useSourceImageAspectRatio();
*/

Expand Down
32 changes: 32 additions & 0 deletions sample/src/main/java/com/yalantis/ucrop/sample/SampleApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.yalantis.ucrop.sample;

import android.app.Application;

import com.yalantis.ucrop.UCropHttpClientStore;

import java.util.Collections;

import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;

public class SampleApp extends Application {

@Override
public void onCreate() {
super.onCreate();
setUcropHttpClient();
}

private void setUcropHttpClient() {
ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.allEnabledCipherSuites()
.allEnabledTlsVersions()
.build();

OkHttpClient client = new OkHttpClient.Builder()
.connectionSpecs(Collections.singletonList(cs))
.build();

UCropHttpClientStore.INSTANCE.setClient(client);
}
}
9 changes: 5 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 28
buildToolsVersion '28.0.3'
compileSdkVersion 31
buildToolsVersion '30.0.2'

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 31
versionCode 26
versionName "2.2.5-native"

Expand Down Expand Up @@ -39,5 +39,6 @@ dependencies {
implementation "androidx.appcompat:appcompat:${androidx_appcompat_version}"
implementation "androidx.exifinterface:exifinterface:${androidx_exifinterface_version}"
implementation "androidx.transition:transition:${androidx_transition_version}"
implementation "com.squareup.okhttp3:okhttp:3.12.1"
// OkHttp3 versions above 3.12.x don't support pre-Lollipop Android versions (API 21)
implementation "com.squareup.okhttp3:okhttp:3.12.13"
}
4 changes: 2 additions & 2 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ public void setFreeStyleCropEnabled(boolean enabled) {
* @param aspectRatio - list of aspect ratio options that are available to user
*/
public void setAspectRatioOptions(int selectedByDefault, AspectRatio... aspectRatio) {
if (selectedByDefault > aspectRatio.length) {
if (selectedByDefault >= aspectRatio.length) {
throw new IllegalArgumentException(String.format(Locale.US,
"Index [selectedByDefault = %d] cannot be higher than aspect ratio options count [count = %d].",
"Index [selectedByDefault = %d] (0-based) cannot be higher or equal than aspect ratio options count [count = %d].",
selectedByDefault, aspectRatio.length));
}
mOptionBundle.putInt(EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, selectedByDefault);
Expand Down
13 changes: 7 additions & 6 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,21 @@ private void processOptions(@NonNull Intent intent) {
mOverlayView.setCropGridStrokeWidth(intent.getIntExtra(UCrop.Options.EXTRA_CROP_GRID_STROKE_WIDTH, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));

// Aspect ratio options
float aspectRatioX = intent.getFloatExtra(UCrop.EXTRA_ASPECT_RATIO_X, 0);
float aspectRatioY = intent.getFloatExtra(UCrop.EXTRA_ASPECT_RATIO_Y, 0);
float aspectRatioX = intent.getFloatExtra(UCrop.EXTRA_ASPECT_RATIO_X, -1);
float aspectRatioY = intent.getFloatExtra(UCrop.EXTRA_ASPECT_RATIO_Y, -1);

int aspectRationSelectedByDefault = intent.getIntExtra(UCrop.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
ArrayList<AspectRatio> aspectRatioList = intent.getParcelableArrayListExtra(UCrop.Options.EXTRA_ASPECT_RATIO_OPTIONS);

if (aspectRatioX > 0 && aspectRatioY > 0) {
if (aspectRatioX >= 0 && aspectRatioY >= 0) {
if (mWrapperStateAspectRatio != null) {
mWrapperStateAspectRatio.setVisibility(View.GONE);
}
mGestureCropImageView.setTargetAspectRatio(aspectRatioX / aspectRatioY);
float targetAspectRatio = aspectRatioX / aspectRatioY;
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
} else if (aspectRatioList != null && aspectRationSelectedByDefault < aspectRatioList.size()) {
mGestureCropImageView.setTargetAspectRatio(aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() /
aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY());
float targetAspectRatio = aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() / aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY();
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
} else {
mGestureCropImageView.setTargetAspectRatio(CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
}
Expand Down
13 changes: 7 additions & 6 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,21 @@ private void processOptions(@NonNull Bundle bundle) {
mOverlayView.setCropGridStrokeWidth(bundle.getInt(UCrop.Options.EXTRA_CROP_GRID_STROKE_WIDTH, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));

// Aspect ratio options
float aspectRatioX = bundle.getFloat(UCrop.EXTRA_ASPECT_RATIO_X, 0);
float aspectRatioY = bundle.getFloat(UCrop.EXTRA_ASPECT_RATIO_Y, 0);
float aspectRatioX = bundle.getFloat(UCrop.EXTRA_ASPECT_RATIO_X, -1);
float aspectRatioY = bundle.getFloat(UCrop.EXTRA_ASPECT_RATIO_Y, -1);

int aspectRationSelectedByDefault = bundle.getInt(UCrop.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
ArrayList<AspectRatio> aspectRatioList = bundle.getParcelableArrayList(UCrop.Options.EXTRA_ASPECT_RATIO_OPTIONS);

if (aspectRatioX > 0 && aspectRatioY > 0) {
if (aspectRatioX >= 0 && aspectRatioY >= 0) {
if (mWrapperStateAspectRatio != null) {
mWrapperStateAspectRatio.setVisibility(View.GONE);
}
mGestureCropImageView.setTargetAspectRatio(aspectRatioX / aspectRatioY);
float targetAspectRatio = aspectRatioX / aspectRatioY;
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
} else if (aspectRatioList != null && aspectRationSelectedByDefault < aspectRatioList.size()) {
mGestureCropImageView.setTargetAspectRatio(aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() /
aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY());
float targetAspectRatio = aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() / aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY();
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
} else {
mGestureCropImageView.setTargetAspectRatio(CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
}
Expand Down
26 changes: 26 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropHttpClientStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yalantis.ucrop;

import androidx.annotation.NonNull;

import okhttp3.OkHttpClient;

public class UCropHttpClientStore {

private UCropHttpClientStore() {}

public final static UCropHttpClientStore INSTANCE = new UCropHttpClientStore();

private OkHttpClient client;

@NonNull
public OkHttpClient getClient() {
if (client == null) {
client = new OkHttpClient();
}
return client;
}

public void setClient(@NonNull OkHttpClient client) {
this.client = client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.yalantis.ucrop.UCropHttpClientStore;
import com.yalantis.ucrop.callback.BitmapLoadCallback;
import com.yalantis.ucrop.model.ExifInfo;
import com.yalantis.ucrop.util.BitmapLoadUtils;
Expand Down Expand Up @@ -204,15 +205,15 @@ private void downloadFile(@NonNull Uri inputUri, @Nullable Uri outputUri) throws
throw new NullPointerException("Output Uri is null - cannot download image");
}

OkHttpClient client = new OkHttpClient();
OkHttpClient client = UCropHttpClientStore.INSTANCE.getClient();

BufferedSource source = null;
Sink sink = null;
Response response = null;
try {
Request request = new Request.Builder()
.url(inputUri.toString())
.build();
.url(inputUri.toString())
.build();
response = client.newCall(request).execute();
source = response.body().source();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GestureCropImageView extends CropImageView {

private float mMidPntX, mMidPntY;

private boolean mIsRotateEnabled = true, mIsScaleEnabled = true;
private boolean mIsRotateEnabled = true, mIsScaleEnabled = true, mIsGestureEnabled = true;
private int mDoubleTapScaleSteps = 5;

public GestureCropImageView(Context context) {
Expand Down Expand Up @@ -52,6 +52,14 @@ public boolean isRotateEnabled() {
return mIsRotateEnabled;
}

public void setGestureEnabled(boolean gestureEnabled) {
mIsGestureEnabled = gestureEnabled;
}

public boolean isGestureEnabled() {
return mIsGestureEnabled;
}

public void setDoubleTapScaleSteps(int doubleTapScaleSteps) {
mDoubleTapScaleSteps = doubleTapScaleSteps;
}
Expand All @@ -77,7 +85,9 @@ public boolean onTouchEvent(MotionEvent event) {
mMidPntY = (event.getY(0) + event.getY(1)) / 2;
}

mGestureDetector.onTouchEvent(event);
if (mIsGestureEnabled) {
mGestureDetector.onTouchEvent(event);
}

if (mIsScaleEnabled) {
mScaleDetector.onTouchEvent(event);
Expand Down
Loading

0 comments on commit 03e8295

Please sign in to comment.