[MainSwitchPreference] Remove SettingsMainSwitchPreferenceController
NO_IFTTT=Update base class Bug: 401406987 Flag: EXEMPT refactor Test: manual Change-Id: I68093366f63fa5b4184aa7b3dde8bc2609f17dfb
This commit is contained in:
@@ -28,8 +28,13 @@ import android.os.VibrationAttributes;
|
|||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
@@ -42,11 +47,12 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
|||||||
* be disabled by this setting, except the flagged alerts and accessibility touch feedback.
|
* be disabled by this setting, except the flagged alerts and accessibility touch feedback.
|
||||||
*/
|
*/
|
||||||
// LINT.IfChange
|
// LINT.IfChange
|
||||||
public class VibrationMainSwitchPreferenceController extends SettingsMainSwitchPreferenceController
|
public class VibrationMainSwitchPreferenceController extends TogglePreferenceController
|
||||||
implements LifecycleObserver, OnStart, OnStop {
|
implements LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
private final ContentObserver mSettingObserver;
|
private final ContentObserver mSettingObserver;
|
||||||
private final Vibrator mVibrator;
|
private final Vibrator mVibrator;
|
||||||
|
private @Nullable Preference mPreference;
|
||||||
|
|
||||||
public VibrationMainSwitchPreferenceController(Context context, String preferenceKey) {
|
public VibrationMainSwitchPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
@@ -55,7 +61,9 @@ public class VibrationMainSwitchPreferenceController extends SettingsMainSwitchP
|
|||||||
mSettingObserver = new ContentObserver(handler) {
|
mSettingObserver = new ContentObserver(handler) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange, Uri uri) {
|
public void onChange(boolean selfChange, Uri uri) {
|
||||||
updateState(mSwitchPreference);
|
if (mPreference != null) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -65,6 +73,12 @@ public class VibrationMainSwitchPreferenceController extends SettingsMainSwitchP
|
|||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mContext.getContentResolver().registerContentObserver(
|
mContext.getContentResolver().registerContentObserver(
|
||||||
|
@@ -27,34 +27,44 @@ import android.os.Looper;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
/** The controller to handle double tap power button main switch enable or disable state. */
|
/** The controller to handle double tap power button main switch enable or disable state. */
|
||||||
public class DoubleTapPowerMainSwitchPreferenceController
|
public class DoubleTapPowerMainSwitchPreferenceController
|
||||||
extends SettingsMainSwitchPreferenceController
|
extends TogglePreferenceController
|
||||||
implements LifecycleObserver, OnStart, OnStop {
|
implements LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
private final ContentObserver mSettingsObserver =
|
private final ContentObserver mSettingsObserver =
|
||||||
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||||
if (mSwitchPreference == null || uri == null) {
|
if (mPreference == null || uri == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateState(mSwitchPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private @Nullable Preference mPreference;
|
||||||
|
|
||||||
public DoubleTapPowerMainSwitchPreferenceController(
|
public DoubleTapPowerMainSwitchPreferenceController(
|
||||||
@NonNull Context context, @NonNull String preferenceKey) {
|
@NonNull Context context, @NonNull String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return DoubleTapPowerSettingsUtils
|
return DoubleTapPowerSettingsUtils
|
||||||
|
@@ -23,15 +23,14 @@ import android.provider.Settings;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link SettingsMainSwitchPreferenceController}
|
* {@link TogglePreferenceController}
|
||||||
* that controls whether Adaptive connectivity option is enabled.
|
* that controls whether Adaptive connectivity option is enabled.
|
||||||
*/
|
*/
|
||||||
// LINT.IfChange
|
// LINT.IfChange
|
||||||
public class AdaptiveConnectivityTogglePreferenceController extends
|
public class AdaptiveConnectivityTogglePreferenceController extends TogglePreferenceController {
|
||||||
SettingsMainSwitchPreferenceController {
|
|
||||||
|
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
|
|
||||||
|
@@ -25,10 +25,12 @@ import android.net.Uri;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
@@ -38,10 +40,11 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
|||||||
* Allows user to turn bubbles on or off for the device.
|
* Allows user to turn bubbles on or off for the device.
|
||||||
*/
|
*/
|
||||||
public class BubbleNotificationPreferenceController extends
|
public class BubbleNotificationPreferenceController extends
|
||||||
SettingsMainSwitchPreferenceController implements LifecycleObserver, OnResume, OnPause {
|
TogglePreferenceController implements LifecycleObserver, OnResume, OnPause {
|
||||||
|
|
||||||
private static final String TAG = "BubbleNotifPrefContr";
|
private static final String TAG = "BubbleNotifPrefContr";
|
||||||
|
|
||||||
|
private @Nullable Preference mPreference;
|
||||||
private SettingObserver mSettingObserver;
|
private SettingObserver mSettingObserver;
|
||||||
|
|
||||||
public BubbleNotificationPreferenceController(Context context, String preferenceKey) {
|
public BubbleNotificationPreferenceController(Context context, String preferenceKey) {
|
||||||
@@ -49,10 +52,11 @@ public class BubbleNotificationPreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
if (mSwitchPreference != null) {
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
mSettingObserver = new SettingObserver(mSwitchPreference);
|
if (mPreference != null) {
|
||||||
|
mSettingObserver = new SettingObserver(mPreference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,10 +21,9 @@ import android.content.Context;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class BundleGlobalPreferenceController extends
|
public class BundleGlobalPreferenceController extends TogglePreferenceController {
|
||||||
SettingsMainSwitchPreferenceController {
|
|
||||||
|
|
||||||
NotificationBackend mBackend;
|
NotificationBackend mBackend;
|
||||||
|
|
||||||
|
@@ -22,10 +22,9 @@ import android.service.notification.Adjustment;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class BundleTypePreferenceController extends
|
public class BundleTypePreferenceController extends TogglePreferenceController {
|
||||||
SettingsMainSwitchPreferenceController {
|
|
||||||
|
|
||||||
static final String PROMO_KEY = "promotions";
|
static final String PROMO_KEY = "promotions";
|
||||||
static final String NEWS_KEY = "news";
|
static final String NEWS_KEY = "news";
|
||||||
|
@@ -33,10 +33,10 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.server.notification.Flags;
|
import com.android.server.notification.Flags;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class LockScreenNotificationsGlobalPreferenceController
|
public class LockScreenNotificationsGlobalPreferenceController
|
||||||
extends SettingsMainSwitchPreferenceController
|
extends TogglePreferenceController
|
||||||
implements LifecycleEventObserver {
|
implements LifecycleEventObserver {
|
||||||
|
|
||||||
public static final int ON = 1;
|
public static final int ON = 1;
|
||||||
|
@@ -22,10 +22,9 @@ import android.provider.Settings;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.server.notification.Flags;
|
import com.android.server.notification.Flags;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class PoliteNotificationGlobalPreferenceController extends
|
public class PoliteNotificationGlobalPreferenceController extends TogglePreferenceController {
|
||||||
SettingsMainSwitchPreferenceController {
|
|
||||||
|
|
||||||
public static final int ON = 1;
|
public static final int ON = 1;
|
||||||
public static final int OFF = 0;
|
public static final int OFF = 0;
|
||||||
|
@@ -21,10 +21,9 @@ import android.content.Context;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class SummarizationGlobalPreferenceController extends
|
public class SummarizationGlobalPreferenceController extends TogglePreferenceController {
|
||||||
SettingsMainSwitchPreferenceController {
|
|
||||||
|
|
||||||
NotificationBackend mBackend;
|
NotificationBackend mBackend;
|
||||||
|
|
||||||
|
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.widget;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
import com.android.settingslib.widget.MainSwitchPreference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Preference controller for MainSwitchPreference.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link TogglePreferenceController} directly
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class SettingsMainSwitchPreferenceController extends
|
|
||||||
TogglePreferenceController implements OnCheckedChangeListener {
|
|
||||||
|
|
||||||
protected MainSwitchPreference mSwitchPreference;
|
|
||||||
|
|
||||||
public SettingsMainSwitchPreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
final Preference pref = screen.findPreference(getPreferenceKey());
|
|
||||||
if (pref != null && pref instanceof MainSwitchPreference) {
|
|
||||||
mSwitchPreference = (MainSwitchPreference) pref;
|
|
||||||
mSwitchPreference.addOnSwitchChangeListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
mSwitchPreference.setChecked(isChecked);
|
|
||||||
setChecked(isChecked);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -31,7 +31,6 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.widget.Switch;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -66,9 +65,6 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Switch mSwitch;
|
|
||||||
|
|
||||||
private BubbleNotificationPreferenceController mController;
|
private BubbleNotificationPreferenceController mController;
|
||||||
private MainSwitchPreference mPreference;
|
private MainSwitchPreference mPreference;
|
||||||
|
|
||||||
@@ -113,7 +109,7 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
public void onSwitchChanged_true_settingIsOff_flagShouldOn() {
|
public void onSwitchChanged_true_settingIsOff_flagShouldOn() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||||
|
|
||||||
mController.onCheckedChanged(mSwitch, true);
|
mController.setChecked(true);
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, OFF)).isEqualTo(ON);
|
NOTIFICATION_BUBBLES, OFF)).isEqualTo(ON);
|
||||||
@@ -123,7 +119,7 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
public void onSwitchChanged_false_settingIsOn_flagShouldOff() {
|
public void onSwitchChanged_false_settingIsOn_flagShouldOff() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||||
|
|
||||||
mController.onCheckedChanged(mSwitch, false);
|
mController.setChecked(false);
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
||||||
|
Reference in New Issue
Block a user