Skip to content

Commit

Permalink
Remove corner adjustment from MaterialButton and ExtendedFloatingActi…
Browse files Browse the repository at this point in the history
…onButton.

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)
  • Loading branch information
ymarian authored and ldjcmu committed Oct 4, 2019
1 parent f9e5bfd commit 18d4e6b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.material.button;

import android.content.Context;
import java.util.HashSet;
import java.util.Set;

/**
* A class to control whether corner adjustment is enable or not.
*/
class CornerAdjustmentFlag {

private CornerAdjustmentFlag() {}

static boolean isEnabled(Context context) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
Expand Down Expand Up @@ -70,10 +71,12 @@ class MaterialButtonHelper {
private boolean cornerRadiusSet = false;
private boolean checkable;
private LayerDrawable rippleDrawable;
private boolean cornerAdjustmentEnabled;

MaterialButtonHelper(MaterialButton button, @NonNull ShapeAppearanceModel shapeAppearanceModel) {
materialButton = button;
this.shapeAppearanceModel = shapeAppearanceModel;
cornerAdjustmentEnabled = CornerAdjustmentFlag.isEnabled(button.getContext());
}

void loadFromAttributes(@NonNull TypedArray attributes) {
Expand Down Expand Up @@ -192,7 +195,8 @@ void setShouldDrawSurfaceColorStroke(boolean shouldDrawSurfaceColorStroke) {
*/
private Drawable createBackground() {
MaterialShapeDrawable backgroundDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
backgroundDrawable.initializeElevationOverlay(materialButton.getContext());
Context context = materialButton.getContext();
backgroundDrawable.initializeElevationOverlay(context);
DrawableCompat.setTintList(backgroundDrawable, backgroundTint);
if (backgroundTintMode != null) {
DrawableCompat.setTintMode(backgroundDrawable, backgroundTintMode);
Expand All @@ -210,7 +214,7 @@ private Drawable createBackground() {

if (IS_LOLLIPOP) {
maskDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
if (strokeWidth > 0) {
if (strokeWidth > 0 && cornerAdjustmentEnabled) {
ShapeAppearanceModel adjustedShapeAppearanceModel =
adjustShapeAppearanceModelCornerRadius(shapeAppearanceModel, strokeWidth / 2f);
backgroundDrawable.setShapeAppearanceModel(adjustedShapeAppearanceModel);
Expand Down Expand Up @@ -304,7 +308,7 @@ private void updateStroke() {
? MaterialColors.getColor(materialButton, R.attr.colorSurface)
: Color.TRANSPARENT);
}
if (IS_LOLLIPOP) {
if (IS_LOLLIPOP && cornerAdjustmentEnabled) {
ShapeAppearanceModel shapeAppearance =
adjustShapeAppearanceModelCornerRadius(shapeAppearanceModel, strokeWidth / 2f);
updateButtonShape(shapeAppearance);
Expand All @@ -322,8 +326,10 @@ void setCornerRadius(int cornerRadius) {
if (!cornerRadiusSet || this.cornerRadius != cornerRadius) {
this.cornerRadius = cornerRadius;
cornerRadiusSet = true;

setShapeAppearanceModel(
shapeAppearanceModel.withCornerRadius(cornerRadius + (strokeWidth / 2f)));
shapeAppearanceModel.withCornerRadius(
cornerAdjustmentEnabled ? cornerRadius + (strokeWidth / 2f) : cornerRadius));
}
}

Expand Down

0 comments on commit 18d4e6b

Please sign in to comment.