Skip to content

Commit

Permalink
[ProgressIndicator] Fix ArithmeticException when calculating the phase
Browse files Browse the repository at this point in the history
Resolves #4154

GIT_ORIGIN_REV_ID=d5aedbbd23f1b6d126263cba8960df0bc36386c4
PiperOrigin-RevId: 634014470
  • Loading branch information
pubiqq authored and dsn5ft committed May 15, 2024
1 parent d13bfdf commit ce00ba3
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,18 @@ float getPhaseFraction() {
if (mockPhaseFraction > 0) {
return mockPhaseFraction;
}

float phaseFraction = 0f;
if (baseSpec.speed != 0) {
if (baseSpec.hasWavyEffect() && baseSpec.speed != 0) {
float durationScale =
animatorDurationScaleProvider.getSystemAnimatorDurationScale(
context.getContentResolver());
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
if (phaseFraction < 0f) {
phaseFraction = (phaseFraction % 1) + 1f;
if (durationScale > 0f) {
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
if (phaseFraction < 0f) {
phaseFraction = (phaseFraction % 1) + 1f;
}
}
}
return phaseFraction;
Expand Down

0 comments on commit ce00ba3

Please sign in to comment.