anastr / SpeedView

Dynamic Speedometer and Gauge for Android. amazing, powerful, and multi shape :zap:
Apache License 2.0
1.29k stars 324 forks source link

lowSpeedPercent must be smaller than mediumSpeedPercent #152

Closed Drjacky closed 5 years ago

Drjacky commented 5 years ago

I've set the minimum percentage to 90 and the medium percentage to 92 and the max percentage is 100, But still getting this error:

Stack trace:
java.lang.IllegalArgumentException: lowSpeedPercent must be smaller than mediumSpeedPercent at com.github.anastr.speedviewlib.Gauge.checkSpeedometerPercent(Gauge.kt:339) at com.github.anastr.speedviewlib.Gauge.setLowSpeedPercent(Gauge.kt:1176)

When I set it through XML, it works. But when I set it programmatically like this, it doesn't work:

            speedView.setLowSpeedPercent(miniCompletionRate)
            speedView.setMediumSpeedPercent(miniCompletionRate + 2)
Drjacky commented 5 years ago

It works when I set the medium percentage first, then the low percentage:

            speedView.setMediumSpeedPercent(miniCompletionRate + 2)
            speedView.setLowSpeedPercent(miniCompletionRate)       
Drjacky commented 5 years ago

The solution is we have to define Medium and Low percentages on XML, then set them programmatically. Otherwise, we get the error.

anastr commented 5 years ago

Technically, default value of Low/Medium percent are 60/87. When you change lowSpeedPercent first to '90' it will throw the exception above, because lowSpeedPercent '90' is bigger than mediumSpeedPercent '87'.