use L10n-friendly runtime number formatting based on locale

Arabic use Western or Eastern numbers depends on the regions.

Bug: 276479321
Test: atest AccessibilityButtonFooterPreferenceControllerTest
Test: manual
Change-Id: I855f4fd891893b094163b0d479bdf3e5155dffc1
This commit is contained in:
Chun-Ku Lin
2023-06-29 02:43:44 +00:00
parent 4dd2e56ddf
commit 20976c3a53
4 changed files with 54 additions and 20 deletions

View File

@@ -4497,10 +4497,24 @@
<string name="accessibility_button_intro">Using the accessibility button. The gesture isn\u2019t available with 3-button navigation.</string> <string name="accessibility_button_intro">Using the accessibility button. The gesture isn\u2019t available with 3-button navigation.</string>
<!-- Summary text for the accessibility button preference. [CHAR LIMIT=50] --> <!-- Summary text for the accessibility button preference. [CHAR LIMIT=50] -->
<string name="accessibility_button_summary">Quickly access accessibility features</string> <string name="accessibility_button_summary">Quickly access accessibility features</string>
<!-- Description for the accessibility button in gesture navigation. Explain how this page works. [CHAR LIMIT=NONE] --> <!-- Description for the accessibility button in gesture navigation. Explain how this page works in numbered ordered list. [CHAR LIMIT=NONE] -->
<string name="accessibility_button_gesture_description"><b>To get started</b>\n1. Go to accessibility settings\n2. Select a feature and tap the shortcut\n3. Choose whether you want to use a button or gesture to access the feature</string> <string name="accessibility_button_gesture_description">
<!-- Description for the accessibility button page. Explain how this page works. [CHAR LIMIT=NONE] --> <![CDATA[
<string name="accessibility_button_description"><b>To get started</b>\n1. Go to accessibility settings\n2. Select a feature and tap the shortcut\n3. Choose the button to access the feature</string> <b>To get started</b><br/>
{0,number,integer}. Go to accessibility settings<br/>
{1,number,integer}. Select a feature and tap the shortcut<br/>
{2,number,integer}. Choose whether you want to use a button or gesture to access the feature<br/>
]]>
</string>
<!-- Description for the accessibility button page. Explain how this page works in numbered ordered list. [CHAR LIMIT=NONE] -->
<string name="accessibility_button_description">
<![CDATA[
<b>To get started</b><br/>
{0,number,integer}. Go to accessibility settings<br/>
{1,number,integer}. Select a feature and tap the shortcut<br/>
{2,number,integer}. Choose the button to access the feature<br/>
]]>
</string>
<!-- Title for the button or gesture of the accessibility button. [CHAR LIMIT=35] --> <!-- Title for the button or gesture of the accessibility button. [CHAR LIMIT=35] -->
<string name="accessibility_button_or_gesture_title">Use button or gesture</string> <string name="accessibility_button_or_gesture_title">Use button or gesture</string>
<!-- Title for the location of the accessibility button. [CHAR LIMIT=35] --> <!-- Title for the location of the accessibility button. [CHAR LIMIT=35] -->
@@ -8616,20 +8630,24 @@
<string name="app_pinning_intro">App pinning allows you to keep the current app in view until you unpin it. This feature can be used, for example, to let a trusted friend play a specific game.</string> <string name="app_pinning_intro">App pinning allows you to keep the current app in view until you unpin it. This feature can be used, for example, to let a trusted friend play a specific game.</string>
<!-- [CHAR LIMIT=none] Screen pinning description --> <!-- [CHAR LIMIT=none] Screen pinning description -->
<string name="screen_pinning_description"> <string name="screen_pinning_description">
<![CDATA[
When an app is pinned, the pinned app may open other apps and personal data may be accessible. When an app is pinned, the pinned app may open other apps and personal data may be accessible.
\n\nTo use app pinning: \n\nTo use app pinning:
\t\n1. Turn on app pinning \t\n{0,number,integer}. Turn on app pinning
\t\n2. Open Overview \t\n{1,number,integer}. Open Overview
\t\n3. Tap the app icon at the top of the screen, then tap Pin \t\n{2,number,integer}. Tap the app icon at the top of the screen, then tap Pin
]]>
</string> </string>
<!-- [CHAR LIMIT=none] Screen pinning description --> <!-- [CHAR LIMIT=none] Screen pinning description -->
<string name="screen_pinning_guest_user_description"> <string name="screen_pinning_guest_user_description">
<![CDATA[
When an app is pinned, the pinned app may open other apps and personal data may be accessible. When an app is pinned, the pinned app may open other apps and personal data may be accessible.
\n\nIf you want to securely share your device with someone, try using a guest user instead. \n\nIf you want to securely share your device with someone, try using a guest user instead.
\n\nTo use app pinning: \n\nTo use app pinning:
\t\n1. Turn on app pinning \t\n{0,number,integer}. Turn on app pinning
\t\n2. Open Overview \t\n{1,number,integer}. Open Overview
\t\n3. Tap the app icon at the top of the screen, then tap Pin \t\n{2,number,integer}. Tap the app icon at the top of the screen, then tap Pin
]]>
</string> </string>
<!-- [CHAR LIMIT=300] Screen pinning title --> <!-- [CHAR LIMIT=300] Screen pinning title -->
<string name="screen_pinning_dialog_message"> <string name="screen_pinning_dialog_message">

View File

@@ -17,6 +17,8 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import android.content.Context; import android.content.Context;
import android.icu.text.MessageFormat;
import android.text.Html;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -50,7 +52,9 @@ public class AccessibilityButtonFooterPreferenceController extends
final int titleResource = AccessibilityUtil.isGestureNavigateEnabled(mContext) final int titleResource = AccessibilityUtil.isGestureNavigateEnabled(mContext)
? R.string.accessibility_button_gesture_description ? R.string.accessibility_button_gesture_description
: R.string.accessibility_button_description; : R.string.accessibility_button_description;
final CharSequence footerText = mContext.getText(titleResource); final CharSequence footerText = Html.fromHtml(
MessageFormat.format(mContext.getString(titleResource), 1, 2, 3),
Html.FROM_HTML_MODE_COMPACT);
final AccessibilityFooterPreference footerPreference = final AccessibilityFooterPreference footerPreference =
screen.findPreference(getPreferenceKey()); screen.findPreference(getPreferenceKey());
footerPreference.setTitle(footerText); footerPreference.setTitle(footerText);

View File

@@ -20,6 +20,7 @@ import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.icu.text.MessageFormat;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -242,9 +243,10 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment
} }
private CharSequence getAppPinningContent() { private CharSequence getAppPinningContent() {
return isGuestModeSupported() final int stringResource = isGuestModeSupported()
? getActivity().getText(R.string.screen_pinning_guest_user_description) ? R.string.screen_pinning_guest_user_description
: getActivity().getText(R.string.screen_pinning_description); : R.string.screen_pinning_description;
return MessageFormat.format(getActivity().getString(stringResource), 1, 2, 3);
} }
/** /**

View File

@@ -25,6 +25,8 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.icu.text.MessageFormat;
import android.text.Html;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -73,18 +75,26 @@ public class AccessibilityButtonFooterPreferenceControllerTest {
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat(mPreference.getTitle()).isEqualTo( assertThat(mPreference.getTitle().toString()).isEqualTo(
mContext.getText(R.string.accessibility_button_gesture_description)); Html.fromHtml(
MessageFormat.format(mContext.getString(
R.string.accessibility_button_gesture_description), 1, 2, 3),
Html.FROM_HTML_MODE_COMPACT).toString());
} }
@Test @Test
public void displayPreference_navigationGestureDisabled_setCorrectTitle() { public void displayPreference_navigationGestureDisabled_setCorrectTitle() {
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode)) when(mResources.getInteger(
.thenReturn(NAV_BAR_MODE_2BUTTON); com.android.internal.R.integer.config_navBarInteractionMode)).thenReturn(
NAV_BAR_MODE_2BUTTON);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat(mPreference.getTitle()).isEqualTo( assertThat(mPreference.getTitle().toString()).isEqualTo(
mContext.getText(R.string.accessibility_button_description)); Html.fromHtml(
MessageFormat.format(
mContext.getString(
R.string.accessibility_button_description), 1, 2, 3),
Html.FROM_HTML_MODE_COMPACT).toString());
} }
} }