summaryrefslogtreecommitdiff
path: root/Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java')
-rw-r--r--Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java42
1 files changed, 32 insertions, 10 deletions
diff --git a/Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java b/Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java
index ed4c733e6..72150403e 100644
--- a/Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java
+++ b/Settings/src/com/android/tv/settings/util/ResolutionSelectionUtils.java
@@ -16,26 +16,35 @@
package com.android.tv.settings.util;
+import static java.math.RoundingMode.HALF_UP;
+
import android.content.Context;
-import android.content.res.Resources;
+import android.icu.number.LocalizedNumberFormatter;
+import android.icu.number.NumberFormatter;
import android.view.Display;
import com.android.tv.settings.R;
+import java.util.Locale;
+
+
/** This utility class for Resolution Setting **/
public class ResolutionSelectionUtils {
/**
- * Returns the refresh rate converted to a string. If the refresh rate has only 0s after the
- * floating point, they are removed. The unit "Hz" is added to end of refresh rate.
+ * Returns the refresh rate converted to a string in the local language. If the refresh rate has
+ * only 0s after the floating point, they are removed.
+ * The unit "Hz" is added to end of refresh rate.
*/
- public static String getRefreshRateString(Resources resources, float refreshRate) {
- float roundedRefreshRate = Math.round(refreshRate * 100.0f) / 100.0f;
+ public static String getRefreshRateString(float refreshRate) {
+ LocalizedNumberFormatter localizedNumberFormatter = NumberFormatter.with().roundingMode(
+ HALF_UP).locale(Locale.getDefault());
+ double roundedRefreshRate = Math.round(refreshRate * 100.0f) / 100.0f;
if (roundedRefreshRate % 1 == 0) {
- return ((int) roundedRefreshRate) + " "
- + resources.getString(R.string.resolution_selection_hz);
+ return localizedNumberFormatter.format(roundedRefreshRate).toString();
} else {
- return roundedRefreshRate + " " + resources.getString(R.string.resolution_selection_hz);
+ return String.format(Locale.getDefault(), "%.2f",
+ localizedNumberFormatter.format(roundedRefreshRate).toBigDecimal());
}
}
@@ -59,8 +68,21 @@ public class ResolutionSelectionUtils {
if (mode == null) {
return context.getString(R.string.resolution_selection_auto_title);
}
- String modeString = getResolutionString(mode.getPhysicalWidth(), mode.getPhysicalHeight());
- modeString += " " + getRefreshRateString(context.getResources(), mode.getRefreshRate());
+ final String modeString = context.getString(R.string.resolution_display_mode,
+ ResolutionSelectionUtils.getResolutionString(
+ mode.getPhysicalWidth(), mode.getPhysicalHeight()),
+ ResolutionSelectionUtils.getRefreshRateString(mode.getRefreshRate()));
return modeString;
}
+
+ /**
+ * Returns the resolution mode converted to a string in the local language.
+ * Format: width + " x " + height
+ */
+ public static String getResolutionSummary(int physicalWidth, int physicalHeight) {
+ LocalizedNumberFormatter localizedNumberFormatter = NumberFormatter.with().locale(
+ Locale.getDefault());
+ return localizedNumberFormatter.format(physicalWidth).toString() + " x "
+ + localizedNumberFormatter.format(physicalHeight).toString();
+ }
}