Skip to content

Commit 03e8295

Browse files
authored
Merge pull request #811 from Yalantis/improve/native/2.2.8-prs_integration
Improve/native/2.2.8 prs integration
2 parents 4d3623e + 5f6f375 commit 03e8295

File tree

24 files changed

+200
-53
lines changed

24 files changed

+200
-53
lines changed

README.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<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>
1515

16-
1. Include the library as local library project.
16+
1. Include the library as a local library project.
1717

1818
```
1919
allprojects {
@@ -25,9 +25,9 @@
2525
```
2626

2727
``` implementation 'com.github.yalantis:ucrop:2.2.6' ``` - lightweight general solution
28-
28+
2929
``` 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)
30-
30+
3131
2. Add UCropActivity into your AndroidManifest.xml
3232

3333
```
@@ -73,24 +73,24 @@ If you want to let your users choose crop ratio dynamically, just do not call `w
7373
7474
uCrop builder class has method `withOptions(UCrop.Options options)` which extends library configurations.
7575
76-
Currently you can change:
76+
Currently, you can change:
7777
7878
* image compression format (e.g. PNG, JPEG, WEBP), compression
7979
* image compression quality [0 - 100]. PNG which is lossless, will ignore the quality setting.
8080
* whether all gestures are enabled simultaneously
81-
* maximum size for Bitmap that is decoded from source Uri and used within crop view. If you want to override default behaviour.
81+
* maximum size for Bitmap that is decoded from source Uri and used within crop view. If you want to override the default behaviour.
8282
* toggle whether to show crop frame/guidelines
8383
* setup color/width/count of crop frame/rows/columns
84-
* choose whether you want rectangle or oval crop area
84+
* choose whether you want rectangle or oval(`options.setCircleDimmedLayer(true)`) crop area
8585
* the UI colors (Toolbar, StatusBar, active widget state)
8686
* and more...
87-
87+
8888
# Compatibility
89-
89+
9090
* Library - Android ICS 4.0+ (API 14) (Android GINGERBREAD 2.3+ (API 10) for versions <= 1.3.2)
9191
* Sample - Android ICS 4.0+ (API 14)
9292
* CPU - armeabi armeabi-v7a x86 x86_64 arm64-v8a (for versions >= 2.1.2)
93-
93+
9494
# Changelog
9595
9696
### Version: 2.2.5
@@ -106,13 +106,13 @@ Currently you can change:
106106
* **AndroidX migration**
107107
* Redesign
108108
* Several fixes including [#550](https://github.com/Yalantis/uCrop/issues/550)
109-
109+
110110
### Version: 2.2.3
111111
112-
* Several fixes including [#445](https://github.com/Yalantis/uCrop/issues/445), [#465](https://github.com/Yalantis/uCrop/issues/465) and more!
113-
* Material design support
112+
* Several fixes including [#445](https://github.com/Yalantis/uCrop/issues/445), [#465](https://github.com/Yalantis/uCrop/issues/465) and more!
113+
* Material design support
114114
* uCrop fragment as child fragment
115-
* Added Italian language
115+
* Added the Italian language
116116
117117
### Version: 2.2.2
118118
@@ -131,7 +131,7 @@ Currently you can change:
131131
### Version: 2.1
132132
133133
* 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)
134-
* Added API to set custom set of aspect ratio options for user. [#131](https://github.com/Yalantis/uCrop/issues/131)
134+
* Added API to set custom set of aspect ratio options for the user. [#131](https://github.com/Yalantis/uCrop/issues/131)
135135
* Added API to set all configs via UCrop.Options class. [#126](https://github.com/Yalantis/uCrop/issues/126)
136136
* Added ABI x86_64 support. [#105](https://github.com/Yalantis/uCrop/issues/105)
137137
@@ -140,7 +140,7 @@ Currently you can change:
140140
* Native image crop (able to crop high-resolution images, e.g. 16MP & 32MP images on Nexus 5X).
141141
* WebP compression format is not supported at the moment (choose JPEG or PNG).
142142
* Now library copies EXIF data to cropped image (size and orientation are updated).
143-
143+
144144
### Version: 1.5
145145
146146
* Introduced "Freestyle" crop (you can resize crop rectangle by dragging it corners) [#32](https://github.com/Yalantis/uCrop/issues/32)
@@ -149,21 +149,21 @@ Currently you can change:
149149
150150
### Version: 1.4
151151
152-
* Introduced http(s) Uri support!
153-
* Image is cropped in background thread.
152+
* Introduced HTTP(s) Uri support!
153+
* Image is cropped in a background thread.
154154
* Showing loader while Bitmap is processed (both loading and cropping).
155155
* Several bug fixes.
156156
* Couple new things to configure.
157157
* Updated minSdkVersion to Android ICS 4.0 (no reason to support couple percents of old phones).
158158
159159
### Version: 1.3
160160
161-
* Image is loaded in background thread. Better error-handling for image decoding.
161+
* Image is loaded in a background thread. Better error-handling for image decoding.
162162
* Improved EXIF data support (rotation and mirror).
163163
* Small UI updates.
164164
* Couple new things to configure.
165-
166-
* Sample updated with possibility to choose custom aspect ratio.
165+
166+
* Sample updated with the possibility to choose custom aspect ratio.
167167
168168
### Version: 1.2
169169
@@ -179,7 +179,7 @@ Currently you can change:
179179
180180
### Let us know!
181181
182-
We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the library.
182+
We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the library.
183183
184184
#### Apps using uCrop
185185

sample/build.gradle

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 29
5-
buildToolsVersion '28.0.3'
4+
compileSdkVersion 31
5+
buildToolsVersion '30.0.3'
66
defaultConfig {
77
applicationId "com.yalantis.ucrop.sample"
88
minSdkVersion 14
9-
targetSdkVersion 29
9+
targetSdkVersion 31
1010
versionCode 13
1111
versionName "1.2.4"
1212
}
@@ -38,5 +38,6 @@ dependencies {
3838
implementation "androidx.appcompat:appcompat:${androidx_appcompat_version}"
3939
implementation "androidx.core:core:${androidx_core_version}"
4040
implementation "androidx.constraintlayout:constraintlayout:${constraintlayout_version}"
41+
implementation "com.squareup.okhttp3:okhttp:3.12.13"
4142
implementation project(':ucrop')
4243
}

sample/src/main/AndroidManifest.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<uses-permission android:name="android.permission.INTERNET" />
88

99
<application
10+
android:name=".SampleApp"
1011
android:allowBackup="false"
1112
android:icon="@mipmap/ic_launcher"
1213
android:requestLegacyExternalStorage="true"
@@ -24,7 +25,8 @@
2425

2526
<activity
2627
android:name=".SampleActivity"
27-
android:screenOrientation="portrait">
28+
android:screenOrientation="portrait"
29+
android:exported="true">
2830
<intent-filter>
2931
<action android:name="android.intent.action.MAIN" />
3032

sample/src/main/java/com/yalantis/ucrop/sample/SampleActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,14 @@ Tune everything (ノ◕ヮ◕)ノ*:・゚✧
349349
options.setActiveControlsWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
350350
351351
// Aspect ratio options
352-
options.setAspectRatioOptions(1,
352+
options.setAspectRatioOptions(2,
353353
new AspectRatio("WOW", 1, 2),
354354
new AspectRatio("MUCH", 3, 4),
355355
new AspectRatio("RATIO", CropImageView.DEFAULT_ASPECT_RATIO, CropImageView.DEFAULT_ASPECT_RATIO),
356356
new AspectRatio("SO", 16, 9),
357357
new AspectRatio("ASPECT", 1, 1));
358+
options.withAspectRatio(CropImageView.DEFAULT_ASPECT_RATIO, CropImageView.DEFAULT_ASPECT_RATIO);
359+
options.useSourceImageAspectRatio();
358360
359361
*/
360362

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.yalantis.ucrop.sample;
2+
3+
import android.app.Application;
4+
5+
import com.yalantis.ucrop.UCropHttpClientStore;
6+
7+
import java.util.Collections;
8+
9+
import okhttp3.ConnectionSpec;
10+
import okhttp3.OkHttpClient;
11+
12+
public class SampleApp extends Application {
13+
14+
@Override
15+
public void onCreate() {
16+
super.onCreate();
17+
setUcropHttpClient();
18+
}
19+
20+
private void setUcropHttpClient() {
21+
ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
22+
.allEnabledCipherSuites()
23+
.allEnabledTlsVersions()
24+
.build();
25+
26+
OkHttpClient client = new OkHttpClient.Builder()
27+
.connectionSpecs(Collections.singletonList(cs))
28+
.build();
29+
30+
UCropHttpClientStore.INSTANCE.setClient(client);
31+
}
32+
}

ucrop/build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply from: '../mavenpush.gradle'
33

44
android {
5-
compileSdkVersion 28
6-
buildToolsVersion '28.0.3'
5+
compileSdkVersion 31
6+
buildToolsVersion '30.0.2'
77

88
defaultConfig {
99
minSdkVersion 14
10-
targetSdkVersion 28
10+
targetSdkVersion 31
1111
versionCode 26
1212
versionName "2.2.5-native"
1313

@@ -39,5 +39,6 @@ dependencies {
3939
implementation "androidx.appcompat:appcompat:${androidx_appcompat_version}"
4040
implementation "androidx.exifinterface:exifinterface:${androidx_exifinterface_version}"
4141
implementation "androidx.transition:transition:${androidx_transition_version}"
42-
implementation "com.squareup.okhttp3:okhttp:3.12.1"
42+
// OkHttp3 versions above 3.12.x don't support pre-Lollipop Android versions (API 21)
43+
implementation "com.squareup.okhttp3:okhttp:3.12.13"
4344
}

ucrop/src/main/java/com/yalantis/ucrop/UCrop.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ public void setFreeStyleCropEnabled(boolean enabled) {
517517
* @param aspectRatio - list of aspect ratio options that are available to user
518518
*/
519519
public void setAspectRatioOptions(int selectedByDefault, AspectRatio... aspectRatio) {
520-
if (selectedByDefault > aspectRatio.length) {
520+
if (selectedByDefault >= aspectRatio.length) {
521521
throw new IllegalArgumentException(String.format(Locale.US,
522-
"Index [selectedByDefault = %d] cannot be higher than aspect ratio options count [count = %d].",
522+
"Index [selectedByDefault = %d] (0-based) cannot be higher or equal than aspect ratio options count [count = %d].",
523523
selectedByDefault, aspectRatio.length));
524524
}
525525
mOptionBundle.putInt(EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, selectedByDefault);

ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,21 @@ private void processOptions(@NonNull Intent intent) {
256256
mOverlayView.setCropGridStrokeWidth(intent.getIntExtra(UCrop.Options.EXTRA_CROP_GRID_STROKE_WIDTH, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));
257257

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

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

265-
if (aspectRatioX > 0 && aspectRatioY > 0) {
265+
if (aspectRatioX >= 0 && aspectRatioY >= 0) {
266266
if (mWrapperStateAspectRatio != null) {
267267
mWrapperStateAspectRatio.setVisibility(View.GONE);
268268
}
269-
mGestureCropImageView.setTargetAspectRatio(aspectRatioX / aspectRatioY);
269+
float targetAspectRatio = aspectRatioX / aspectRatioY;
270+
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
270271
} else if (aspectRatioList != null && aspectRationSelectedByDefault < aspectRatioList.size()) {
271-
mGestureCropImageView.setTargetAspectRatio(aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() /
272-
aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY());
272+
float targetAspectRatio = aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() / aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY();
273+
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
273274
} else {
274275
mGestureCropImageView.setTargetAspectRatio(CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
275276
}

ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,21 @@ private void processOptions(@NonNull Bundle bundle) {
237237
mOverlayView.setCropGridStrokeWidth(bundle.getInt(UCrop.Options.EXTRA_CROP_GRID_STROKE_WIDTH, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));
238238

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

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

246-
if (aspectRatioX > 0 && aspectRatioY > 0) {
246+
if (aspectRatioX >= 0 && aspectRatioY >= 0) {
247247
if (mWrapperStateAspectRatio != null) {
248248
mWrapperStateAspectRatio.setVisibility(View.GONE);
249249
}
250-
mGestureCropImageView.setTargetAspectRatio(aspectRatioX / aspectRatioY);
250+
float targetAspectRatio = aspectRatioX / aspectRatioY;
251+
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
251252
} else if (aspectRatioList != null && aspectRationSelectedByDefault < aspectRatioList.size()) {
252-
mGestureCropImageView.setTargetAspectRatio(aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() /
253-
aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY());
253+
float targetAspectRatio = aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() / aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY();
254+
mGestureCropImageView.setTargetAspectRatio(Float.isNaN(targetAspectRatio) ? CropImageView.SOURCE_IMAGE_ASPECT_RATIO : targetAspectRatio);
254255
} else {
255256
mGestureCropImageView.setTargetAspectRatio(CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
256257
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.yalantis.ucrop;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import okhttp3.OkHttpClient;
6+
7+
public class UCropHttpClientStore {
8+
9+
private UCropHttpClientStore() {}
10+
11+
public final static UCropHttpClientStore INSTANCE = new UCropHttpClientStore();
12+
13+
private OkHttpClient client;
14+
15+
@NonNull
16+
public OkHttpClient getClient() {
17+
if (client == null) {
18+
client = new OkHttpClient();
19+
}
20+
return client;
21+
}
22+
23+
public void setClient(@NonNull OkHttpClient client) {
24+
this.client = client;
25+
}
26+
}

ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.NonNull;
1212
import androidx.annotation.Nullable;
1313

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

207-
OkHttpClient client = new OkHttpClient();
208+
OkHttpClient client = UCropHttpClientStore.INSTANCE.getClient();
208209

209210
BufferedSource source = null;
210211
Sink sink = null;
211212
Response response = null;
212213
try {
213214
Request request = new Request.Builder()
214-
.url(inputUri.toString())
215-
.build();
215+
.url(inputUri.toString())
216+
.build();
216217
response = client.newCall(request).execute();
217218
source = response.body().source();
218219

ucrop/src/main/java/com/yalantis/ucrop/view/GestureCropImageView.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class GestureCropImageView extends CropImageView {
2121

2222
private float mMidPntX, mMidPntY;
2323

24-
private boolean mIsRotateEnabled = true, mIsScaleEnabled = true;
24+
private boolean mIsRotateEnabled = true, mIsScaleEnabled = true, mIsGestureEnabled = true;
2525
private int mDoubleTapScaleSteps = 5;
2626

2727
public GestureCropImageView(Context context) {
@@ -52,6 +52,14 @@ public boolean isRotateEnabled() {
5252
return mIsRotateEnabled;
5353
}
5454

55+
public void setGestureEnabled(boolean gestureEnabled) {
56+
mIsGestureEnabled = gestureEnabled;
57+
}
58+
59+
public boolean isGestureEnabled() {
60+
return mIsGestureEnabled;
61+
}
62+
5563
public void setDoubleTapScaleSteps(int doubleTapScaleSteps) {
5664
mDoubleTapScaleSteps = doubleTapScaleSteps;
5765
}
@@ -77,7 +85,9 @@ public boolean onTouchEvent(MotionEvent event) {
7785
mMidPntY = (event.getY(0) + event.getY(1)) / 2;
7886
}
7987

80-
mGestureDetector.onTouchEvent(event);
88+
if (mIsGestureEnabled) {
89+
mGestureDetector.onTouchEvent(event);
90+
}
8191

8292
if (mIsScaleEnabled) {
8393
mScaleDetector.onTouchEvent(event);

0 commit comments

Comments
 (0)