Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/java/com/google/android/material/slider/BaseSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ abstract class BaseSlider<
"Value(%s) must be equal to valueFrom(%s) plus a multiple of stepSize(%s) when using"
+ " stepSize(%s)";
private static final String EXCEPTION_ILLEGAL_VALUE_FROM =
"valueFrom(%s) must be smaller than valueTo(%s)";
"valueFrom(%s) must be smaller than or equal to valueTo(%s)";
private static final String EXCEPTION_ILLEGAL_STEP_SIZE =
"The stepSize(%s) must be 0, or a factor of the valueFrom(%s)-valueTo(%s) range";
private static final String EXCEPTION_ILLEGAL_MIN_SEPARATION =
Expand Down Expand Up @@ -735,7 +735,7 @@ private void validateStepSize() {
}

private void validateValues() {
if (valueFrom >= valueTo) {
if (valueFrom > valueTo) {
throw new IllegalStateException(
String.format(EXCEPTION_ILLEGAL_VALUE_FROM, valueFrom, valueTo));
}
Expand Down Expand Up @@ -2879,7 +2879,7 @@ private void drawInactiveTrackSection(
* being on the far left, and 1 on the far right.
*/
private float normalizeValue(float value) {
float normalized = (value - valueFrom) / (valueTo - valueFrom);
float normalized = (valueTo != valueFrom) ? (value - valueFrom) / (valueTo - valueFrom) : 0;
if (isRtl() || isVertical()) {
return 1 - normalized;
}
Expand Down Expand Up @@ -3481,7 +3481,7 @@ private void resetThumbWidth() {
}

private double snapPosition(float position) {
if (stepSize > 0.0f) {
if (stepSize > 0.0f && valueTo != valueFrom) {
int stepCount = (int) ((valueTo - valueFrom) / stepSize);
return Math.round(position * stepCount) / (double) stepCount;
}
Expand Down Expand Up @@ -3522,7 +3522,7 @@ protected boolean pickActiveThumb() {

if (compare(valueDiff, activeThumbDiff) == 0) {
// Two thumbs on the same value and we don't have enough movement to use direction yet.
if (abs(valueX - touchX) < scaledTouchSlop) {
if (abs(valueX - touchX) < scaledTouchSlop && valueTo != valueFrom) {
activeThumbIdx = -1;
return false;
}
Expand Down