Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a method to set title size and alignment mode #796

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public static class Options {
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";
public static final String EXTRA_UCROP_TITLE_GRAVITY_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarTitleGravity";
public static final String EXTRA_UCROP_TITLE_SIZE_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarTitleSize";
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";
Expand Down Expand Up @@ -314,7 +316,7 @@ public Bundle getOptionBundle() {
}

/**
* Set one of {@link android.graphics.Bitmap.CompressFormat} that will be used to save resulting Bitmap.
* Set one of {@link Bitmap.CompressFormat} that will be used to save resulting Bitmap.
*/
public void setCompressionFormat(@NonNull Bitmap.CompressFormat format) {
mOptionBundle.putString(EXTRA_COMPRESSION_FORMAT_NAME, format.name());
Expand Down Expand Up @@ -468,6 +470,21 @@ public void setToolbarWidgetColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_UCROP_WIDGET_COLOR_TOOLBAR, color);
}

/**
* @param gravity - desired text for Toolbar title alignment mode
* @see android.view.Gravity
*/
public void setToolbarTitleTextGravity(@Nullable int gravity) {
mOptionBundle.putInt(EXTRA_UCROP_TITLE_GRAVITY_TOOLBAR, gravity);
}

/**
* @param textSize - desired text for Toolbar title text size
*/
public void setToolbarTitleTextSize(@Nullable Float textSize) {
mOptionBundle.putFloat(EXTRA_UCROP_TITLE_SIZE_TOOLBAR, textSize);
}

/**
* @param text - desired text for Toolbar title
*/
Expand Down
34 changes: 26 additions & 8 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -82,8 +83,14 @@ public class UCropActivity extends AppCompatActivity {
private static final int TABS_COUNT = 3;
private static final int SCALE_WIDGET_SENSITIVITY_COEFFICIENT = 15000;
private static final int ROTATE_WIDGET_SENSITIVITY_COEFFICIENT = 42;
private static final float DEFAULT_TOOLBAR_TEXT_SIZE = 14F;
private static final int DEFAULT_TOOLBAR_GRAVITY = Gravity.START;

private String mToolbarTitle;
// Toolbar title alignment mode
private int mToolbarGravity = DEFAULT_TOOLBAR_GRAVITY;
// Toolbar title text size
private Float mToolbarTextSize = DEFAULT_TOOLBAR_TEXT_SIZE;

// Enables dynamic coloring
private int mToolbarColor;
Expand All @@ -102,6 +109,8 @@ public class UCropActivity extends AppCompatActivity {
private boolean mShowLoader = true;

private UCropView mUCropView;
private TextView mToolbarTextView;
private Toolbar mToolbarView;
private GestureCropImageView mGestureCropImageView;
private OverlayView mOverlayView;
private ViewGroup mWrapperStateAspectRatio, mWrapperStateRotate, mWrapperStateScale;
Expand Down Expand Up @@ -290,6 +299,8 @@ private void setupViews(@NonNull Intent intent) {
mToolbarColor = intent.getIntExtra(UCrop.Options.EXTRA_TOOL_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar));
mActiveControlsWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_active_controls_color));

mToolbarGravity = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_TITLE_GRAVITY_TOOLBAR, Gravity.START);
mToolbarTextSize = intent.getFloatExtra(UCrop.Options.EXTRA_UCROP_TITLE_SIZE_TOOLBAR, 20F);
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);
Expand Down Expand Up @@ -336,22 +347,29 @@ private void setupViews(@NonNull Intent intent) {
private void setupAppBar() {
setStatusBarColor(mStatusBarColor);

final Toolbar toolbar = findViewById(R.id.toolbar);
mToolbarView = findViewById(R.id.toolbar);

// Set all of the Toolbar coloring
toolbar.setBackgroundColor(mToolbarColor);
toolbar.setTitleTextColor(mToolbarWidgetColor);
mToolbarView.setBackgroundColor(mToolbarColor);
mToolbarView.setTitleTextColor(mToolbarWidgetColor);

final TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
toolbarTitle.setTextColor(mToolbarWidgetColor);
toolbarTitle.setText(mToolbarTitle);
mToolbarTextView = mToolbarView.findViewById(R.id.toolbar_title);
//Set the title size
mToolbarTextView.setTextSize(mToolbarTextSize);
mToolbarTextView.setTextColor(mToolbarWidgetColor);
mToolbarTextView.setText(mToolbarTitle);

//Set the title alignment mode
Toolbar.LayoutParams lp = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.WRAP_CONTENT);
lp.gravity = mToolbarGravity;
mToolbarTextView.setLayoutParams(lp);

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

setSupportActionBar(toolbar);
setSupportActionBar(mToolbarView);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
Expand Down