Skip to content

Commit be723b2

Browse files
committed
Fallback logic for button shape update logic for lollipop
1 parent 6b45884 commit be723b2

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/java/com/google/android/material/button/MaterialButtonHelper.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
@RestrictTo(LIBRARY_GROUP)
5252
class MaterialButtonHelper {
5353

54-
private static final boolean IS_LOLLIPOP = VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP;
54+
private static final boolean IS_MIN_LOLLIPOP = VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP;
55+
private static final boolean IS_LOLLIPOP = VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP &&
56+
VERSION.SDK_INT <= VERSION_CODES.LOLLIPOP_MR1;
5557
private final MaterialButton materialButton;
5658
@NonNull private ShapeAppearanceModel shapeAppearanceModel;
5759

@@ -219,7 +221,7 @@ private Drawable createBackground() {
219221
? MaterialColors.getColor(materialButton, R.attr.colorSurface)
220222
: Color.TRANSPARENT);
221223

222-
if (IS_LOLLIPOP) {
224+
if (IS_MIN_LOLLIPOP) {
223225
maskDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
224226
DrawableCompat.setTint(maskDrawable, Color.WHITE);
225227
rippleDrawable =
@@ -256,10 +258,10 @@ void setBackgroundColor(int color) {
256258
void setRippleColor(@Nullable ColorStateList rippleColor) {
257259
if (this.rippleColor != rippleColor) {
258260
this.rippleColor = rippleColor;
259-
if (IS_LOLLIPOP && materialButton.getBackground() instanceof RippleDrawable) {
261+
if (IS_MIN_LOLLIPOP && materialButton.getBackground() instanceof RippleDrawable) {
260262
((RippleDrawable) materialButton.getBackground())
261263
.setColor(RippleUtils.sanitizeRippleDrawableColor(rippleColor));
262-
} else if (!IS_LOLLIPOP && materialButton.getBackground() instanceof RippleDrawableCompat) {
264+
} else if (!IS_MIN_LOLLIPOP && materialButton.getBackground() instanceof RippleDrawableCompat) {
263265
((RippleDrawableCompat) materialButton.getBackground()).setTintList(
264266
RippleUtils.sanitizeRippleDrawableColor(rippleColor));
265267
}
@@ -327,7 +329,7 @@ int getCornerRadius() {
327329
@Nullable
328330
private MaterialShapeDrawable getMaterialShapeDrawable(boolean getSurfaceColorStrokeDrawable) {
329331
if (rippleDrawable != null && rippleDrawable.getNumberOfLayers() > 0) {
330-
if (IS_LOLLIPOP) {
332+
if (IS_MIN_LOLLIPOP) {
331333
InsetDrawable insetDrawable = (InsetDrawable) rippleDrawable.getDrawable(0);
332334
LayerDrawable layerDrawable = (LayerDrawable) insetDrawable.getDrawable();
333335
return (MaterialShapeDrawable)

lib/javatests/com/google/android/material/button/MaterialButtonTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import android.content.Context;
2323
import android.graphics.drawable.Drawable;
2424
import androidx.core.graphics.drawable.DrawableCompat;
25+
26+
import android.os.Build;
2527
import android.view.View.MeasureSpec;
2628
import androidx.annotation.Nullable;
2729
import androidx.core.content.ContextCompat;
@@ -64,9 +66,23 @@ public void testSetShapeAppearanceModel_setCornerRadius() {
6466

6567
ShapeAppearanceModel newShapeAppearanceModel = materialButton.getShapeAppearanceModel();
6668

69+
assertThat(shapeAppearanceModel).isSameInstanceAs(newShapeAppearanceModel);
6770
assertThatCornerSizesMatch(shapeAppearanceModel, newShapeAppearanceModel);
6871
}
6972

73+
@Test
74+
@Config(sdk = Build.VERSION_CODES.LOLLIPOP)
75+
public void testShapeRippleDrawableInLollipop() {
76+
MaterialButton materialButton = new MaterialButton(context);
77+
ShapeAppearanceModel shapeAppearanceModel = materialButton.getShapeAppearanceModel();
78+
79+
materialButton.setCornerRadius((int) LARGE_CORNER_SIZE);
80+
ShapeAppearanceModel newShapeAppearanceModel = materialButton.getShapeAppearanceModel();
81+
assertThat(shapeAppearanceModel).isNotSameInstanceAs(newShapeAppearanceModel);
82+
assertThat(shapeAppearanceModel).isNotEqualTo(newShapeAppearanceModel);
83+
}
84+
85+
7086
@Test
7187
public void testSetShapeAppearanceModel() {
7288
MaterialButton materialButton = new MaterialButton(context);

0 commit comments

Comments
 (0)