Skip to content

Commit

Permalink
[ProgressIndicator] Fix ArithmeticException when calculating the phase
Browse files Browse the repository at this point in the history
  • Loading branch information
pubiqq committed Apr 25, 2024
1 parent cc125d9 commit 174269e
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,18 @@ float getPhaseFraction() {
if (mockPhaseFraction > 0) {
return mockPhaseFraction;
}

float phaseFraction = 0f;
if (baseSpec.speed != 0) {
if (baseSpec.wavelength > 0 && 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 174269e

Please sign in to comment.