Support getDynamicSummary in BasePreferenceController
Adds dynamic summary getter in relevant BasePreferenceControllers.
Preferece controllers that don't have dynamic summaries or which
are not yet BasePreferenceControllers are not changed right now.
Change-Id: I435ccab7758d90515583fd8ca10a9b1ef0c858b9
Fixes: 71514936
Test: robotests
diff --git a/src/com/android/settings/applications/AppPermissionsPreferenceController.java b/src/com/android/settings/applications/AppPermissionsPreferenceController.java
index c8ff381..6100123 100644
--- a/src/com/android/settings/applications/AppPermissionsPreferenceController.java
+++ b/src/com/android/settings/applications/AppPermissionsPreferenceController.java
@@ -75,7 +75,8 @@
The 3 permissions are the first three from the list which any app has granted:
Location, Microphone, Camera, Sms, Contacts, and Phone
*/
- private String getSummary() {
+ @Override
+ public String 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 fa67ec8..873c98c 100644
--- a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
+++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
@@ -14,7 +14,6 @@
package com.android.settings.applications.appinfo;
-import android.app.slice.Slice;
import android.content.Context;
import android.os.Bundle;
import android.os.UserManager;
@@ -52,7 +51,13 @@
@Override
public void updateState(Preference preference) {
- preference.setSummary(isDefaultApp() ? R.string.yes : R.string.no);
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
+ int summaryResId = isDefaultApp() ? R.string.yes : R.string.no;
+ return mContext.getString(summaryResId);
}
@Override
@@ -69,12 +74,14 @@
/**
* Check whether the app has the default app capability
+ *
* @return true if the app has the default app capability
*/
protected abstract boolean hasAppCapability();
/**
* Check whether the app is the default app
+ *
* @return true if the app is the default app
*/
protected abstract boolean isDefaultApp();
diff --git a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
index 37a9edf..02f52b6 100644
--- a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.UserManager;
-import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
@@ -61,9 +60,8 @@
return DrawOverlayDetails.class;
}
- @VisibleForTesting
- CharSequence getSummary() {
- return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry());
+ @Override
+ public String getSummary() {
+ return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()).toString();
}
-
}
diff --git a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
index 2a88d2f..73e7675 100644
--- a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.UserManager;
-import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
@@ -62,9 +61,9 @@
return WriteSettingsDetails.class;
}
- @VisibleForTesting
- CharSequence getSummary() {
- return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry());
- }
+ @Override
+ public String getSummary() {
+ return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString();
+ }
}
diff --git a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
index 7a7530c..dccc310 100644
--- a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
+++ b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
@@ -23,8 +23,6 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
public class BackupSettingsActivityPreferenceController extends BasePreferenceController {
private static final String TAG = "BackupSettingActivityPC";
@@ -49,10 +47,15 @@
@Override
public void updateState(Preference preference) {
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
final boolean backupEnabled = mBackupManager.isBackupEnabled();
- preference.setSummary(backupEnabled
- ? R.string.accessibility_feature_state_on
- : R.string.accessibility_feature_state_off);
+ return backupEnabled
+ ? mContext.getString(R.string.accessibility_feature_state_on)
+ : mContext.getString(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 2d0ce60..bf13e07 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
@@ -109,7 +109,19 @@
@Override
public void updateState(Preference preference) {
- updateDeviceName(preference, mLocalAdapter.getName());
+ updateDeviceName(preference);
+ }
+
+ @Override
+ public String getSummary() {
+ String deviceName = getDeviceName();
+ if (TextUtils.isEmpty(deviceName)) {
+ return super.getSummary();
+ }
+
+ return TextUtils.expandTemplate(
+ mContext.getText(R.string.bluetooth_device_name_summary),
+ BidiFormatter.getInstance().unicodeWrap(deviceName)).toString();
}
/**
@@ -132,18 +144,14 @@
* Update device summary with {@code deviceName}, where {@code deviceName} has accent color
*
* @param preference to set the summary for
- * @param deviceName bluetooth device name to show in the summary
*/
- protected void updateDeviceName(final Preference preference, final String deviceName) {
- if (deviceName == null) {
- // TODO: show error message in preference subtitle
- return;
- }
- final CharSequence summary = TextUtils.expandTemplate(
- mContext.getText(R.string.bluetooth_device_name_summary),
- BidiFormatter.getInstance().unicodeWrap(deviceName));
+ protected void updateDeviceName(final Preference preference) {
preference.setSelectable(false);
- preference.setSummary(summary);
+ preference.setSummary(getSummary());
+ }
+
+ protected String getDeviceName() {
+ return mLocalAdapter.getName();
}
/**
@@ -158,7 +166,7 @@
if (TextUtils.equals(action, BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED)) {
if (mPreference != null && mLocalAdapter != null && mLocalAdapter.isEnabled()) {
- updateDeviceName(mPreference, mLocalAdapter.getName());
+ updateDeviceName(mPreference);
}
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
index 69eefcf..a12d1a8 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
@@ -67,8 +67,13 @@
}
@Override
- protected void updateDeviceName(final Preference preference, final String deviceName) {
- preference.setSummary(deviceName);
+ protected void updateDeviceName(final Preference preference) {
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
+ return getDeviceName();
}
@Override
diff --git a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
index 92c33d8..a061f82 100644
--- a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
@@ -78,8 +78,12 @@
@Override
public void updateState(Preference preference) {
- preference.setSummary(mContext.getString(R.string.about_summary,
- Build.VERSION.RELEASE));
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
+ return mContext.getString(R.string.about_summary, Build.VERSION.RELEASE);
}
/**
diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
index 819b128..8b2fcc0 100644
--- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
+++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
@@ -24,7 +24,6 @@
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -58,25 +57,28 @@
@Override
public void updateState(Preference preference) {
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
if (!mFeatureProvider.isSensorAvailable(mContext)) {
- preference.setSummary("");
- return;
+ return "";
}
final ContentResolver contentResolver = mContext.getContentResolver();
final boolean assistGestureEnabled = Settings.Secure.getInt(
contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0;
final boolean assistGestureSilenceEnabled = Settings.Secure.getInt(
contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0;
- final String summary;
+
if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) {
- summary = mContext.getString(
+ return mContext.getString(
R.string.language_input_gesture_summary_on_with_assist);
- } else if (assistGestureSilenceEnabled) {
- summary = mContext.getString(
- R.string.language_input_gesture_summary_on_non_assist);
- } else {
- summary = mContext.getString(R.string.language_input_gesture_summary_off);
}
- preference.setSummary(summary);
+ if (assistGestureSilenceEnabled) {
+ return mContext.getString(
+ R.string.language_input_gesture_summary_on_non_assist);
+ }
+ return mContext.getString(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 3d51b25..5ec60c2 100644
--- a/src/com/android/settings/notification/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/HeaderPreferenceController.java
@@ -77,7 +77,8 @@
: mAppRow.label;
}
- CharSequence getSummary() {
+ @Override
+ public String getSummary() {
if (mChannel != null) {
if (mChannelGroup != null && mChannelGroup.getGroup() != null
&& !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) {
@@ -87,12 +88,12 @@
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(mChannelGroup.getGroup().getName().toString()));
- return summary;
+ return summary.toString();
} else {
- return mAppRow.label;
+ return mAppRow.label.toString();
}
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
- return mAppRow.label;
+ return mAppRow.label.toString();
} else {
return "";
}