|
16 | 16 |
|
17 | 17 | package com.google.android.material.slider; |
18 | 18 |
|
| 19 | +import androidx.core.os.ConfigurationCompat; |
| 20 | +import androidx.core.os.LocaleListCompat; |
19 | 21 | import com.google.android.material.R; |
20 | 22 |
|
21 | 23 | import static android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS; |
@@ -305,6 +307,7 @@ abstract class BaseSlider< |
305 | 307 | @NonNull private final Paint inactiveTicksPaint; |
306 | 308 | @NonNull private final Paint activeTicksPaint; |
307 | 309 | @NonNull private final Paint stopIndicatorPaint; |
| 310 | + @NonNull private final Locale locale; |
308 | 311 | @NonNull private final AccessibilityHelper accessibilityHelper; |
309 | 312 | private final AccessibilityManager accessibilityManager; |
310 | 313 | private AccessibilityEventSender accessibilityEventSender; |
@@ -476,6 +479,14 @@ public BaseSlider( |
476 | 479 | // Initialize with just this view's visibility. |
477 | 480 | thisAndAncestorsVisible = isShown(); |
478 | 481 |
|
| 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 | + |
479 | 490 | inactiveTrackPaint = new Paint(); |
480 | 491 | activeTrackPaint = new Paint(); |
481 | 492 |
|
@@ -3762,7 +3773,7 @@ private String formatValue(float value) { |
3762 | 3773 | return formatter.getFormattedValue(value); |
3763 | 3774 | } |
3764 | 3775 |
|
3765 | | - return String.format((int) value == value ? "%.0f" : "%.2f", value); |
| 3776 | + return String.format(locale, (int) value == value ? "%.0f" : "%.2f", value); |
3766 | 3777 | } |
3767 | 3778 |
|
3768 | 3779 | private void setValueForLabel(TooltipDrawable label, float value) { |
@@ -4334,7 +4345,7 @@ protected void onPopulateNodeForVirtualView( |
4334 | 4345 | info.setStateDescription(stateDescription); |
4335 | 4346 | } else { |
4336 | 4347 | contentDescription.append( |
4337 | | - String.format(Locale.getDefault(), "%s, %s", verbalValueType, verbalValue)); |
| 4348 | + String.format(slider.locale, "%s, %s", verbalValueType, verbalValue)); |
4338 | 4349 | } |
4339 | 4350 | info.setContentDescription(contentDescription.toString()); |
4340 | 4351 |
|
|
0 commit comments