@@ -344,6 +344,8 @@ abstract class BaseSlider<
344
344
@ NonNull private List <Drawable > customThumbDrawablesForValues = Collections .emptyList ();
345
345
346
346
private float touchPosition ;
347
+
348
+ private float minSeparation = 0f ;
347
349
@ SeparationUnit private int separationUnit = UNIT_PX ;
348
350
349
351
@ NonNull
@@ -628,7 +630,6 @@ private void validateValues() {
628
630
}
629
631
630
632
private void validateMinSeparation () {
631
- final float minSeparation = getMinSeparation ();
632
633
if (minSeparation < 0 ) {
633
634
throw new IllegalStateException (
634
635
String .format (EXCEPTION_ILLEGAL_MIN_SEPARATION , minSeparation ));
@@ -2532,7 +2533,7 @@ private boolean snapThumbToValue(int idx, float value) {
2532
2533
2533
2534
/** Thumbs cannot cross each other, clamp the value to a bound or the value next to it. */
2534
2535
private float getClampedValue (int idx , float value ) {
2535
- float minSeparation = getMinSeparation () ;
2536
+ float minSeparation = this . minSeparation ;
2536
2537
minSeparation = separationUnit == UNIT_PX ? dimenToValue (minSeparation ) : minSeparation ;
2537
2538
if (isRtl ()) {
2538
2539
minSeparation = -minSeparation ;
@@ -2550,16 +2551,22 @@ private float dimenToValue(float dimen) {
2550
2551
return ((dimen - trackSidePadding ) / trackWidth ) * (valueFrom - valueTo ) + valueFrom ;
2551
2552
}
2552
2553
2553
- protected void setSeparationUnit (int separationUnit ) {
2554
+ protected float getMinSeparation () {
2555
+ return minSeparation ;
2556
+ }
2557
+
2558
+ protected float getSeparationUnit () {
2559
+ return separationUnit ;
2560
+ }
2561
+
2562
+ protected void setMinSeparation (float minSeparation , @ SeparationUnit int separationUnit ) {
2563
+ this .minSeparation = minSeparation ;
2554
2564
this .separationUnit = separationUnit ;
2565
+
2555
2566
dirtyConfig = true ;
2556
2567
postInvalidate ();
2557
2568
}
2558
2569
2559
- protected float getMinSeparation () {
2560
- return 0 ;
2561
- }
2562
-
2563
2570
private float getValueOfTouchPosition () {
2564
2571
double position = snapPosition (touchPosition );
2565
2572
@@ -3131,6 +3138,8 @@ protected Parcelable onSaveInstanceState() {
3131
3138
sliderState .valueTo = valueTo ;
3132
3139
sliderState .values = new ArrayList <>(values );
3133
3140
sliderState .stepSize = stepSize ;
3141
+ sliderState .minSeparation = minSeparation ;
3142
+ sliderState .separationUnit = separationUnit ;
3134
3143
sliderState .hasFocus = hasFocus ();
3135
3144
return sliderState ;
3136
3145
}
@@ -3144,6 +3153,9 @@ protected void onRestoreInstanceState(Parcelable state) {
3144
3153
valueTo = sliderState .valueTo ;
3145
3154
setValuesInternal (sliderState .values );
3146
3155
stepSize = sliderState .stepSize ;
3156
+ minSeparation = sliderState .minSeparation ;
3157
+ separationUnit = sliderState .separationUnit ;
3158
+
3147
3159
if (sliderState .hasFocus ) {
3148
3160
requestFocus ();
3149
3161
}
@@ -3155,6 +3167,8 @@ static class SliderState extends BaseSavedState {
3155
3167
float valueTo ;
3156
3168
ArrayList <Float > values ;
3157
3169
float stepSize ;
3170
+ float minSeparation ;
3171
+ @ SeparationUnit int separationUnit ;
3158
3172
boolean hasFocus ;
3159
3173
3160
3174
public static final Creator <SliderState > CREATOR =
@@ -3184,6 +3198,8 @@ private SliderState(@NonNull Parcel source) {
3184
3198
values = new ArrayList <>();
3185
3199
source .readList (values , Float .class .getClassLoader ());
3186
3200
stepSize = source .readFloat ();
3201
+ minSeparation = source .readFloat ();
3202
+ separationUnit = source .readInt ();
3187
3203
hasFocus = source .createBooleanArray ()[0 ];
3188
3204
}
3189
3205
@@ -3194,6 +3210,8 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
3194
3210
dest .writeFloat (valueTo );
3195
3211
dest .writeList (values );
3196
3212
dest .writeFloat (stepSize );
3213
+ dest .writeFloat (minSeparation );
3214
+ dest .writeInt (separationUnit );
3197
3215
boolean [] booleans = new boolean [1 ];
3198
3216
booleans [0 ] = hasFocus ;
3199
3217
dest .writeBooleanArray (booleans );
0 commit comments