Refactor badging notification preference controller.
- Convert inheritance from AbstractPreferenceController to TogglePreferenceController. - Register BadgingNotificationPreferenceController in XML. - Add RoboTests test cases for BadgingNotificationPreferenceController. Fixes: 67997784 Test: RunSettingsRoboTests Change-Id: If10744c067f065e7c2465ca1fff66895d7dc1c56 Merged-In: If10744c067f065e7c2465ca1fff66895d7dc1c56
This commit is contained in:
@@ -23,11 +23,13 @@ import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.DatabaseIndexingUtils;
|
||||
@@ -39,19 +41,20 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
|
||||
|
||||
public class BadgingNotificationPreferenceController extends AbstractPreferenceController
|
||||
public class BadgingNotificationPreferenceController extends TogglePreferenceController
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
||||
LifecycleObserver, OnResume, OnPause {
|
||||
|
||||
private static final String TAG = "BadgeNotifPrefContr";
|
||||
private static final String KEY_NOTIFICATION_BADGING = "notification_badging";
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
@VisibleForTesting
|
||||
static final int ON = 1;
|
||||
@VisibleForTesting
|
||||
static final int OFF = 0;
|
||||
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
public BadgingNotificationPreferenceController(Context context) {
|
||||
super(context);
|
||||
public BadgingNotificationPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,28 +81,22 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_NOTIFICATION_BADGING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getResources()
|
||||
.getBoolean(com.android.internal.R.bool.config_notificationBadging);
|
||||
.getBoolean(com.android.internal.R.bool.config_notificationBadging)
|
||||
? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean checked = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BADGING, ON) == ON;
|
||||
((TwoStatePreference) preference).setChecked(checked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean val = (Boolean) newValue;
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BADGING, val ? ON : OFF);
|
||||
NOTIFICATION_BADGING, isChecked ? ON : OFF);
|
||||
}
|
||||
|
||||
class SettingObserver extends ContentObserver {
|
||||
@@ -134,7 +131,7 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
ConfigureNotificationSettings.class.getName(), KEY_NOTIFICATION_BADGING,
|
||||
ConfigureNotificationSettings.class.getName(), getPreferenceKey(),
|
||||
mContext.getString(R.string.configure_notification_settings));
|
||||
|
||||
return new InlineSwitchPayload(Settings.Secure.NOTIFICATION_BADGING,
|
||||
|
Reference in New Issue
Block a user