Change PreferenceController#getSummary return type.
Return CharSequence instead of String.
All user visible string should be modeled as CharSequence.
Bug: 73950519
Test: robotest
Change-Id: I30befef0c33f94351d4a2774e283bd1ed804aa8b
diff --git a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
index e12c60a..0e24a10 100644
--- a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
@@ -82,19 +82,19 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
final int intensity = Settings.System.getInt(mContext.getContentResolver(),
mSettingKey, getDefaultIntensity());
switch (intensity) {
case Vibrator.VIBRATION_INTENSITY_OFF:
- return mContext.getString(R.string.accessibility_vibration_intensity_off);
+ return mContext.getText(R.string.accessibility_vibration_intensity_off);
case Vibrator.VIBRATION_INTENSITY_LOW:
- return mContext.getString(R.string.accessibility_vibration_intensity_low);
+ return mContext.getText(R.string.accessibility_vibration_intensity_low);
case Vibrator.VIBRATION_INTENSITY_MEDIUM:
- return mContext.getString(R.string.accessibility_vibration_intensity_medium);
+ return mContext.getText(R.string.accessibility_vibration_intensity_medium);
case Vibrator.VIBRATION_INTENSITY_HIGH:
- return mContext.getString(R.string.accessibility_vibration_intensity_high);
+ return mContext.getText(R.string.accessibility_vibration_intensity_high);
default:
return "";
}
diff --git a/src/com/android/settings/applications/AppPermissionsPreferenceController.java b/src/com/android/settings/applications/AppPermissionsPreferenceController.java
index 6100123..9bd8c0b 100644
--- a/src/com/android/settings/applications/AppPermissionsPreferenceController.java
+++ b/src/com/android/settings/applications/AppPermissionsPreferenceController.java
@@ -64,7 +64,7 @@
@Override
public void updateState(Preference preference) {
- final String summary = getSummary();
+ final CharSequence summary = getSummary();
if (summary != null) {
preference.setSummary(summary);
}
@@ -76,7 +76,7 @@
Location, Microphone, Camera, Sms, Contacts, and Phone
*/
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
final Set<String> permissions = getAllPermissionsInGroups();
Set<String> grantedPermissionGroups = getGrantedPermissionGroups(permissions);
CharSequence summary = null;
diff --git a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
index 7d3f946..8952de0 100644
--- a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
+++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
@@ -55,9 +55,9 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
int summaryResId = isDefaultApp() ? R.string.yes : R.string.no;
- return mContext.getString(summaryResId);
+ return mContext.getText(summaryResId);
}
@Override
diff --git a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
index 02f52b6..21c6195 100644
--- a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
@@ -61,7 +61,7 @@
}
@Override
- public String getSummary() {
- return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()).toString();
+ public CharSequence getSummary() {
+ return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry());
}
}
diff --git a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
index 73e7675..ec69b85 100644
--- a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
@@ -62,8 +62,8 @@
}
@Override
- public String getSummary() {
- return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString();
+ public CharSequence getSummary() {
+ return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry());
}
}
diff --git a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
index dccc310..1070ae9 100644
--- a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
+++ b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
@@ -51,11 +51,11 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
final boolean backupEnabled = mBackupManager.isBackupEnabled();
return backupEnabled
- ? mContext.getString(R.string.accessibility_feature_state_on)
- : mContext.getString(R.string.accessibility_feature_state_off);
+ ? mContext.getText(R.string.accessibility_feature_state_on)
+ : mContext.getText(R.string.accessibility_feature_state_off);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
index bf13e07..f2f220a 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
@@ -113,7 +113,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
String deviceName = getDeviceName();
if (TextUtils.isEmpty(deviceName)) {
return super.getSummary();
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
index cea0147..262d6b3 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
@@ -72,7 +72,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
return getDeviceName();
}
diff --git a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
index 0f1dea1..6d0302f 100644
--- a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
@@ -67,7 +67,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
return mDeviceName;
}
diff --git a/src/com/android/settings/fuelgauge/BatterySaverController.java b/src/com/android/settings/fuelgauge/BatterySaverController.java
index 83efefd..f139f31 100644
--- a/src/com/android/settings/fuelgauge/BatterySaverController.java
+++ b/src/com/android/settings/fuelgauge/BatterySaverController.java
@@ -103,7 +103,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
final boolean mode = mPowerManager.isPowerSaveMode();
final int format = mode ? R.string.battery_saver_on_summary
: R.string.battery_saver_off_summary;
diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
index 8b2fcc0..3a74a8c 100644
--- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
+++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
@@ -61,7 +61,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
if (!mFeatureProvider.isSensorAvailable(mContext)) {
return "";
}
@@ -72,13 +72,13 @@
contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0;
if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) {
- return mContext.getString(
+ return mContext.getText(
R.string.language_input_gesture_summary_on_with_assist);
}
if (assistGestureSilenceEnabled) {
- return mContext.getString(
+ return mContext.getText(
R.string.language_input_gesture_summary_on_non_assist);
}
- return mContext.getString(R.string.language_input_gesture_summary_off);
+ return mContext.getText(R.string.language_input_gesture_summary_off);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/notification/HeaderPreferenceController.java b/src/com/android/settings/notification/HeaderPreferenceController.java
index 5ec60c2..1247659 100644
--- a/src/com/android/settings/notification/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/HeaderPreferenceController.java
@@ -78,7 +78,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
if (mChannel != null) {
if (mChannelGroup != null && mChannelGroup.getGroup() != null
&& !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) {
diff --git a/src/com/android/settings/print/PrintSettingPreferenceController.java b/src/com/android/settings/print/PrintSettingPreferenceController.java
index 1f85c4c..7fb6734 100644
--- a/src/com/android/settings/print/PrintSettingPreferenceController.java
+++ b/src/com/android/settings/print/PrintSettingPreferenceController.java
@@ -93,7 +93,7 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
final List<PrintJob> printJobs = mPrintManager.getPrintJobs();
int numActivePrintJobs = 0;
@@ -112,7 +112,7 @@
final List<PrintServiceInfo> services =
mPrintManager.getPrintServices(PrintManager.ENABLED_SERVICES);
if (services == null || services.isEmpty()) {
- return mContext.getString(R.string.print_settings_summary_no_service);
+ return mContext.getText(R.string.print_settings_summary_no_service);
} else {
final int count = services.size();
return mContext.getResources().getQuantityString(
diff --git a/src/com/android/settings/security/ScreenPinningPreferenceController.java b/src/com/android/settings/security/ScreenPinningPreferenceController.java
index 305d076..36b25a3 100644
--- a/src/com/android/settings/security/ScreenPinningPreferenceController.java
+++ b/src/com/android/settings/security/ScreenPinningPreferenceController.java
@@ -38,11 +38,11 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
return Settings.System.getInt(mContext.getContentResolver(),
Settings.System.LOCK_TO_APP_ENABLED, 0) != 0
- ? mContext.getString(R.string.switch_on_text)
- : mContext.getString(R.string.switch_off_text);
+ ? mContext.getText(R.string.switch_on_text)
+ : mContext.getText(R.string.switch_off_text);
}
@Override
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index a01ea1b..35bc07e 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -57,7 +57,7 @@
final Icon icon = Icon.createWithResource(context, sliceData.getIconResource());
final BasePreferenceController controller = getPreferenceController(context, sliceData);
- final String subtitleText = getSubtitleText(context, controller, sliceData);
+ final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
final RowBuilder builder = new RowBuilder(context, sliceData.getUri())
.setTitle(sliceData.getTitle())
@@ -120,9 +120,9 @@
}
@VisibleForTesting
- static String getSubtitleText(Context context, AbstractPreferenceController controller,
+ static CharSequence getSubtitleText(Context context, AbstractPreferenceController controller,
SliceData sliceData) {
- String summaryText = sliceData.getSummary();
+ CharSequence summaryText = sliceData.getSummary();
if (isValidSummary(context, summaryText)) {
return summaryText;
}
@@ -138,13 +138,14 @@
return sliceData.getScreenTitle();
}
- private static boolean isValidSummary(Context context, String summary) {
- if (summary == null || TextUtils.isEmpty(summary.trim())) {
+ private static boolean isValidSummary(Context context, CharSequence summary) {
+ if (summary == null || TextUtils.isEmpty(summary.toString().trim())) {
return false;
}
- final String placeHolder = context.getString(R.string.summary_placeholder);
- final String doublePlaceHolder = context.getString(R.string.summary_two_lines_placeholder);
+ final CharSequence placeHolder = context.getText(R.string.summary_placeholder);
+ final CharSequence doublePlaceHolder =
+ context.getText(R.string.summary_two_lines_placeholder);
return !(TextUtils.equals(summary, placeHolder)
|| TextUtils.equals(summary, doublePlaceHolder));
diff --git a/src/com/android/settings/system/SystemUpdatePreferenceController.java b/src/com/android/settings/system/SystemUpdatePreferenceController.java
index 20f43ef..134166f 100644
--- a/src/com/android/settings/system/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/system/SystemUpdatePreferenceController.java
@@ -88,16 +88,16 @@
}
@Override
- public String getSummary() {
+ public CharSequence getSummary() {
final Bundle updateInfo = mUpdateManager.retrieveSystemUpdateInfo();
- String summary = mContext.getString(R.string.android_version_summary,
+ CharSequence summary = mContext.getString(R.string.android_version_summary,
Build.VERSION.RELEASE);
switch (updateInfo.getInt(SystemUpdateManager.KEY_STATUS)) {
case SystemUpdateManager.STATUS_WAITING_DOWNLOAD:
case SystemUpdateManager.STATUS_IN_PROGRESS:
case SystemUpdateManager.STATUS_WAITING_INSTALL:
case SystemUpdateManager.STATUS_WAITING_REBOOT:
- summary = mContext.getString(R.string.android_version_pending_update_summary);
+ summary = mContext.getText(R.string.android_version_pending_update_summary);
break;
case SystemUpdateManager.STATUS_UNKNOWN:
Log.d(TAG, "Update statue unknown");
diff --git a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
index d2333ba..5fc787b 100644
--- a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
@@ -106,17 +106,17 @@
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
mController.updateState(mPreference);
- verify(mActivity).getString(R.string.language_input_gesture_summary_off);
+ verify(mActivity).getText(R.string.language_input_gesture_summary_off);
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
mController.updateState(mPreference);
- verify(mActivity).getString(R.string.language_input_gesture_summary_on_with_assist);
+ verify(mActivity).getText(R.string.language_input_gesture_summary_on_with_assist);
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1);
mController.updateState(mPreference);
- verify(mActivity).getString(R.string.language_input_gesture_summary_on_non_assist);
+ verify(mActivity).getText(R.string.language_input_gesture_summary_on_non_assist);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 88e4695..184be5f 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -89,7 +89,7 @@
SliceData data = getDummyData();
FakePreferenceController controller = new FakePreferenceController(mContext, KEY);
- String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
+ CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
assertThat(summary).isEqualTo(data.getSummary());
}
@@ -101,7 +101,7 @@
String controllerSummary = "new_Summary";
doReturn(controllerSummary).when(controller).getSummary();
- String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
+ CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
assertThat(summary).isEqualTo(controllerSummary);
}
@@ -111,7 +111,7 @@
SliceData data = getDummyData((String) null);
FakePreferenceController controller = new FakePreferenceController(mContext, KEY);
- String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
+ CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
assertThat(summary).isEqualTo(data.getScreenTitle());
}
@@ -120,7 +120,7 @@
public void testDynamicSummary_placeHolderString_returnsScreenTitle() {
SliceData data = getDummyData(mContext.getString(R.string.summary_placeholder));
FakePreferenceController controller = new FakePreferenceController(mContext, KEY);
- String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
+ CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
assertThat(summary).isEqualTo(data.getScreenTitle());
}
@@ -132,7 +132,7 @@
FakePreferenceController controller = spy(new FakePreferenceController(mContext, KEY));
doReturn(summaryPlaceholder).when(controller).getSummary();
- String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
+ CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data);
assertThat(summary).isEqualTo(data.getScreenTitle());
}