|
32 | 32 | import android.content.Context;
|
33 | 33 | import android.content.res.ColorStateList;
|
34 | 34 | import android.content.res.TypedArray;
|
| 35 | +import android.graphics.Color; |
35 | 36 | import android.graphics.Rect;
|
36 | 37 | import android.text.TextUtils;
|
37 | 38 | import android.util.AttributeSet;
|
@@ -103,6 +104,8 @@ public class ExtendedFloatingActionButton extends MaterialButton implements Atta
|
103 | 104 | /** Strategy to extend the FAB. */
|
104 | 105 | private static final int EXTEND = 3;
|
105 | 106 |
|
| 107 | + private boolean animationEnabled = true; |
| 108 | + |
106 | 109 | /**
|
107 | 110 | * The strategy type determines what motion strategy to apply on the FAB.
|
108 | 111 | *
|
@@ -915,8 +918,25 @@ private boolean isOrWillBeHidden() {
|
915 | 918 | }
|
916 | 919 | }
|
917 | 920 |
|
| 921 | + /** |
| 922 | + * Set whether or not animations are enabled. |
| 923 | + * |
| 924 | + * @hide |
| 925 | + */ |
| 926 | + @RestrictTo(LIBRARY_GROUP) |
| 927 | + public void setAnimationEnabled(boolean animationEnabled) { |
| 928 | + this.animationEnabled = animationEnabled; |
| 929 | + } |
| 930 | + |
| 931 | + /** Return whether or not animations are enabled. */ |
| 932 | + public boolean isAnimationEnabled() { |
| 933 | + return animationEnabled; |
| 934 | + } |
| 935 | + |
918 | 936 | private boolean shouldAnimateVisibilityChange() {
|
919 |
| - return (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout)) && !isInEditMode(); |
| 937 | + return animationEnabled |
| 938 | + && (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout)) |
| 939 | + && !isInEditMode(); |
920 | 940 | }
|
921 | 941 |
|
922 | 942 | /**
|
@@ -1332,6 +1352,17 @@ public void performNow() {
|
1332 | 1352 | }
|
1333 | 1353 | layoutParams.width = size.getLayoutParams().width;
|
1334 | 1354 | layoutParams.height = size.getLayoutParams().height;
|
| 1355 | + |
| 1356 | + if (extending) { // extending |
| 1357 | + silentlyUpdateTextColor(originalTextCsl); |
| 1358 | + } else if (getText() != null && getText() != "") { // shrinking |
| 1359 | + // We only update the text to transparent if it exists, otherwise, updating the |
| 1360 | + // text color to transparent affects the elevation of the view. |
| 1361 | + // It's okay for the text to be set afterwards and not be transparent, as it is cut off |
| 1362 | + // by forcing the layout param dimens. |
| 1363 | + silentlyUpdateTextColor(ColorStateList.valueOf(Color.TRANSPARENT)); |
| 1364 | + } |
| 1365 | + |
1335 | 1366 | setPaddingRelative(
|
1336 | 1367 | size.getPaddingStart(),
|
1337 | 1368 | getPaddingTop(),
|
|
0 commit comments