Skip to content

Commit 18d4e6b

Browse files
ymarianldjcmu
authored andcommitted
Remove corner adjustment from MaterialButton and ExtendedFloatingActionButton.
ExtendedFloatingActionButton extends from MaterialButton so removing MaterialButton's corner size adjustment removes the adjustment from ExtendedFloatingActionButton, as well. PiperOrigin-RevId: 268282804 (cherry picked from commit ca2db83)
1 parent f9e5bfd commit 18d4e6b

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.material.button;
18+
19+
import android.content.Context;
20+
import java.util.HashSet;
21+
import java.util.Set;
22+
23+
/**
24+
* A class to control whether corner adjustment is enable or not.
25+
*/
26+
class CornerAdjustmentFlag {
27+
28+
private CornerAdjustmentFlag() {}
29+
30+
static boolean isEnabled(Context context) {
31+
return false;
32+
}
33+
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
2222

23+
import android.content.Context;
2324
import android.content.res.ColorStateList;
2425
import android.content.res.TypedArray;
2526
import 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

Comments
 (0)