Skip to content

Commit 742ccd5

Browse files
committed
[Slider] Use the locale from the context for formatting
1 parent c2051db commit 742ccd5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/java/com/google/android/material/slider/BaseSlider.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ abstract class BaseSlider<
304304
@NonNull private final Paint inactiveTicksPaint;
305305
@NonNull private final Paint activeTicksPaint;
306306
@NonNull private final Paint stopIndicatorPaint;
307+
@NonNull private final Locale locale;
307308
@NonNull private final AccessibilityHelper accessibilityHelper;
308309
private final AccessibilityManager accessibilityManager;
309310
private AccessibilityEventSender accessibilityEventSender;
@@ -466,6 +467,8 @@ public BaseSlider(
466467
// Initialize with just this view's visibility.
467468
thisAndAncestorsVisible = isShown();
468469

470+
locale = context.getResources().getConfiguration().locale;
471+
469472
inactiveTrackPaint = new Paint();
470473
activeTrackPaint = new Paint();
471474

@@ -3609,7 +3612,7 @@ private String formatValue(float value) {
36093612
return formatter.getFormattedValue(value);
36103613
}
36113614

3612-
return String.format((int) value == value ? "%.0f" : "%.2f", value);
3615+
return String.format(locale, (int) value == value ? "%.0f" : "%.2f", value);
36133616
}
36143617

36153618
private void setValueForLabel(TooltipDrawable label, float value) {
@@ -4228,7 +4231,7 @@ protected void onPopulateNodeForVirtualView(
42284231
info.setStateDescription(stateDescription);
42294232
} else {
42304233
contentDescription.append(
4231-
String.format(Locale.getDefault(), "%s, %s", verbalValueType, verbalValue));
4234+
String.format(slider.locale, "%s, %s", verbalValueType, verbalValue));
42324235
}
42334236
info.setContentDescription(contentDescription.toString());
42344237

0 commit comments

Comments
 (0)