Merge pull request #504 from alexbakker/fix-zero-div

Fix division by zero when calculating progress for large periods
This commit is contained in:
Michael Schättgen 2020-07-04 12:19:31 +02:00 committed by GitHub
commit 4ef8d9e826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

View file

@ -65,8 +65,8 @@ public class TotpProgressBar extends ProgressBar {
int currentProgress = (int) (maxProgress * ((float) millisTillRotation / (_period * 1000))); int currentProgress = (int) (maxProgress * ((float) millisTillRotation / (_period * 1000)));
// start progress animation, compensating for any changes to the animator duration scale settings // start progress animation, compensating for any changes to the animator duration scale settings
int animPart = maxProgress / _period; float animPart = (float) maxProgress / _period;
int animEnd = (currentProgress / animPart) * animPart; int animEnd = (int) ((currentProgress / animPart) * animPart);
int animPartDuration = (int) (1000 / _animDurationScale); int animPartDuration = (int) (1000 / _animDurationScale);
float animDurationFraction = (float) (currentProgress - animEnd) / animPart; float animDurationFraction = (float) (currentProgress - animEnd) / animPart;
int realAnimDuration = (int) (1000 * animDurationFraction); int realAnimDuration = (int) (1000 * animDurationFraction);

View file

@ -148,7 +148,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="3dp" android:layout_height="3dp"
android:id="@+id/progressBar" android:id="@+id/progressBar"
android:max="1000" android:max="5000"
android:layout_weight="1"/> android:layout_weight="1"/>
</LinearLayout> </LinearLayout>

View file

@ -145,7 +145,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="3dp" android:layout_height="3dp"
android:id="@+id/progressBar" android:id="@+id/progressBar"
android:max="1000" android:max="5000"
android:layout_weight="1"/> android:layout_weight="1"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>