2424import android .content .Context ;
2525import android .content .res .ColorStateList ;
2626import android .content .res .TypedArray ;
27- import android .graphics .Canvas ;
2827import android .graphics .Paint ;
2928import android .graphics .PorterDuff ;
3029import android .graphics .PorterDuff .Mode ;
4241import com .google .android .material .internal .ThemeEnforcement ;
4342import com .google .android .material .internal .ViewUtils ;
4443import com .google .android .material .resources .MaterialResources ;
44+ import com .google .android .material .shape .ShapeAppearanceModel ;
4545import android .support .v4 .graphics .drawable .DrawableCompat ;
4646import android .support .v4 .view .ViewCompat ;
4747import android .support .v4 .widget .TextViewCompat ;
@@ -156,9 +156,11 @@ public MaterialButton(Context context, AttributeSet attrs, int defStyleAttr) {
156156 iconGravity = attributes .getInteger (R .styleable .MaterialButton_iconGravity , ICON_GRAVITY_START );
157157
158158 iconSize = attributes .getDimensionPixelSize (R .styleable .MaterialButton_iconSize , 0 );
159+ ShapeAppearanceModel shapeAppearanceModel =
160+ new ShapeAppearanceModel (context , attrs , defStyleAttr , DEF_STYLE_RES );
159161
160162 // Loads and sets background drawable attributes
161- materialButtonHelper = new MaterialButtonHelper (this );
163+ materialButtonHelper = new MaterialButtonHelper (this , shapeAppearanceModel );
162164 materialButtonHelper .loadFromAttributes (attributes );
163165
164166 attributes .recycle ();
@@ -167,15 +169,6 @@ public MaterialButton(Context context, AttributeSet attrs, int defStyleAttr) {
167169 updateIcon ();
168170 }
169171
170- @ Override
171- protected void onDraw (Canvas canvas ) {
172- super .onDraw (canvas );
173- // Manually draw stroke on top of background for Kit Kat (API 19) and earlier versions
174- if (VERSION .SDK_INT < VERSION_CODES .LOLLIPOP && isUsingOriginalBackground ()) {
175- materialButtonHelper .drawStroke (canvas );
176- }
177- }
178-
179172 /**
180173 * This should be accessed via {@link
181174 * android.support.v4.view.ViewCompat#setBackgroundTintList(android.view.View, ColorStateList)}
@@ -187,7 +180,7 @@ protected void onDraw(Canvas canvas) {
187180 public void setSupportBackgroundTintList (@ Nullable ColorStateList tint ) {
188181 if (isUsingOriginalBackground ()) {
189182 materialButtonHelper .setSupportBackgroundTintList (tint );
190- } else if ( materialButtonHelper != null ) {
183+ } else {
191184 // If default MaterialButton background has been overwritten, we will let AppCompatButton
192185 // handle the tinting
193186 super .setSupportBackgroundTintList (tint );
@@ -225,7 +218,7 @@ public ColorStateList getSupportBackgroundTintList() {
225218 public void setSupportBackgroundTintMode (@ Nullable PorterDuff .Mode tintMode ) {
226219 if (isUsingOriginalBackground ()) {
227220 materialButtonHelper .setSupportBackgroundTintMode (tintMode );
228- } else if ( materialButtonHelper != null ) {
221+ } else {
229222 // If default MaterialButton background has been overwritten, we will let AppCompatButton
230223 // handle the tint Mode
231224 super .setSupportBackgroundTintMode (tintMode );
0 commit comments