102
102
import java .lang .annotation .Retention ;
103
103
import java .lang .annotation .RetentionPolicy ;
104
104
import java .math .BigDecimal ;
105
+ import java .text .NumberFormat ;
106
+ import java .text .ParseException ;
105
107
import java .util .ArrayList ;
106
108
import java .util .Collections ;
107
109
import java .util .Iterator ;
@@ -239,6 +241,8 @@ abstract class BaseSlider<
239
241
"Floating point value used for %s(%s). Using floats can have rounding errors which may"
240
242
+ " result in incorrect values. Instead, consider using integers with a custom"
241
243
+ " LabelFormatter to display the value correctly." ;
244
+ private static final String WARNING_PARSE_ERROR =
245
+ "Error parsing value(%s), valueFrom(%s), and valueTo(%s) into a float." ;
242
246
243
247
private static final int TIMEOUT_SEND_ACCESSIBILITY_EVENT = 200 ;
244
248
private static final int HALO_ALPHA = 63 ;
@@ -3251,7 +3255,7 @@ protected void onPopulateNodeForVirtualView(
3251
3255
info .addAction (AccessibilityNodeInfoCompat .AccessibilityActionCompat .ACTION_SET_PROGRESS );
3252
3256
3253
3257
List <Float > values = slider .getValues ();
3254
- final float value = values .get (virtualViewId );
3258
+ float value = values .get (virtualViewId );
3255
3259
float valueFrom = slider .getValueFrom ();
3256
3260
float valueTo = slider .getValueTo ();
3257
3261
@@ -3264,6 +3268,16 @@ protected void onPopulateNodeForVirtualView(
3264
3268
}
3265
3269
}
3266
3270
3271
+ NumberFormat nf = NumberFormat .getNumberInstance ();
3272
+ nf .setMaximumFractionDigits (2 );
3273
+ try {
3274
+ valueFrom = nf .parse (nf .format (valueFrom )).floatValue ();
3275
+ valueTo = nf .parse (nf .format (valueTo )).floatValue ();
3276
+ value = nf .parse (nf .format (value )).floatValue ();
3277
+ } catch (ParseException e ) {
3278
+ Log .w (TAG , String .format (WARNING_PARSE_ERROR , value , valueFrom , valueTo ));
3279
+ }
3280
+
3267
3281
info .setRangeInfo (RangeInfoCompat .obtain (RANGE_TYPE_FLOAT , valueFrom , valueTo , value ));
3268
3282
info .setClassName (SeekBar .class .getName ());
3269
3283
StringBuilder contentDescription = new StringBuilder ();
0 commit comments