Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,17 @@ Tune everything (ノ◕ヮ◕)ノ*:・゚✧
options.setCropGridColor(Color.GREEN);
options.setCropGridColumnCount(2);
options.setCropGridRowCount(1);
options.setToolbarCropDrawable(R.drawable.your_crop_icon);
options.setToolbarCancelDrawable(R.drawable.your_cancel_icon);

// 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.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
options.setRootViewBackgroundColor(ContextCompat.getColor(this, R.color.your_color_res));

// Aspect ratio options
// Aspect ratio options
options.setAspectRatioOptions(1,
new AspectRatio("WOW", 1, 2),
new AspectRatio("MUCH", 3, 4),
Expand Down
26 changes: 26 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -242,6 +243,8 @@ public static class Options {

public static final String EXTRA_UCROP_WIDGET_COLOR_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarWidgetColor";
public static final String EXTRA_UCROP_TITLE_TEXT_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarTitleText";
public static final String EXTRA_UCROP_WIDGET_CANCEL_DRAWABLE = EXTRA_PREFIX + ".UcropToolbarCancelDrawable";
public static final String EXTRA_UCROP_WIDGET_CROP_DRAWABLE = EXTRA_PREFIX + ".UcropToolbarCropDrawable";

public static final String EXTRA_UCROP_LOGO_COLOR = EXTRA_PREFIX + ".UcropLogoColor";

Expand All @@ -251,6 +254,8 @@ public static class Options {
public static final String EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT = EXTRA_PREFIX + ".AspectRatioSelectedByDefault";
public static final String EXTRA_ASPECT_RATIO_OPTIONS = EXTRA_PREFIX + ".AspectRatioOptions";

public static final String EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR = EXTRA_PREFIX + ".UcropRootViewBackgroundColor";


private final Bundle mOptionBundle;

Expand Down Expand Up @@ -418,6 +423,20 @@ public void setToolbarTitle(@Nullable String text) {
mOptionBundle.putString(EXTRA_UCROP_TITLE_TEXT_TOOLBAR, text);
}

/**
* @param drawable - desired drawable for the Toolbar left cancel icon
*/
public void setToolbarCancelDrawable(@DrawableRes int drawable) {
mOptionBundle.putInt(EXTRA_UCROP_WIDGET_CANCEL_DRAWABLE, drawable);
}

/**
* @param drawable - desired drawable for the Toolbar right crop icon
*/
public void setToolbarCropDrawable(@DrawableRes int drawable) {
mOptionBundle.putInt(EXTRA_UCROP_WIDGET_CROP_DRAWABLE, drawable);
}

/**
* @param color - desired resolved color of logo fill (default is darker grey)
*/
Expand Down Expand Up @@ -455,6 +474,13 @@ public void setAspectRatioOptions(int selectedByDefault, AspectRatio... aspectRa
mOptionBundle.putParcelableArrayList(EXTRA_ASPECT_RATIO_OPTIONS, new ArrayList<Parcelable>(Arrays.asList(aspectRatio)));
}

/**
* @param color - desired background color that should be applied to the root view
*/
public void setRootViewBackgroundColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR, color);
}

/**
* Set an aspect ratio for crop bounds.
* User won't see the menu with other ratios options.
Expand Down
15 changes: 12 additions & 3 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -83,6 +84,9 @@ public class UCropActivity extends AppCompatActivity {
private int mStatusBarColor;
private int mActiveWidgetColor;
private int mToolbarWidgetColor;
@ColorInt private int mRootViewBackgroundColor;
@DrawableRes private int mToolbarCancelDrawable;
@DrawableRes private int mToolbarCropDrawable;
private int mLogoColor;

private boolean mShowBottomControls;
Expand Down Expand Up @@ -134,7 +138,7 @@ public boolean onCreateOptionsMenu(final Menu menu) {
}

MenuItem menuItemCrop = menu.findItem(R.id.menu_crop);
Drawable menuItemCropIcon = menuItemCrop.getIcon();
Drawable menuItemCropIcon = ContextCompat.getDrawable(this, mToolbarCropDrawable);
if (menuItemCropIcon != null) {
menuItemCropIcon.mutate();
menuItemCropIcon.setColorFilter(mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
Expand Down Expand Up @@ -268,10 +272,13 @@ private void setupViews(@NonNull Intent intent) {
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_active));
mToolbarWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_WIDGET_COLOR_TOOLBAR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar_widget));
mToolbarCancelDrawable = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_WIDGET_CANCEL_DRAWABLE, R.drawable.ucrop_ic_cross);
mToolbarCropDrawable = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_WIDGET_CROP_DRAWABLE, R.drawable.ucrop_ic_done);
mToolbarTitle = intent.getStringExtra(UCrop.Options.EXTRA_UCROP_TITLE_TEXT_TOOLBAR);
mToolbarTitle = !TextUtils.isEmpty(mToolbarTitle) ? mToolbarTitle : getResources().getString(R.string.ucrop_label_edit_photo);
mToolbarTitle = mToolbarTitle != null ? mToolbarTitle : getResources().getString(R.string.ucrop_label_edit_photo);
mLogoColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_LOGO_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_default_logo));
mShowBottomControls = !intent.getBooleanExtra(UCrop.Options.EXTRA_HIDE_BOTTOM_CONTROLS, false);
mRootViewBackgroundColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_crop_background));

setupAppBar();
initiateRootViews();
Expand Down Expand Up @@ -315,7 +322,7 @@ private void setupAppBar() {
toolbarTitle.setText(mToolbarTitle);

// Color buttons inside the Toolbar
Drawable stateButtonDrawable = ContextCompat.getDrawable(this, R.drawable.ucrop_ic_cross).mutate();
Drawable stateButtonDrawable = ContextCompat.getDrawable(this, mToolbarCancelDrawable).mutate();
stateButtonDrawable.setColorFilter(mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(stateButtonDrawable);

Expand All @@ -334,6 +341,8 @@ private void initiateRootViews() {
mGestureCropImageView.setTransformImageListener(mImageListener);

((ImageView) findViewById(R.id.image_view_logo)).setColorFilter(mLogoColor, PorterDuff.Mode.SRC_ATOP);

findViewById(R.id.ucrop_frame).setBackgroundColor(mRootViewBackgroundColor);
}

private TransformImageView.TransformImageListener mImageListener = new TransformImageView.TransformImageListener() {
Expand Down