Skip to content

Commit 411a11f

Browse files
authored
Merge pull request #644 from Yalantis/feature/non_native
Feature/non native
2 parents df14c58 + 684dd33 commit 411a11f

File tree

12 files changed

+97
-90
lines changed

12 files changed

+97
-90
lines changed

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20-
VERSION_NAME=2.2.3-non-native
21-
VERSION_CODE=24
20+
VERSION_NAME=2.2.5-non-native
21+
VERSION_CODE=25
2222
GROUP=com.yalantis
2323

2424
POM_DESCRIPTION=Android Library for cropping images

sample/build.gradle

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

33
android {
4-
compileSdkVersion 28
4+
compileSdkVersion 29
55
buildToolsVersion '28.0.3'
66
defaultConfig {
77
applicationId "com.yalantis.ucrop.sample"
88
minSdkVersion 14
9-
targetSdkVersion 28
9+
targetSdkVersion 29
1010
versionCode 13
1111
versionName "1.2.4"
1212
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ Tune everything (ノ◕ヮ◕)ノ*:・゚✧
372372
// Color palette
373373
options.setToolbarColor(ContextCompat.getColor(this, R.color.your_color_res));
374374
options.setStatusBarColor(ContextCompat.getColor(this, R.color.your_color_res));
375-
options.setActiveWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
376375
options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
377376
options.setRootViewBackgroundColor(ContextCompat.getColor(this, R.color.your_color_res));
377+
options.setActiveControlsWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
378378
379379
// Aspect ratio options
380380
options.setAspectRatioOptions(1,

sample/src/main/res/values/colors.xml

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<color name="colorPrimary">#FF6E40</color>
44
<color name="colorPrimaryDark">#CC5833</color>
55
<color name="colorAccent">#FF6E40</color>
6+
7+
<color name="your_color_res">#03A9F4</color>
68
</resources>

ucrop/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
defaultConfig {
99
minSdkVersion 14
1010
targetSdkVersion 28
11-
versionCode 24
12-
versionName "2.2.4-non-native"
11+
versionCode 25
12+
versionName "2.2.5-non-native"
1313

1414
vectorDrawables.useSupportLibrary = true
1515
}

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

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yalantis.ucrop;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.graphics.Bitmap;
@@ -123,7 +124,7 @@ public UCrop withOptions(@NonNull Options options) {
123124
*
124125
* @param activity Activity to receive result
125126
*/
126-
public void start(@NonNull AppCompatActivity activity) {
127+
public void start(@NonNull Activity activity) {
127128
start(activity, REQUEST_CROP);
128129
}
129130

@@ -133,7 +134,7 @@ public void start(@NonNull AppCompatActivity activity) {
133134
* @param activity Activity to receive result
134135
* @param requestCode requestCode for result
135136
*/
136-
public void start(@NonNull AppCompatActivity activity, int requestCode) {
137+
public void start(@NonNull Activity activity, int requestCode) {
137138
activity.startActivityForResult(getIntent(activity), requestCode);
138139
}
139140

@@ -260,7 +261,6 @@ public static class Options {
260261

261262
public static final String EXTRA_TOOL_BAR_COLOR = EXTRA_PREFIX + ".ToolbarColor";
262263
public static final String EXTRA_STATUS_BAR_COLOR = EXTRA_PREFIX + ".StatusBarColor";
263-
public static final String EXTRA_UCROP_COLOR_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorWidgetActive";
264264
public static final String EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorControlsWidgetActive";
265265

266266
public static final String EXTRA_UCROP_WIDGET_COLOR_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarWidgetColor";
@@ -425,14 +425,7 @@ public void setStatusBarColor(@ColorInt int color) {
425425
}
426426

427427
/**
428-
* @param color - desired resolved color of the progress wheel middle line (default is violet)
429-
*/
430-
public void setActiveWidgetColor(@ColorInt int color) {
431-
mOptionBundle.putInt(EXTRA_UCROP_COLOR_WIDGET_ACTIVE, color);
432-
}
433-
434-
/**
435-
* @param color - desired resolved color of the active and selected widget (default is white)
428+
* @param color - desired resolved color of the active and selected widget and progress wheel middle line (default is white)
436429
*/
437430
public void setActiveControlsWidgetColor(@ColorInt int color) {
438431
mOptionBundle.putInt(EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, color);

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

+29-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import androidx.annotation.NonNull;
5050
import androidx.appcompat.app.ActionBar;
5151
import androidx.appcompat.app.AppCompatActivity;
52+
import androidx.appcompat.app.AppCompatDelegate;
5253
import androidx.appcompat.widget.Toolbar;
5354
import androidx.core.content.ContextCompat;
5455
import androidx.transition.AutoTransition;
@@ -87,7 +88,6 @@ public class UCropActivity extends AppCompatActivity {
8788
// Enables dynamic coloring
8889
private int mToolbarColor;
8990
private int mStatusBarColor;
90-
private int mActiveWidgetColor;
9191
private int mActiveControlsWidgetColor;
9292
private int mToolbarWidgetColor;
9393
@ColorInt
@@ -116,6 +116,10 @@ public class UCropActivity extends AppCompatActivity {
116116
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
117117
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};
118118

119+
static {
120+
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
121+
}
122+
119123
@Override
120124
public void onCreate(Bundle savedInstanceState) {
121125
super.onCreate(savedInstanceState);
@@ -282,7 +286,6 @@ private void processOptions(@NonNull Intent intent) {
282286
private void setupViews(@NonNull Intent intent) {
283287
mStatusBarColor = intent.getIntExtra(UCrop.Options.EXTRA_STATUS_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_statusbar));
284288
mToolbarColor = intent.getIntExtra(UCrop.Options.EXTRA_TOOL_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar));
285-
mActiveWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
286289
mActiveControlsWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_active_controls_color));
287290

288291
mToolbarWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_WIDGET_COLOR_TOOLBAR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar_widget));
@@ -302,7 +305,6 @@ private void setupViews(@NonNull Intent intent) {
302305
ViewGroup viewGroup = findViewById(R.id.ucrop_photobox);
303306
ViewGroup wrapper = viewGroup.findViewById(R.id.controls_wrapper);
304307
wrapper.setVisibility(View.VISIBLE);
305-
wrapper.setBackgroundColor(mRootViewBackgroundColor);
306308
LayoutInflater.from(this).inflate(R.layout.ucrop_controls, wrapper, true);
307309

308310
mControlsTransition = new AutoTransition();
@@ -364,6 +366,11 @@ private void initiateRootViews() {
364366
((ImageView) findViewById(R.id.image_view_logo)).setColorFilter(mLogoColor, PorterDuff.Mode.SRC_ATOP);
365367

366368
findViewById(R.id.ucrop_frame).setBackgroundColor(mRootViewBackgroundColor);
369+
if (!mShowBottomControls) {
370+
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) findViewById(R.id.ucrop_frame).getLayoutParams();
371+
params.bottomMargin = 0;
372+
findViewById(R.id.ucrop_frame).requestLayout();
373+
}
367374
}
368375

369376
private TransformImageView.TransformImageListener mImageListener = new TransformImageView.TransformImageListener() {
@@ -394,7 +401,7 @@ public void onLoadFailure(@NonNull Exception e) {
394401
};
395402

396403
/**
397-
* Use {@link #mActiveWidgetColor} for color filter
404+
* Use {@link #mActiveControlsWidgetColor} for color filter
398405
*/
399406
private void setupStatesWrapper() {
400407
ImageView stateScaleImageView = findViewById(R.id.image_view_state_scale);
@@ -496,7 +503,7 @@ public void onScrollStart() {
496503
}
497504
});
498505

499-
((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
506+
((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);
500507

501508

502509
findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() {
@@ -511,6 +518,8 @@ public void onClick(View v) {
511518
rotateByAngle(90);
512519
}
513520
});
521+
522+
setAngleTextColor(mActiveControlsWidgetColor);
514523
}
515524

516525
private void setupScaleWidget() {
@@ -538,7 +547,9 @@ public void onScrollStart() {
538547
mGestureCropImageView.cancelAllAnimations();
539548
}
540549
});
541-
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
550+
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);
551+
552+
setScaleTextColor(mActiveControlsWidgetColor);
542553
}
543554

544555
private void setAngleText(float angle) {
@@ -547,12 +558,24 @@ private void setAngleText(float angle) {
547558
}
548559
}
549560

561+
private void setAngleTextColor(int textColor) {
562+
if (mTextViewRotateAngle != null) {
563+
mTextViewRotateAngle.setTextColor(textColor);
564+
}
565+
}
566+
550567
private void setScaleText(float scale) {
551568
if (mTextViewScalePercent != null) {
552569
mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100)));
553570
}
554571
}
555572

573+
private void setScaleTextColor(int textColor) {
574+
if (mTextViewScalePercent != null) {
575+
mTextViewScalePercent.setTextColor(textColor);
576+
}
577+
}
578+
556579
private void resetRotation() {
557580
mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle());
558581
mGestureCropImageView.setImageToWrapCropBounds();

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

+30-8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import androidx.annotation.IntDef;
4040
import androidx.annotation.NonNull;
4141
import androidx.annotation.Nullable;
42+
import androidx.appcompat.app.AppCompatDelegate;
4243
import androidx.core.content.ContextCompat;
4344
import androidx.fragment.app.Fragment;
4445
import androidx.transition.AutoTransition;
@@ -72,7 +73,6 @@ public class UCropFragment extends Fragment {
7273
private UCropFragmentCallback callback;
7374

7475
private int mActiveControlsWidgetColor;
75-
private int mActiveWidgetColor;
7676
@ColorInt
7777
private int mRootViewBackgroundColor;
7878
private int mLogoColor;
@@ -94,6 +94,10 @@ public class UCropFragment extends Fragment {
9494
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
9595
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};
9696

97+
static {
98+
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
99+
}
100+
97101
public static UCropFragment newInstance(Bundle uCrop) {
98102
UCropFragment fragment = new UCropFragment();
99103
fragment.setArguments(uCrop);
@@ -133,8 +137,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
133137

134138

135139
public void setupViews(View view, Bundle args) {
136-
mActiveWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_background));
137-
mActiveControlsWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_active));
140+
mActiveControlsWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_active));
138141
mLogoColor = args.getInt(UCrop.Options.EXTRA_UCROP_LOGO_COLOR, ContextCompat.getColor(getContext(), R.color.ucrop_color_default_logo));
139142
mShowBottomControls = !args.getBoolean(UCrop.Options.EXTRA_HIDE_BOTTOM_CONTROLS, false);
140143
mRootViewBackgroundColor = args.getInt(UCrop.Options.EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR, ContextCompat.getColor(getContext(), R.color.ucrop_color_crop_background));
@@ -146,7 +149,6 @@ public void setupViews(View view, Bundle args) {
146149

147150
ViewGroup wrapper = view.findViewById(R.id.controls_wrapper);
148151
wrapper.setVisibility(View.VISIBLE);
149-
wrapper.setBackgroundColor(mRootViewBackgroundColor);
150152
LayoutInflater.from(getContext()).inflate(R.layout.ucrop_controls, wrapper, true);
151153

152154
mControlsTransition = new AutoTransition();
@@ -167,6 +169,10 @@ public void setupViews(View view, Bundle args) {
167169
setupRotateWidget(view);
168170
setupScaleWidget(view);
169171
setupStatesWrapper(view);
172+
} else {
173+
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.findViewById(R.id.ucrop_frame).getLayoutParams();
174+
params.bottomMargin = 0;
175+
view.findViewById(R.id.ucrop_frame).requestLayout();
170176
}
171177
}
172178

@@ -296,7 +302,7 @@ public void onLoadFailure(@NonNull Exception e) {
296302
};
297303

298304
/**
299-
* Use {@link #mActiveWidgetColor} for color filter
305+
* Use {@link #mActiveControlsWidgetColor} for color filter
300306
*/
301307
private void setupStatesWrapper(View view) {
302308
ImageView stateScaleImageView = view.findViewById(R.id.image_view_state_scale);
@@ -334,7 +340,7 @@ private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) {
334340
wrapperAspectRatio = (FrameLayout) getLayoutInflater().inflate(R.layout.ucrop_aspect_ratio, null);
335341
wrapperAspectRatio.setLayoutParams(lp);
336342
aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0));
337-
aspectRatioTextView.setActiveColor(mActiveWidgetColor);
343+
aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor);
338344
aspectRatioTextView.setAspectRatio(aspectRatio);
339345

340346
wrapperAspectRatioList.addView(wrapperAspectRatio);
@@ -380,7 +386,7 @@ public void onScrollStart() {
380386
}
381387
});
382388

383-
((HorizontalProgressWheelView) view.findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
389+
((HorizontalProgressWheelView) view.findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);
384390

385391

386392
view.findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() {
@@ -395,6 +401,8 @@ public void onClick(View v) {
395401
rotateByAngle(90);
396402
}
397403
});
404+
405+
setAngleTextColor(mActiveControlsWidgetColor);
398406
}
399407

400408
private void setupScaleWidget(View view) {
@@ -422,7 +430,9 @@ public void onScrollStart() {
422430
mGestureCropImageView.cancelAllAnimations();
423431
}
424432
});
425-
((HorizontalProgressWheelView) view.findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
433+
((HorizontalProgressWheelView) view.findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);
434+
435+
setScaleTextColor(mActiveControlsWidgetColor);
426436
}
427437

428438
private void setAngleText(float angle) {
@@ -431,12 +441,24 @@ private void setAngleText(float angle) {
431441
}
432442
}
433443

444+
private void setAngleTextColor(int textColor) {
445+
if (mTextViewRotateAngle != null) {
446+
mTextViewRotateAngle.setTextColor(textColor);
447+
}
448+
}
449+
434450
private void setScaleText(float scale) {
435451
if (mTextViewScalePercent != null) {
436452
mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100)));
437453
}
438454
}
439455

456+
private void setScaleTextColor(int textColor) {
457+
if (mTextViewScalePercent != null) {
458+
mTextViewScalePercent.setTextColor(textColor);
459+
}
460+
}
461+
440462
private void resetRotation() {
441463
mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle());
442464
mGestureCropImageView.setImageToWrapCropBounds();

0 commit comments

Comments
 (0)