|
18 | 18 |
|
19 | 19 | import com.google.android.material.R;
|
20 | 20 |
|
| 21 | +import static com.google.android.material.progressindicator.DeterminateDrawable.MAX_DRAWABLE_LEVEL; |
21 | 22 | import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;
|
22 | 23 | import static java.lang.Math.abs;
|
23 | 24 | import static java.lang.Math.min;
|
|
43 | 44 | import androidx.annotation.RestrictTo.Scope;
|
44 | 45 | import androidx.annotation.StyleRes;
|
45 | 46 | import androidx.annotation.VisibleForTesting;
|
| 47 | +import androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener; |
46 | 48 | import androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback;
|
47 | 49 | import com.google.android.material.color.MaterialColors;
|
48 | 50 | import com.google.android.material.internal.ThemeEnforcement;
|
@@ -960,6 +962,25 @@ public void setVisibilityAfterHide(int visibility) {
|
960 | 962 | visibilityAfterHide = visibility;
|
961 | 963 | }
|
962 | 964 |
|
| 965 | + private final OnAnimationEndListener hideAfterMaxProgressListener = |
| 966 | + (animation, canceled, value, velocity) -> { |
| 967 | + if (getProgressDrawable() != null |
| 968 | + && getProgressDrawable().getLevel() == MAX_DRAWABLE_LEVEL) { |
| 969 | + hide(); |
| 970 | + } |
| 971 | + }; |
| 972 | + |
| 973 | + public void setHideAfterMaxProgress(boolean hideAfterMaxProgress) { |
| 974 | + if (getProgressDrawable() == null) { |
| 975 | + return; |
| 976 | + } |
| 977 | + if (hideAfterMaxProgress) { |
| 978 | + getProgressDrawable().addSpringAnimationEndListener(hideAfterMaxProgressListener); |
| 979 | + } else { |
| 980 | + getProgressDrawable().removeSpringAnimationEndListener(hideAfterMaxProgressListener); |
| 981 | + } |
| 982 | + } |
| 983 | + |
963 | 984 | /**
|
964 | 985 | * Sets the scale of the animation duration in indeterminate mode.
|
965 | 986 | *
|
|
0 commit comments