Skip to content

[Slider] Use the locale from the context for formatting #4573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/java/com/google/android/material/slider/BaseSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ abstract class BaseSlider<
@NonNull private final Paint inactiveTicksPaint;
@NonNull private final Paint activeTicksPaint;
@NonNull private final Paint stopIndicatorPaint;
@NonNull private final Locale locale;
@NonNull private final AccessibilityHelper accessibilityHelper;
private final AccessibilityManager accessibilityManager;
private AccessibilityEventSender accessibilityEventSender;
Expand Down Expand Up @@ -465,6 +466,8 @@ public BaseSlider(
// Initialize with just this view's visibility.
thisAndAncestorsVisible = isShown();

locale = context.getResources().getConfiguration().locale;

inactiveTrackPaint = new Paint();
activeTrackPaint = new Paint();

Expand Down Expand Up @@ -3547,7 +3550,7 @@ private String formatValue(float value) {
return formatter.getFormattedValue(value);
}

return String.format((int) value == value ? "%.0f" : "%.2f", value);
return String.format(locale, (int) value == value ? "%.0f" : "%.2f", value);
}

private void setValueForLabel(TooltipDrawable label, float value) {
Expand Down Expand Up @@ -4155,7 +4158,7 @@ protected void onPopulateNodeForVirtualView(
info.setStateDescription(stateDescription);
} else {
contentDescription.append(
String.format(Locale.getDefault(), "%s, %s", verbalValueType, verbalValue));
String.format(slider.locale, "%s, %s", verbalValueType, verbalValue));
}
info.setContentDescription(contentDescription.toString());

Expand Down