Skip to content

Commit ce00ba3

Browse files
pubiqqdsn5ft
authored andcommitted
[ProgressIndicator] Fix ArithmeticException when calculating the phase
Resolves #4154 GIT_ORIGIN_REV_ID=d5aedbbd23f1b6d126263cba8960df0bc36386c4 PiperOrigin-RevId: 634014470
1 parent d13bfdf commit ce00ba3

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,18 @@ float getPhaseFraction() {
451451
if (mockPhaseFraction > 0) {
452452
return mockPhaseFraction;
453453
}
454+
454455
float phaseFraction = 0f;
455-
if (baseSpec.speed != 0) {
456+
if (baseSpec.hasWavyEffect() && baseSpec.speed != 0) {
456457
float durationScale =
457458
animatorDurationScaleProvider.getSystemAnimatorDurationScale(
458459
context.getContentResolver());
459-
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
460-
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
461-
if (phaseFraction < 0f) {
462-
phaseFraction = (phaseFraction % 1) + 1f;
460+
if (durationScale > 0f) {
461+
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
462+
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
463+
if (phaseFraction < 0f) {
464+
phaseFraction = (phaseFraction % 1) + 1f;
465+
}
463466
}
464467
}
465468
return phaseFraction;

0 commit comments

Comments
 (0)