2020
2121import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
2222
23+ import android .content .Context ;
2324import android .content .res .ColorStateList ;
2425import android .content .res .TypedArray ;
2526import android .graphics .Color ;
@@ -70,10 +71,12 @@ class MaterialButtonHelper {
7071 private boolean cornerRadiusSet = false ;
7172 private boolean checkable ;
7273 private LayerDrawable rippleDrawable ;
74+ private boolean cornerAdjustmentEnabled ;
7375
7476 MaterialButtonHelper (MaterialButton button , @ NonNull ShapeAppearanceModel shapeAppearanceModel ) {
7577 materialButton = button ;
7678 this .shapeAppearanceModel = shapeAppearanceModel ;
79+ cornerAdjustmentEnabled = CornerAdjustmentFlag .isEnabled (button .getContext ());
7780 }
7881
7982 void loadFromAttributes (@ NonNull TypedArray attributes ) {
@@ -192,7 +195,8 @@ void setShouldDrawSurfaceColorStroke(boolean shouldDrawSurfaceColorStroke) {
192195 */
193196 private Drawable createBackground () {
194197 MaterialShapeDrawable backgroundDrawable = new MaterialShapeDrawable (shapeAppearanceModel );
195- backgroundDrawable .initializeElevationOverlay (materialButton .getContext ());
198+ Context context = materialButton .getContext ();
199+ backgroundDrawable .initializeElevationOverlay (context );
196200 DrawableCompat .setTintList (backgroundDrawable , backgroundTint );
197201 if (backgroundTintMode != null ) {
198202 DrawableCompat .setTintMode (backgroundDrawable , backgroundTintMode );
@@ -210,7 +214,7 @@ private Drawable createBackground() {
210214
211215 if (IS_LOLLIPOP ) {
212216 maskDrawable = new MaterialShapeDrawable (shapeAppearanceModel );
213- if (strokeWidth > 0 ) {
217+ if (strokeWidth > 0 && cornerAdjustmentEnabled ) {
214218 ShapeAppearanceModel adjustedShapeAppearanceModel =
215219 adjustShapeAppearanceModelCornerRadius (shapeAppearanceModel , strokeWidth / 2f );
216220 backgroundDrawable .setShapeAppearanceModel (adjustedShapeAppearanceModel );
@@ -304,7 +308,7 @@ private void updateStroke() {
304308 ? MaterialColors .getColor (materialButton , R .attr .colorSurface )
305309 : Color .TRANSPARENT );
306310 }
307- if (IS_LOLLIPOP ) {
311+ if (IS_LOLLIPOP && cornerAdjustmentEnabled ) {
308312 ShapeAppearanceModel shapeAppearance =
309313 adjustShapeAppearanceModelCornerRadius (shapeAppearanceModel , strokeWidth / 2f );
310314 updateButtonShape (shapeAppearance );
@@ -322,8 +326,10 @@ void setCornerRadius(int cornerRadius) {
322326 if (!cornerRadiusSet || this .cornerRadius != cornerRadius ) {
323327 this .cornerRadius = cornerRadius ;
324328 cornerRadiusSet = true ;
329+
325330 setShapeAppearanceModel (
326- shapeAppearanceModel .withCornerRadius (cornerRadius + (strokeWidth / 2f )));
331+ shapeAppearanceModel .withCornerRadius (
332+ cornerAdjustmentEnabled ? cornerRadius + (strokeWidth / 2f ) : cornerRadius ));
327333 }
328334 }
329335
0 commit comments