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
This commit is contained in:
@@ -75,7 +75,8 @@ public class AppPermissionsPreferenceController extends AbstractPreferenceContro
|
||||
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;
|
||||
|
@@ -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 @@ public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePre
|
||||
|
||||
@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 @@ public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePre
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
@@ -21,7 +21,6 @@ import static android.Manifest.permission.SYSTEM_ALERT_WINDOW;
|
||||
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 @@ public class DrawOverlayDetailPreferenceController extends AppInfoPreferenceCont
|
||||
return DrawOverlayDetails.class;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
CharSequence getSummary() {
|
||||
return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry());
|
||||
@Override
|
||||
public String getSummary() {
|
||||
return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ import static android.Manifest.permission.WRITE_SETTINGS;
|
||||
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 @@ public class WriteSystemSettingsPreferenceController extends AppInfoPreferenceCo
|
||||
return WriteSettingsDetails.class;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
CharSequence getSummary() {
|
||||
return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry());
|
||||
}
|
||||
@Override
|
||||
public String getSummary() {
|
||||
return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -23,8 +23,6 @@ import android.support.v7.preference.Preference;
|
||||
|
||||
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 @@ public class BackupSettingsActivityPreferenceController extends BasePreferenceCo
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
@@ -109,7 +109,19 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
|
||||
@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 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
* 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 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
|
||||
if (TextUtils.equals(action, BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED)) {
|
||||
if (mPreference != null && mLocalAdapter != null && mLocalAdapter.isEnabled()) {
|
||||
updateDeviceName(mPreference, mLocalAdapter.getName());
|
||||
updateDeviceName(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -67,8 +67,13 @@ public class BluetoothDeviceRenamePreferenceController extends
|
||||
}
|
||||
|
||||
@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
|
||||
|
@@ -78,8 +78,12 @@ public class SystemUpdatePreferenceController extends BasePreferenceController {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -24,7 +24,6 @@ import android.support.v7.preference.Preference;
|
||||
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 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
@@ -77,7 +77,8 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
||||
: 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 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
||||
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 "";
|
||||
}
|
||||
|
@@ -96,8 +96,8 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
|
||||
mController.isDefault = true;
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary(R.string.yes);
|
||||
String yesString = mContext.getString(R.string.yes);
|
||||
verify(mPreference).setSummary(yesString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +106,8 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary(R.string.no);
|
||||
String noString = mContext.getString(R.string.no);
|
||||
verify(mPreference).setSummary(noString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -77,8 +77,8 @@ public class BackupSettingsActivityPreferenceControllerTest {
|
||||
mBackupEnabled = true;
|
||||
|
||||
mController.updateState(mBackupPreference);
|
||||
|
||||
verify(mBackupPreference).setSummary(R.string.accessibility_feature_state_on);
|
||||
String summaryString = mContext.getString(R.string.accessibility_feature_state_on);
|
||||
verify(mBackupPreference).setSummary(summaryString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,8 +86,8 @@ public class BackupSettingsActivityPreferenceControllerTest {
|
||||
mBackupEnabled = false;
|
||||
|
||||
mController.updateState(mBackupPreference);
|
||||
|
||||
verify(mBackupPreference).setSummary(R.string.accessibility_feature_state_off);
|
||||
String summaryString = mContext.getString(R.string.accessibility_feature_state_off);
|
||||
verify(mBackupPreference).setSummary(summaryString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -63,13 +63,14 @@ public class BluetoothDeviceNamePreferenceControllerTest {
|
||||
doReturn(mContext).when(mPreferenceScreen).getContext();
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(BluetoothDeviceNamePreferenceController.KEY_DEVICE_NAME);
|
||||
mController = new BluetoothDeviceNamePreferenceController(
|
||||
mContext, mLocalAdapter);
|
||||
mController = spy(new BluetoothDeviceNamePreferenceController(
|
||||
mContext, mLocalAdapter));
|
||||
doReturn(DEVICE_NAME).when(mController).getDeviceName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDeviceName_showSummaryWithDeviceName() {
|
||||
mController.updateDeviceName(mPreference, DEVICE_NAME);
|
||||
mController.updateDeviceName(mPreference);
|
||||
|
||||
final CharSequence summary = mPreference.getSummary();
|
||||
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -69,13 +70,14 @@ public class BluetoothDeviceRenamePreferenceControllerTest {
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(PREF_KEY);
|
||||
|
||||
mController = new BluetoothDeviceRenamePreferenceController(
|
||||
mContext, PREF_KEY, mFragment, mLocalAdapter);
|
||||
mController = spy(new BluetoothDeviceRenamePreferenceController(
|
||||
mContext, PREF_KEY, mFragment, mLocalAdapter));
|
||||
doReturn(DEVICE_NAME).when(mController).getDeviceName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDeviceName_showSummaryWithDeviceName() {
|
||||
mController.updateDeviceName(mPreference, DEVICE_NAME);
|
||||
mController.updateDeviceName(mPreference);
|
||||
|
||||
final CharSequence summary = mPreference.getSummary();
|
||||
|
||||
|
Reference in New Issue
Block a user