39
39
import androidx .annotation .IntDef ;
40
40
import androidx .annotation .NonNull ;
41
41
import androidx .annotation .Nullable ;
42
+ import androidx .appcompat .app .AppCompatDelegate ;
42
43
import androidx .core .content .ContextCompat ;
43
44
import androidx .fragment .app .Fragment ;
44
45
import androidx .transition .AutoTransition ;
@@ -72,7 +73,6 @@ public class UCropFragment extends Fragment {
72
73
private UCropFragmentCallback callback ;
73
74
74
75
private int mActiveControlsWidgetColor ;
75
- private int mActiveWidgetColor ;
76
76
@ ColorInt
77
77
private int mRootViewBackgroundColor ;
78
78
private int mLogoColor ;
@@ -94,6 +94,10 @@ public class UCropFragment extends Fragment {
94
94
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY ;
95
95
private int [] mAllowedGestures = new int []{SCALE , ROTATE , ALL };
96
96
97
+ static {
98
+ AppCompatDelegate .setCompatVectorFromResourcesEnabled (true );
99
+ }
100
+
97
101
public static UCropFragment newInstance (Bundle uCrop ) {
98
102
UCropFragment fragment = new UCropFragment ();
99
103
fragment .setArguments (uCrop );
@@ -133,8 +137,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
133
137
134
138
135
139
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 ));
138
141
mLogoColor = args .getInt (UCrop .Options .EXTRA_UCROP_LOGO_COLOR , ContextCompat .getColor (getContext (), R .color .ucrop_color_default_logo ));
139
142
mShowBottomControls = !args .getBoolean (UCrop .Options .EXTRA_HIDE_BOTTOM_CONTROLS , false );
140
143
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) {
146
149
147
150
ViewGroup wrapper = view .findViewById (R .id .controls_wrapper );
148
151
wrapper .setVisibility (View .VISIBLE );
149
- wrapper .setBackgroundColor (mRootViewBackgroundColor );
150
152
LayoutInflater .from (getContext ()).inflate (R .layout .ucrop_controls , wrapper , true );
151
153
152
154
mControlsTransition = new AutoTransition ();
@@ -167,6 +169,10 @@ public void setupViews(View view, Bundle args) {
167
169
setupRotateWidget (view );
168
170
setupScaleWidget (view );
169
171
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 ();
170
176
}
171
177
}
172
178
@@ -296,7 +302,7 @@ public void onLoadFailure(@NonNull Exception e) {
296
302
};
297
303
298
304
/**
299
- * Use {@link #mActiveWidgetColor } for color filter
305
+ * Use {@link #mActiveControlsWidgetColor } for color filter
300
306
*/
301
307
private void setupStatesWrapper (View view ) {
302
308
ImageView stateScaleImageView = view .findViewById (R .id .image_view_state_scale );
@@ -334,7 +340,7 @@ private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) {
334
340
wrapperAspectRatio = (FrameLayout ) getLayoutInflater ().inflate (R .layout .ucrop_aspect_ratio , null );
335
341
wrapperAspectRatio .setLayoutParams (lp );
336
342
aspectRatioTextView = ((AspectRatioTextView ) wrapperAspectRatio .getChildAt (0 ));
337
- aspectRatioTextView .setActiveColor (mActiveWidgetColor );
343
+ aspectRatioTextView .setActiveColor (mActiveControlsWidgetColor );
338
344
aspectRatioTextView .setAspectRatio (aspectRatio );
339
345
340
346
wrapperAspectRatioList .addView (wrapperAspectRatio );
@@ -380,7 +386,7 @@ public void onScrollStart() {
380
386
}
381
387
});
382
388
383
- ((HorizontalProgressWheelView ) view .findViewById (R .id .rotate_scroll_wheel )).setMiddleLineColor (mActiveWidgetColor );
389
+ ((HorizontalProgressWheelView ) view .findViewById (R .id .rotate_scroll_wheel )).setMiddleLineColor (mActiveControlsWidgetColor );
384
390
385
391
386
392
view .findViewById (R .id .wrapper_reset_rotate ).setOnClickListener (new View .OnClickListener () {
@@ -395,6 +401,8 @@ public void onClick(View v) {
395
401
rotateByAngle (90 );
396
402
}
397
403
});
404
+
405
+ setAngleTextColor (mActiveControlsWidgetColor );
398
406
}
399
407
400
408
private void setupScaleWidget (View view ) {
@@ -422,7 +430,9 @@ public void onScrollStart() {
422
430
mGestureCropImageView .cancelAllAnimations ();
423
431
}
424
432
});
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 );
426
436
}
427
437
428
438
private void setAngleText (float angle ) {
@@ -431,12 +441,24 @@ private void setAngleText(float angle) {
431
441
}
432
442
}
433
443
444
+ private void setAngleTextColor (int textColor ) {
445
+ if (mTextViewRotateAngle != null ) {
446
+ mTextViewRotateAngle .setTextColor (textColor );
447
+ }
448
+ }
449
+
434
450
private void setScaleText (float scale ) {
435
451
if (mTextViewScalePercent != null ) {
436
452
mTextViewScalePercent .setText (String .format (Locale .getDefault (), "%d%%" , (int ) (scale * 100 )));
437
453
}
438
454
}
439
455
456
+ private void setScaleTextColor (int textColor ) {
457
+ if (mTextViewScalePercent != null ) {
458
+ mTextViewScalePercent .setTextColor (textColor );
459
+ }
460
+ }
461
+
440
462
private void resetRotation () {
441
463
mGestureCropImageView .postRotate (-mGestureCropImageView .getCurrentAngle ());
442
464
mGestureCropImageView .setImageToWrapCropBounds ();
0 commit comments