From 6d0a04a1712b9b7cd0d70e3252aead1b5871ecfa Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Tue, 28 Jan 2025 16:47:29 -0800 Subject: [PATCH] Update strings again for refreshed High Contrast Text Deletes the old string resource and uses a new resource because the old translated strings do not have formatting placeholders. Eventually the old translated strings will be automatically deleted and the new string with placeholder will be translated. Also uses placeholders for referencing other strings so that we guarantee that the strings are consistent across this notification and the actual preference in Settings. Bug: 384791485 Test: see bug screenshots Flag: com.android.graphics.hwui.flags.high_contrast_text_small_text_rect Change-Id: I89a9ee4b3755b20f4e090df5b4cccb7ce47a961c --- res/values/strings.xml | 8 ++++---- .../HighContrastTextMigrationReceiver.java | 20 +++++++++++++++---- ...HighContrastTextMigrationReceiverTest.java | 18 ++++++++--------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index f7c0410d3af..bedc0f63840 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5504,13 +5504,13 @@ Change text color to black or white. Maximizes contrast with the background. - High contrast text has been replaced + Improve text contrast - Try Text outlines instead. Find it in Settings. + %1$s has replaced %2$s. You can turn it on in %3$s. - Open Settings + Go to %1$s - Text outlines + Outline text Add a black or white background around text to increase contrast diff --git a/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java b/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java index 863689dddab..0b412aec0b9 100644 --- a/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java +++ b/src/com/android/settings/accessibility/HighContrastTextMigrationReceiver.java @@ -43,6 +43,7 @@ import com.google.common.annotations.VisibleForTesting; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Locale; /** * Handling smooth migration to the new high contrast text appearance @@ -128,14 +129,25 @@ public class HighContrastTextMigrationReceiver extends BroadcastReceiver { } } + private String getNotificationContentText(Context context) { + final String newName = context.getString( + R.string.accessibility_toggle_maximize_text_contrast_preference_title); + final String oldName = context.getString( + R.string.accessibility_toggle_high_text_contrast_preference_title) + .toLowerCase(Locale.getDefault()); + final String settingsAppName = context.getString(R.string.settings_label); + return context.getString( + R.string.accessibility_notification_high_contrast_text_body, + newName, oldName, settingsAppName); + } + private void showNotification(Context context) { Notification.Builder notificationBuilder = new Notification.Builder(context, NOTIFICATION_CHANNEL) .setSmallIcon(R.drawable.ic_settings_24dp) .setContentTitle(context.getString( R.string.accessibility_notification_high_contrast_text_title)) - .setContentText(context.getString( - R.string.accessibility_notification_high_contrast_text_content)) + .setContentText(getNotificationContentText(context)) .setFlag(Notification.FLAG_NO_CLEAR, true); Intent settingsIntent = createHighContrastTextSettingsIntent(context); @@ -149,8 +161,8 @@ public class HighContrastTextMigrationReceiver extends BroadcastReceiver { actionIntent, PendingIntent.FLAG_IMMUTABLE); Notification.Action settingsAction = new Notification.Action.Builder( /* icon= */ null, - context.getString( - R.string.accessibility_notification_high_contrast_text_action), + context.getString(R.string.accessibility_notification_high_contrast_text_action, + context.getString(R.string.settings_label)), actionPendingIntent ).build(); diff --git a/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java b/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java index b0864aa1073..98c2c239b00 100644 --- a/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/HighContrastTextMigrationReceiverTest.java @@ -46,9 +46,10 @@ import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; import com.android.graphics.hwui.flags.Flags; -import com.android.settings.R; import com.android.settings.Utils; +import com.google.common.truth.Expect; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -65,7 +66,8 @@ import java.util.List; /** Tests for {@link HighContrastTextMigrationReceiver}. */ @RunWith(RobolectricTestRunner.class) public class HighContrastTextMigrationReceiverTest { - + @Rule + public final Expect expect = Expect.create(); @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private final Context mContext = ApplicationProvider.getApplicationContext(); @@ -230,14 +232,12 @@ public class HighContrastTextMigrationReceiverTest { assertThat(notification).isNotNull(); ShadowNotification shadowNotification = Shadows.shadowOf(notification); - assertThat(shadowNotification.getContentTitle()).isEqualTo(mContext.getString( - R.string.accessibility_notification_high_contrast_text_title)); - assertThat(shadowNotification.getContentText()).isEqualTo( - mContext.getString(R.string.accessibility_notification_high_contrast_text_content)); + expect.that(shadowNotification.getContentTitle()).isEqualTo("Improve text contrast"); + expect.that(shadowNotification.getContentText()).isEqualTo( + "Outline text has replaced high contrast text. You can turn it on in Settings."); - assertThat(notification.actions.length).isEqualTo(1); - assertThat(notification.actions[0].title.toString()).isEqualTo( - mContext.getString(R.string.accessibility_notification_high_contrast_text_action)); + expect.that(notification.actions.length).isEqualTo(1); + expect.that(notification.actions[0].title.toString()).isEqualTo("Go to Settings"); } private void assertPromptStateAndHctState(