20
20
21
21
import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
22
22
23
+ import android .content .Context ;
23
24
import android .content .res .ColorStateList ;
24
25
import android .content .res .TypedArray ;
25
26
import android .graphics .Color ;
@@ -70,10 +71,12 @@ class MaterialButtonHelper {
70
71
private boolean cornerRadiusSet = false ;
71
72
private boolean checkable ;
72
73
private LayerDrawable rippleDrawable ;
74
+ private boolean cornerAdjustmentEnabled ;
73
75
74
76
MaterialButtonHelper (MaterialButton button , @ NonNull ShapeAppearanceModel shapeAppearanceModel ) {
75
77
materialButton = button ;
76
78
this .shapeAppearanceModel = shapeAppearanceModel ;
79
+ cornerAdjustmentEnabled = CornerAdjustmentFlag .isEnabled (button .getContext ());
77
80
}
78
81
79
82
void loadFromAttributes (@ NonNull TypedArray attributes ) {
@@ -192,7 +195,8 @@ void setShouldDrawSurfaceColorStroke(boolean shouldDrawSurfaceColorStroke) {
192
195
*/
193
196
private Drawable createBackground () {
194
197
MaterialShapeDrawable backgroundDrawable = new MaterialShapeDrawable (shapeAppearanceModel );
195
- backgroundDrawable .initializeElevationOverlay (materialButton .getContext ());
198
+ Context context = materialButton .getContext ();
199
+ backgroundDrawable .initializeElevationOverlay (context );
196
200
DrawableCompat .setTintList (backgroundDrawable , backgroundTint );
197
201
if (backgroundTintMode != null ) {
198
202
DrawableCompat .setTintMode (backgroundDrawable , backgroundTintMode );
@@ -210,7 +214,7 @@ private Drawable createBackground() {
210
214
211
215
if (IS_LOLLIPOP ) {
212
216
maskDrawable = new MaterialShapeDrawable (shapeAppearanceModel );
213
- if (strokeWidth > 0 ) {
217
+ if (strokeWidth > 0 && cornerAdjustmentEnabled ) {
214
218
ShapeAppearanceModel adjustedShapeAppearanceModel =
215
219
adjustShapeAppearanceModelCornerRadius (shapeAppearanceModel , strokeWidth / 2f );
216
220
backgroundDrawable .setShapeAppearanceModel (adjustedShapeAppearanceModel );
@@ -304,7 +308,7 @@ private void updateStroke() {
304
308
? MaterialColors .getColor (materialButton , R .attr .colorSurface )
305
309
: Color .TRANSPARENT );
306
310
}
307
- if (IS_LOLLIPOP ) {
311
+ if (IS_LOLLIPOP && cornerAdjustmentEnabled ) {
308
312
ShapeAppearanceModel shapeAppearance =
309
313
adjustShapeAppearanceModelCornerRadius (shapeAppearanceModel , strokeWidth / 2f );
310
314
updateButtonShape (shapeAppearance );
@@ -322,8 +326,10 @@ void setCornerRadius(int cornerRadius) {
322
326
if (!cornerRadiusSet || this .cornerRadius != cornerRadius ) {
323
327
this .cornerRadius = cornerRadius ;
324
328
cornerRadiusSet = true ;
329
+
325
330
setShapeAppearanceModel (
326
- shapeAppearanceModel .withCornerRadius (cornerRadius + (strokeWidth / 2f )));
331
+ shapeAppearanceModel .withCornerRadius (
332
+ cornerAdjustmentEnabled ? cornerRadius + (strokeWidth / 2f ) : cornerRadius ));
327
333
}
328
334
}
329
335
0 commit comments