Skip to content

Commit

Permalink
enable toggle ratio setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mushroom0210 committed Aug 7, 2024
1 parent 10db399 commit fbf6b71
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public static class Options {

public static final String EXTRA_MIN_ASPECT_RATIO = EXTRA_PREFIX + ".MinAspectRatio";
public static final String EXTRA_MAX_ASPECT_RATIO = EXTRA_PREFIX + ".MaxAspectRatio";
public static final String EXTRA_TOGGLE_RATIO = EXTRA_PREFIX + ".ToggleRatio";

private final Bundle mOptionBundle;

Expand Down Expand Up @@ -531,6 +532,10 @@ public void setMinAspectRatio(float x, float y) {
mOptionBundle.putFloat(EXTRA_MIN_ASPECT_RATIO, x / y);
}

public void setToggleRatioEnabled(boolean enabled) {
mOptionBundle.putBoolean(EXTRA_TOGGLE_RATIO, enabled);
}

/**
* Pass an ordered list of desired aspect ratios that should be available for a user.
*
Expand Down
2 changes: 2 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ private void setStatusBarColor(@ColorInt int color) {
}

private void setupAspectRatioWidget(@NonNull Intent intent) {
boolean toggleRatioEnabled = intent.getBooleanExtra(UCrop.Options.EXTRA_TOGGLE_RATIO, true);

int aspectRationSelectedByDefault = intent.getIntExtra(UCrop.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
ArrayList<AspectRatio> aspectRatioList = intent.getParcelableArrayListExtra(UCrop.Options.EXTRA_ASPECT_RATIO_OPTIONS);
Expand Down Expand Up @@ -470,6 +471,7 @@ private void setupAspectRatioWidget(@NonNull Intent intent) {
aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0));
aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor);
aspectRatioTextView.setAspectRatio(aspectRatio);
aspectRatioTextView.setToggleRatioEnabled(toggleRatioEnabled);

wrapperAspectRatioList.addView(wrapperAspectRatio);
mCropAspectRatioViews.add(wrapperAspectRatio);
Expand Down
3 changes: 3 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ private void setupStatesWrapper(View view) {
}

private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) {
boolean toggleRatioEnabled = bundle.getBoolean(UCrop.Options.EXTRA_TOGGLE_RATIO, true);

int aspectRationSelectedByDefault = bundle.getInt(UCrop.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
ArrayList<AspectRatio> aspectRatioList = bundle.getParcelableArrayList(UCrop.Options.EXTRA_ASPECT_RATIO_OPTIONS);

Expand Down Expand Up @@ -353,6 +355,7 @@ private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) {
aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0));
aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor);
aspectRatioTextView.setAspectRatio(aspectRatio);
aspectRatioTextView.setToggleRatioEnabled(toggleRatioEnabled);

wrapperAspectRatioList.addView(wrapperAspectRatio);
mCropAspectRatioViews.add(wrapperAspectRatio);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class AspectRatioTextView extends AppCompatTextView {
private String mAspectRatioTitle;
private float mAspectRatioX, mAspectRatioY;

private boolean mToggleRatioEnabled = true;

public AspectRatioTextView(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -76,13 +78,16 @@ public void setAspectRatio(@NonNull AspectRatio aspectRatio) {
}

public float getAspectRatio(boolean toggleRatio) {
if (toggleRatio) {
if (toggleRatio && mToggleRatioEnabled) {
toggleAspectRatio();
setTitle();
}
return mAspectRatio;
}

public void setToggleRatioEnabled(boolean enabled) {
mToggleRatioEnabled = enabled;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand Down

0 comments on commit fbf6b71

Please sign in to comment.