From 14b38e3d8286b4421004e40ca3424548fb07cba4 Mon Sep 17 00:00:00 2001 From: "marina.racu" Date: Tue, 21 Jan 2020 16:14:53 +0200 Subject: [PATCH] Implement color applying for scale and angle texts, fixing color applying for middle progress wheel line, remove unused method setActiveWidgetColor() which dublicate setActiveControlsWidgetColor() --- .../yalantis/ucrop/sample/SampleActivity.java | 2 +- sample/src/main/res/values/colors.xml | 2 ++ .../main/java/com/yalantis/ucrop/UCrop.java | 10 +------ .../com/yalantis/ucrop/UCropActivity.java | 24 ++++++++++++---- .../com/yalantis/ucrop/UCropFragment.java | 28 ++++++++++++++----- .../widget/HorizontalProgressWheelView.java | 1 + 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/sample/src/main/java/com/yalantis/ucrop/sample/SampleActivity.java b/sample/src/main/java/com/yalantis/ucrop/sample/SampleActivity.java index acd0d13cf..0eca122f4 100644 --- a/sample/src/main/java/com/yalantis/ucrop/sample/SampleActivity.java +++ b/sample/src/main/java/com/yalantis/ucrop/sample/SampleActivity.java @@ -373,9 +373,9 @@ Tune everything (ノ◕ヮ◕)ノ*:・゚✧ // Color palette options.setToolbarColor(ContextCompat.getColor(this, R.color.your_color_res)); options.setStatusBarColor(ContextCompat.getColor(this, R.color.your_color_res)); - options.setActiveWidgetColor(ContextCompat.getColor(this, R.color.your_color_res)); options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.your_color_res)); options.setRootViewBackgroundColor(ContextCompat.getColor(this, R.color.your_color_res)); + options.setActiveControlsWidgetColor(ContextCompat.getColor(this, R.color.your_color_res)); // Aspect ratio options options.setAspectRatioOptions(1, diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml index 6531d5c07..4f44e31ee 100644 --- a/sample/src/main/res/values/colors.xml +++ b/sample/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ #FF6E40 #CC5833 #FF6E40 + + #03A9F4 diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java index e0d423634..878191c1b 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java @@ -261,7 +261,6 @@ public static class Options { public static final String EXTRA_TOOL_BAR_COLOR = EXTRA_PREFIX + ".ToolbarColor"; public static final String EXTRA_STATUS_BAR_COLOR = EXTRA_PREFIX + ".StatusBarColor"; - public static final String EXTRA_UCROP_COLOR_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorWidgetActive"; public static final String EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorControlsWidgetActive"; public static final String EXTRA_UCROP_WIDGET_COLOR_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarWidgetColor"; @@ -426,14 +425,7 @@ public void setStatusBarColor(@ColorInt int color) { } /** - * @param color - desired resolved color of the progress wheel middle line (default is violet) - */ - public void setActiveWidgetColor(@ColorInt int color) { - mOptionBundle.putInt(EXTRA_UCROP_COLOR_WIDGET_ACTIVE, color); - } - - /** - * @param color - desired resolved color of the active and selected widget (default is white) + * @param color - desired resolved color of the active and selected widget and progress wheel middle line (default is white) */ public void setActiveControlsWidgetColor(@ColorInt int color) { mOptionBundle.putInt(EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, color); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java index a48969fcc..1ef17f884 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java @@ -87,7 +87,6 @@ public class UCropActivity extends AppCompatActivity { // Enables dynamic coloring private int mToolbarColor; private int mStatusBarColor; - private int mActiveWidgetColor; private int mActiveControlsWidgetColor; private int mToolbarWidgetColor; @ColorInt @@ -282,7 +281,6 @@ private void processOptions(@NonNull Intent intent) { private void setupViews(@NonNull Intent intent) { mStatusBarColor = intent.getIntExtra(UCrop.Options.EXTRA_STATUS_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_statusbar)); mToolbarColor = intent.getIntExtra(UCrop.Options.EXTRA_TOOL_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar)); - mActiveWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_widget_background)); mActiveControlsWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_active_controls_color)); mToolbarWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_WIDGET_COLOR_TOOLBAR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar_widget)); @@ -394,7 +392,7 @@ public void onLoadFailure(@NonNull Exception e) { }; /** - * Use {@link #mActiveWidgetColor} for color filter + * Use {@link #mActiveControlsWidgetColor} for color filter */ private void setupStatesWrapper() { ImageView stateScaleImageView = findViewById(R.id.image_view_state_scale); @@ -496,7 +494,7 @@ public void onScrollStart() { } }); - ((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor); + ((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor); findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() { @@ -511,6 +509,8 @@ public void onClick(View v) { rotateByAngle(90); } }); + + setAngleTextColor(mActiveControlsWidgetColor); } private void setupScaleWidget() { @@ -538,7 +538,9 @@ public void onScrollStart() { mGestureCropImageView.cancelAllAnimations(); } }); - ((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor); + ((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor); + + setScaleTextColor(mActiveControlsWidgetColor); } private void setAngleText(float angle) { @@ -547,12 +549,24 @@ private void setAngleText(float angle) { } } + private void setAngleTextColor(int textColor) { + if (mTextViewRotateAngle != null) { + mTextViewRotateAngle.setTextColor(textColor); + } + } + private void setScaleText(float scale) { if (mTextViewScalePercent != null) { mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100))); } } + private void setScaleTextColor(int textColor) { + if (mTextViewScalePercent != null) { + mTextViewScalePercent.setTextColor(textColor); + } + } + private void resetRotation() { mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle()); mGestureCropImageView.setImageToWrapCropBounds(); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java index 6d086be4c..455dac924 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java @@ -72,7 +72,6 @@ public class UCropFragment extends Fragment { private UCropFragmentCallback callback; private int mActiveControlsWidgetColor; - private int mActiveWidgetColor; @ColorInt private int mRootViewBackgroundColor; private int mLogoColor; @@ -133,8 +132,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c public void setupViews(View view, Bundle args) { - mActiveWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_background)); - mActiveControlsWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_active)); + mActiveControlsWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_active)); mLogoColor = args.getInt(UCrop.Options.EXTRA_UCROP_LOGO_COLOR, ContextCompat.getColor(getContext(), R.color.ucrop_color_default_logo)); mShowBottomControls = !args.getBoolean(UCrop.Options.EXTRA_HIDE_BOTTOM_CONTROLS, false); mRootViewBackgroundColor = args.getInt(UCrop.Options.EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR, ContextCompat.getColor(getContext(), R.color.ucrop_color_crop_background)); @@ -296,7 +294,7 @@ public void onLoadFailure(@NonNull Exception e) { }; /** - * Use {@link #mActiveWidgetColor} for color filter + * Use {@link #mActiveControlsWidgetColor} for color filter */ private void setupStatesWrapper(View view) { ImageView stateScaleImageView = view.findViewById(R.id.image_view_state_scale); @@ -334,7 +332,7 @@ private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) { wrapperAspectRatio = (FrameLayout) getLayoutInflater().inflate(R.layout.ucrop_aspect_ratio, null); wrapperAspectRatio.setLayoutParams(lp); aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0)); - aspectRatioTextView.setActiveColor(mActiveWidgetColor); + aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor); aspectRatioTextView.setAspectRatio(aspectRatio); wrapperAspectRatioList.addView(wrapperAspectRatio); @@ -380,7 +378,7 @@ public void onScrollStart() { } }); - ((HorizontalProgressWheelView) view.findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor); + ((HorizontalProgressWheelView) view.findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor); view.findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() { @@ -395,6 +393,8 @@ public void onClick(View v) { rotateByAngle(90); } }); + + setAngleTextColor(mActiveControlsWidgetColor); } private void setupScaleWidget(View view) { @@ -422,7 +422,9 @@ public void onScrollStart() { mGestureCropImageView.cancelAllAnimations(); } }); - ((HorizontalProgressWheelView) view.findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor); + ((HorizontalProgressWheelView) view.findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor); + + setScaleTextColor(mActiveControlsWidgetColor); } private void setAngleText(float angle) { @@ -431,12 +433,24 @@ private void setAngleText(float angle) { } } + private void setAngleTextColor(int textColor) { + if (mTextViewRotateAngle != null) { + mTextViewRotateAngle.setTextColor(textColor); + } + } + private void setScaleText(float scale) { if (mTextViewScalePercent != null) { mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100))); } } + private void setScaleTextColor(int textColor) { + if (mTextViewScalePercent != null) { + mTextViewScalePercent.setTextColor(textColor); + } + } + private void resetRotation() { mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle()); mGestureCropImageView.setImageToWrapCropBounds(); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/view/widget/HorizontalProgressWheelView.java b/ucrop/src/main/java/com/yalantis/ucrop/view/widget/HorizontalProgressWheelView.java index fc7d9b3d8..756765841 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/view/widget/HorizontalProgressWheelView.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/view/widget/HorizontalProgressWheelView.java @@ -59,6 +59,7 @@ public void setScrollingListener(ScrollingListener scrollingListener) { public void setMiddleLineColor(@ColorInt int middleLineColor) { mMiddleLineColor = middleLineColor; + mProgressMiddleLinePaint.setColor(mMiddleLineColor); invalidate(); }