Skip to content

Commit

Permalink
[TextInputLayout] Fixed getBoxCornerRadiusBottomEnd and getBoxCornerR…
Browse files Browse the repository at this point in the history
…adiusBottomStart returning wrong values.

PiperOrigin-RevId: 406360531
  • Loading branch information
leticiarossi authored and veganafro committed Oct 29, 2021
1 parent c352dfd commit 9d2f864
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
Expand Up @@ -1295,14 +1295,14 @@ public void setBoxCornerRadii(
if (boxBackground == null
|| boxBackground.getTopLeftCornerResolvedSize() != boxCornerRadiusTopStart
|| boxBackground.getTopRightCornerResolvedSize() != boxCornerRadiusTopEnd
|| boxBackground.getBottomRightCornerResolvedSize() != boxCornerRadiusBottomEnd
|| boxBackground.getBottomLeftCornerResolvedSize() != boxCornerRadiusBottomStart) {
|| boxBackground.getBottomLeftCornerResolvedSize() != boxCornerRadiusBottomStart
|| boxBackground.getBottomRightCornerResolvedSize() != boxCornerRadiusBottomEnd) {
shapeAppearanceModel =
shapeAppearanceModel.toBuilder()
.setTopLeftCornerSize(boxCornerRadiusTopStart)
.setTopRightCornerSize(boxCornerRadiusTopEnd)
.setBottomRightCornerSize(boxCornerRadiusBottomEnd)
.setBottomLeftCornerSize(boxCornerRadiusBottomStart)
.setBottomRightCornerSize(boxCornerRadiusBottomEnd)
.build();
applyBoxAttributes();
}
Expand Down Expand Up @@ -1335,7 +1335,7 @@ public float getBoxCornerRadiusTopEnd() {
* @see #setBoxCornerRadii(float, float, float, float)
*/
public float getBoxCornerRadiusBottomEnd() {
return boxBackground.getBottomLeftCornerResolvedSize();
return boxBackground.getBottomRightCornerResolvedSize();
}

/**
Expand All @@ -1345,7 +1345,7 @@ public float getBoxCornerRadiusBottomEnd() {
* @see #setBoxCornerRadii(float, float, float, float)
*/
public float getBoxCornerRadiusBottomStart() {
return boxBackground.getBottomRightCornerResolvedSize();
return boxBackground.getBottomLeftCornerResolvedSize();
}

/**
Expand Down
Expand Up @@ -641,8 +641,8 @@ public void perform(UiController uiController, View view) {
public static ViewAction setBoxCornerRadii(
final float topLeftCornerRadius,
final float topRightCornerRadius,
final float bottomRightCornerRadius,
final float bottomLeftCornerRadius) {
final float bottomLeftCornerRadius,
final float bottomRightCornerRadius) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
Expand All @@ -660,17 +660,17 @@ public void perform(UiController uiController, View view) {
layout.setBoxCornerRadii(
topLeftCornerRadius,
topRightCornerRadius,
bottomRightCornerRadius,
bottomLeftCornerRadius);
bottomLeftCornerRadius,
bottomRightCornerRadius);
}
};
}

public static ViewAction setBoxCornerRadii(
@DimenRes final int topLeftCornerRadiusId,
@DimenRes final int topRightCornerRadiusId,
@DimenRes final int bottomRightCornerRadiusId,
@DimenRes final int bottomLeftCornerRadiusId) {
@DimenRes final int bottomLeftCornerRadiusId,
@DimenRes final int bottomRightCornerRadiusId) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
Expand All @@ -688,8 +688,8 @@ public void perform(UiController uiController, View view) {
layout.setBoxCornerRadiiResources(
topLeftCornerRadiusId,
topRightCornerRadiusId,
bottomRightCornerRadiusId,
bottomLeftCornerRadiusId);
bottomLeftCornerRadiusId,
bottomRightCornerRadiusId);
}
};
}
Expand Down
Expand Up @@ -48,6 +48,7 @@
import static com.google.android.material.testutils.TextInputLayoutActions.setHintTextAppearance;
import static com.google.android.material.testutils.TextInputLayoutActions.setPlaceholderText;
import static com.google.android.material.testutils.TextInputLayoutActions.setTypeface;
import static com.google.common.truth.Truth.assertThat;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -687,6 +688,29 @@ public void testFilledBoxBackgroundChangesColor() {
onView(withId(R.id.textinput_box_filled)).check(isBoxBackgroundColor(yellow));
}

@Test
public void testSetBoxCornerRadii() {
float boxCornerRadiusTopStart = 0.5f;
float boxCornerRadiusTopEnd = 1f;
float boxCornerRadiusBottomStart = 1.5f;
float boxCornerRadiusBottomEnd = 2f;

// Set the outline box's corner radii.
onView(withId(R.id.textinput_box_outline))
.perform(
setBoxCornerRadii(
boxCornerRadiusTopStart,
boxCornerRadiusTopEnd,
boxCornerRadiusBottomStart,
boxCornerRadiusBottomEnd));

// Assert values match each respective corner.
onView(withId(R.id.textinput_box_outline)).check(isBoxCornerRadiusTopStart(boxCornerRadiusTopStart));
onView(withId(R.id.textinput_box_outline)).check(isBoxCornerRadiusTopEnd(boxCornerRadiusTopEnd));
onView(withId(R.id.textinput_box_outline)).check(isBoxCornerRadiusBottomStart(boxCornerRadiusBottomStart));
onView(withId(R.id.textinput_box_outline)).check(isBoxCornerRadiusBottomEnd(boxCornerRadiusBottomEnd));
}

@Test
public void testBoxTopEndCornerRadiusChangesWithFloatValue() {
float cornerRadiusSmall =
Expand Down Expand Up @@ -801,14 +825,41 @@ private static ViewAssertion isBoxBackgroundColor(@ColorInt final int boxBackgro
};
}

private static ViewAssertion isBoxCornerRadiusTopStart(final float boxCornerRadiusTopStart) {
return (view, noViewFoundException) -> {
assertThat(view).isInstanceOf(TextInputLayout.class);
assertEquals(
boxCornerRadiusTopStart, ((TextInputLayout) view).getBoxCornerRadiusTopStart(), 0.01);
};
}

private static ViewAssertion isBoxCornerRadiusTopEnd(final float boxCornerRadiusTopEnd) {
return (view, noViewFoundException) -> {
assertTrue(view instanceof TextInputLayout);
assertThat(view).isInstanceOf(TextInputLayout.class);
assertEquals(
boxCornerRadiusTopEnd, ((TextInputLayout) view).getBoxCornerRadiusTopEnd(), 0.01);
};
}

private static ViewAssertion isBoxCornerRadiusBottomEnd(final float boxCornerRadiusBottomEnd) {
return (view, noViewFoundException) -> {
assertThat(view).isInstanceOf(TextInputLayout.class);
assertEquals(
boxCornerRadiusBottomEnd, ((TextInputLayout) view).getBoxCornerRadiusBottomEnd(), 0.01);
};
}

private static ViewAssertion isBoxCornerRadiusBottomStart(
final float boxCornerRadiusBottomStart) {
return (view, noViewFoundException) -> {
assertThat(view).isInstanceOf(TextInputLayout.class);
assertEquals(
boxCornerRadiusBottomStart,
((TextInputLayout) view).getBoxCornerRadiusBottomStart(),
0.01);
};
}

private static ViewAssertion isCutoutOpen(final boolean open) {
return (view, noViewFoundException) -> {
assertTrue(view instanceof TextInputLayout);
Expand Down

0 comments on commit 9d2f864

Please sign in to comment.