Skip to content

Commit 58c950b

Browse files
committed
[Slider] Use the locale from the context for formatting
1 parent 4b26950 commit 58c950b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.android.material.slider;
1818

19+
import androidx.core.os.ConfigurationCompat;
20+
import androidx.core.os.LocaleListCompat;
1921
import com.google.android.material.R;
2022

2123
import static android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS;
@@ -305,6 +307,7 @@ abstract class BaseSlider<
305307
@NonNull private final Paint inactiveTicksPaint;
306308
@NonNull private final Paint activeTicksPaint;
307309
@NonNull private final Paint stopIndicatorPaint;
310+
@NonNull private final Locale locale;
308311
@NonNull private final AccessibilityHelper accessibilityHelper;
309312
private final AccessibilityManager accessibilityManager;
310313
private AccessibilityEventSender accessibilityEventSender;
@@ -476,6 +479,14 @@ public BaseSlider(
476479
// Initialize with just this view's visibility.
477480
thisAndAncestorsVisible = isShown();
478481

482+
LocaleListCompat ll = ConfigurationCompat.getLocales(context.getResources().getConfiguration());
483+
if (ll.isEmpty()) {
484+
ll = LocaleListCompat.getDefault();
485+
}
486+
487+
//noinspection DataFlowIssue
488+
locale = ll.get(0);
489+
479490
inactiveTrackPaint = new Paint();
480491
activeTrackPaint = new Paint();
481492

@@ -3762,7 +3773,7 @@ private String formatValue(float value) {
37623773
return formatter.getFormattedValue(value);
37633774
}
37643775

3765-
return String.format((int) value == value ? "%.0f" : "%.2f", value);
3776+
return String.format(locale, (int) value == value ? "%.0f" : "%.2f", value);
37663777
}
37673778

37683779
private void setValueForLabel(TooltipDrawable label, float value) {
@@ -4334,7 +4345,7 @@ protected void onPopulateNodeForVirtualView(
43344345
info.setStateDescription(stateDescription);
43354346
} else {
43364347
contentDescription.append(
4337-
String.format(Locale.getDefault(), "%s, %s", verbalValueType, verbalValue));
4348+
String.format(slider.locale, "%s, %s", verbalValueType, verbalValue));
43384349
}
43394350
info.setContentDescription(contentDescription.toString());
43404351

0 commit comments

Comments
 (0)