|
15 | 15 | */ |
16 | 16 | package com.google.android.material.progressindicator; |
17 | 17 |
|
| 18 | +import static com.google.android.material.math.MathUtils.lerp; |
18 | 19 | import static com.google.android.material.progressindicator.BaseProgressIndicator.HIDE_ESCAPE; |
19 | 20 | import static com.google.android.material.progressindicator.BaseProgressIndicator.HIDE_INWARD; |
20 | 21 | import static com.google.android.material.progressindicator.BaseProgressIndicator.SHOW_OUTWARD; |
@@ -42,6 +43,11 @@ final class LinearDrawingDelegate extends DrawingDelegate<LinearProgressIndicato |
42 | 43 | private float displayedCornerRadius; |
43 | 44 | private Path displayedTrackPath; |
44 | 45 |
|
| 46 | + // This will be used in the ESCAPE hide animation. The start and end fraction in track will be |
| 47 | + // scaled by this fraction with a pivot of 1.0f. |
| 48 | + @FloatRange(from = 0.0f, to = 1.0f) |
| 49 | + private float totalTrackLengthFraction; |
| 50 | + |
45 | 51 | /** Instantiates LinearDrawingDelegate with the current spec. */ |
46 | 52 | public LinearDrawingDelegate(@NonNull LinearProgressIndicatorSpec spec) { |
47 | 53 | super(spec); |
@@ -96,13 +102,11 @@ public void adjustCanvas( |
96 | 102 | if (isShowing || (isHiding && spec.hideAnimationBehavior != HIDE_ESCAPE)) { |
97 | 103 | canvas.translate(0f, spec.trackThickness * (trackThicknessFraction - 1) / 2f); |
98 | 104 | } |
99 | | - // Scales canvas while hiding with escape animation. |
| 105 | + // Sets the total track length fraction if ESCAPE hide animation is used. |
100 | 106 | if (isHiding && spec.hideAnimationBehavior == HIDE_ESCAPE) { |
101 | | - canvas.scale( |
102 | | - trackThicknessFraction, |
103 | | - trackThicknessFraction, |
104 | | - bounds.left + bounds.width() / 2f, |
105 | | - bounds.top + bounds.height() / 2f); |
| 107 | + totalTrackLengthFraction = trackThicknessFraction; |
| 108 | + } else { |
| 109 | + totalTrackLengthFraction = 1f; |
106 | 110 | } |
107 | 111 |
|
108 | 112 | // Clips all drawing to the track area, so it doesn't draw outside of its bounds (which can |
@@ -139,6 +143,9 @@ public void fillIndicator( |
139 | 143 | return; |
140 | 144 | } |
141 | 145 | color = MaterialColors.compositeARGBWithAlpha(color, drawableAlpha); |
| 146 | + // Scale start and end fraction if ESCAPE animation is used. |
| 147 | + startFraction = lerp(1 - totalTrackLengthFraction, 1f, startFraction); |
| 148 | + endFraction = lerp(1 - totalTrackLengthFraction, 1f, endFraction); |
142 | 149 |
|
143 | 150 | float originX = -trackLength / 2; |
144 | 151 |
|
@@ -218,10 +225,11 @@ void fillTrack( |
218 | 225 | paint.setColor(trackColor); |
219 | 226 |
|
220 | 227 | float right = trackLength / 2; |
| 228 | + float left = right - trackLength * totalTrackLengthFraction; |
221 | 229 | float bottom = displayedTrackThickness / 2; |
222 | 230 | displayedTrackPath = new Path(); |
223 | 231 | displayedTrackPath.addRoundRect( |
224 | | - new RectF(-right, -bottom, right, bottom), |
| 232 | + new RectF(left, -bottom, right, bottom), |
225 | 233 | displayedCornerRadius, |
226 | 234 | displayedCornerRadius, |
227 | 235 | Path.Direction.CCW); |
|
0 commit comments