Migrate to TwoStatePreference
SwitchPreference and SwitchPreferenceCompat are both TwoStatePreference. Using TwoStatePreference in Java will helps migration in the future. Bug: 306771414 Test: manual - check Settings pages Change-Id: I84e1d7b09451106797c2b23d127855c6976678ca
This commit is contained in:
@@ -22,7 +22,7 @@ import android.os.SystemProperties;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -43,7 +43,7 @@ public class BootSoundPreferenceController extends AbstractPreferenceController
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
SwitchPreference preference = screen.findPreference(KEY_BOOT_SOUNDS);
|
||||
TwoStatePreference preference = screen.findPreference(KEY_BOOT_SOUNDS);
|
||||
preference.setChecked(SystemProperties.getBoolean(PROPERTY_BOOT_SOUNDS, true));
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class BootSoundPreferenceController extends AbstractPreferenceController
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_BOOT_SOUNDS.equals(preference.getKey())) {
|
||||
SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
TwoStatePreference switchPreference = (TwoStatePreference) preference;
|
||||
SystemProperties.set(PROPERTY_BOOT_SOUNDS, switchPreference.isChecked() ? "1" : "0");
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -33,7 +33,7 @@ import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
@@ -81,7 +81,7 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
|
||||
new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference pref) {
|
||||
SwitchPreference preference = (SwitchPreference) pref;
|
||||
TwoStatePreference preference = (TwoStatePreference) pref;
|
||||
final boolean bypassDnd = preference.isChecked();
|
||||
for (NotificationChannel channel : mChannels) {
|
||||
if (showNotification(channel) && isChannelConfigurable(channel)) {
|
||||
|
||||
@@ -34,7 +34,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
@@ -313,7 +313,7 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
|
||||
&& isChannelGroupBlockable(group));
|
||||
preference.setChecked(!group.isBlocked());
|
||||
preference.setOnPreferenceClickListener(preference1 -> {
|
||||
final boolean allowGroup = ((SwitchPreference) preference1).isChecked();
|
||||
final boolean allowGroup = ((TwoStatePreference) preference1).isChecked();
|
||||
group.setBlocked(!allowGroup);
|
||||
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, group);
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ZenModeAlarmsPreferenceController extends
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
pref.setEnabled(false);
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ZenModeEventsPreferenceController extends AbstractZenModePreference
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
|
||||
@@ -22,7 +22,7 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ZenModeMediaPreferenceController extends AbstractZenModePreferenceC
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
pref.setEnabled(false);
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ZenModeRemindersPreferenceController extends AbstractZenModePrefere
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
|
||||
@@ -24,7 +24,7 @@ import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -65,7 +65,7 @@ public class ZenModeRepeatCallersPreferenceController extends AbstractZenModePre
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
|
||||
@@ -31,12 +31,13 @@ import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceClickListener;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
@@ -60,7 +61,8 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase {
|
||||
private Preference mDays;
|
||||
private TimePickerPreference mStart;
|
||||
private TimePickerPreference mEnd;
|
||||
private SwitchPreference mExitAtAlarm;
|
||||
@Nullable
|
||||
private TwoStatePreference mExitAtAlarm = null;
|
||||
private AlertDialog mDayDialog;
|
||||
private ScheduleInfo mSchedule;
|
||||
|
||||
@@ -135,7 +137,7 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase {
|
||||
root.addPreference(mEnd);
|
||||
mEnd.setDependency(mDays.getKey());
|
||||
|
||||
mExitAtAlarm = (SwitchPreference) root.findPreference(KEY_EXIT_AT_ALARM);
|
||||
mExitAtAlarm = root.findPreference(KEY_EXIT_AT_ALARM);
|
||||
mExitAtAlarm.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ZenModeSystemPreferenceController extends
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
pref.setEnabled(false);
|
||||
|
||||
@@ -22,7 +22,7 @@ import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -47,7 +47,7 @@ public class ZenRuleCustomSwitchPreferenceController extends
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
pref.setChecked(mRule.getZenPolicy().isCategoryAllowed(mCategory, false));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.util.Pair;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -52,7 +52,7 @@ public class ZenRuleRepeatCallersPreferenceController extends
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
boolean anyCallersCanBypassDnd = mRule.getZenPolicy().getPriorityCallSenders()
|
||||
== ZenPolicy.PEOPLE_TYPE_ANYONE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user