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 1 commit
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
32 changes: 23 additions & 9 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 @@ -84,6 +85,8 @@ public class UCropActivity extends AppCompatActivity {
private static final int ROTATE_WIDGET_SENSITIVITY_COEFFICIENT = 42;

private String mToolbarTitle;
private int mGravity = Gravity.START;
private Float mToolbarTextSize = 14F;
hexianqiao3755 marked this conversation as resolved.
Show resolved Hide resolved

// Enables dynamic coloring
private int mToolbarColor;
Expand All @@ -102,6 +105,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 @@ -212,7 +217,7 @@ private void setImageData(@NonNull Intent intent) {
}

/**
* This method extracts {@link com.yalantis.ucrop.UCrop.Options #optionsBundle} from incoming intent
* This method extracts {@link UCrop.Options #optionsBundle} from incoming intent
* and setups Activity, {@link OverlayView} and {@link CropImageView} properly.
*/
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -289,6 +294,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));

mGravity = 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 @@ -335,22 +342,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 = mGravity;
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