Skip to content

Commit

Permalink
Merge pull request #612 from Yalantis/fix/active_color_widget_issue_6…
Browse files Browse the repository at this point in the history
…02_non_native

Implement color applying for scale and angle texts, fixing color appl…
  • Loading branch information
Kirill authored Mar 18, 2020
2 parents 3685a7a + ecd26a6 commit 901f480
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<color name="colorPrimary">#FF6E40</color>
<color name="colorPrimaryDark">#CC5833</color>
<color name="colorAccent">#FF6E40</color>

<color name="your_color_res">#03A9F4</color>
</resources>
10 changes: 1 addition & 9 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 19 additions & 5 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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
Expand Down Expand Up @@ -287,7 +286,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));
Expand Down Expand Up @@ -399,7 +397,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);
Expand Down Expand Up @@ -501,7 +499,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() {
Expand All @@ -516,6 +514,8 @@ public void onClick(View v) {
rotateByAngle(90);
}
});

setAngleTextColor(mActiveControlsWidgetColor);
}

private void setupScaleWidget() {
Expand Down Expand Up @@ -543,7 +543,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) {
Expand All @@ -552,12 +554,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();
Expand Down
28 changes: 21 additions & 7 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public class UCropFragment extends Fragment {
private UCropFragmentCallback callback;

private int mActiveControlsWidgetColor;
private int mActiveWidgetColor;
@ColorInt
private int mRootViewBackgroundColor;
private int mLogoColor;
Expand Down Expand Up @@ -138,8 +137,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));
Expand Down Expand Up @@ -301,7 +299,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);
Expand Down Expand Up @@ -339,7 +337,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);
Expand Down Expand Up @@ -385,7 +383,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() {
Expand All @@ -400,6 +398,8 @@ public void onClick(View v) {
rotateByAngle(90);
}
});

setAngleTextColor(mActiveControlsWidgetColor);
}

private void setupScaleWidget(View view) {
Expand Down Expand Up @@ -427,7 +427,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) {
Expand All @@ -436,12 +438,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void setScrollingListener(ScrollingListener scrollingListener) {

public void setMiddleLineColor(@ColorInt int middleLineColor) {
mMiddleLineColor = middleLineColor;
mProgressMiddleLinePaint.setColor(mMiddleLineColor);
invalidate();
}

Expand Down

0 comments on commit 901f480

Please # to comment.