Skip to content

Commit 174269e

Browse files
committed
[ProgressIndicator] Fix ArithmeticException when calculating the phase
1 parent cc125d9 commit 174269e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,18 @@ float getPhaseFraction() {
452452
if (mockPhaseFraction > 0) {
453453
return mockPhaseFraction;
454454
}
455+
455456
float phaseFraction = 0f;
456-
if (baseSpec.speed != 0) {
457+
if (baseSpec.wavelength > 0 && baseSpec.speed != 0) {
457458
float durationScale =
458459
animatorDurationScaleProvider.getSystemAnimatorDurationScale(
459460
context.getContentResolver());
460-
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
461-
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
462-
if (phaseFraction < 0f) {
463-
phaseFraction = (phaseFraction % 1) + 1f;
461+
if (durationScale > 0f) {
462+
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
463+
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
464+
if (phaseFraction < 0f) {
465+
phaseFraction = (phaseFraction % 1) + 1f;
466+
}
464467
}
465468
}
466469
return phaseFraction;

0 commit comments

Comments
 (0)