summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/development/DevelopmentSwitchBarController.java
diff options
context:
space:
mode:
authorFan Zhang <zhfan@google.com>2017-09-08 15:29:54 -0700
committerFan Zhang <zhfan@google.com>2017-09-12 10:25:43 -0700
commitd77881f88d0ef73a4492c214fceb505c2e555c95 (patch)
treec0ab9b018fe81783030771ce239e11ad3569e749 /src/com/android/settings/development/DevelopmentSwitchBarController.java
parentc939be65510c04963556af4b9262b7485b5762b6 (diff)
downloadpackages_apps_Settings-d77881f88d0ef73a4492c214fceb505c2e555c95.tar.gz
packages_apps_Settings-d77881f88d0ef73a4492c214fceb505c2e555c95.tar.bz2
packages_apps_Settings-d77881f88d0ef73a4492c214fceb505c2e555c95.zip
Add switch bar to enable/disable dev settings in new page.
Bug: 65522852 Test: make RunSettingsRoboTests -j40 ROBOTEST_FILTER=Development Change-Id: I0958950dc6aaee24d8d5e0be58d7564d108bc72e
Diffstat (limited to 'src/com/android/settings/development/DevelopmentSwitchBarController.java')
-rw-r--r--src/com/android/settings/development/DevelopmentSwitchBarController.java38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/com/android/settings/development/DevelopmentSwitchBarController.java b/src/com/android/settings/development/DevelopmentSwitchBarController.java
index 168f7c062b..ae875b3996 100644
--- a/src/com/android/settings/development/DevelopmentSwitchBarController.java
+++ b/src/com/android/settings/development/DevelopmentSwitchBarController.java
@@ -22,18 +22,39 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
public class DevelopmentSwitchBarController implements LifecycleObserver, OnStart, OnStop {
private final SwitchBar mSwitchBar;
private final boolean mIsAvailable;
private final DevelopmentSettings mSettings;
+ private final DevelopmentSettingsDashboardFragment mNewSettings;
+ /**
+ * @deprecated in favor of the other constructor.
+ */
+ @Deprecated
public DevelopmentSwitchBarController(DevelopmentSettings settings, SwitchBar switchBar,
boolean isAvailable, Lifecycle lifecycle) {
mSwitchBar = switchBar;
mIsAvailable = isAvailable && !Utils.isMonkeyRunning();
mSettings = settings;
+ mNewSettings = null;
+
+ if (mIsAvailable) {
+ lifecycle.addObserver(this);
+ } else {
+ mSwitchBar.setEnabled(false);
+ }
+ }
+
+ public DevelopmentSwitchBarController(DevelopmentSettingsDashboardFragment settings,
+ SwitchBar switchBar, boolean isAvailable, Lifecycle lifecycle) {
+ mSwitchBar = switchBar;
+ mIsAvailable = isAvailable && !Utils.isMonkeyRunning();
+ mSettings = null;
+ mNewSettings = settings;
if (mIsAvailable) {
lifecycle.addObserver(this);
@@ -44,11 +65,24 @@ public class DevelopmentSwitchBarController implements LifecycleObserver, OnStar
@Override
public void onStart() {
- mSwitchBar.addOnSwitchChangeListener(mSettings);
+ if (mSettings != null) {
+ mSwitchBar.addOnSwitchChangeListener(mSettings);
+ }
+ if (mNewSettings != null) {
+ final boolean developmentEnabledState = DevelopmentSettingsEnabler
+ .isDevelopmentSettingsEnabled(mNewSettings.getContext());
+ mSwitchBar.setChecked(developmentEnabledState);
+ mSwitchBar.addOnSwitchChangeListener(mNewSettings);
+ }
}
@Override
public void onStop() {
- mSwitchBar.removeOnSwitchChangeListener(mSettings);
+ if (mSettings != null) {
+ mSwitchBar.removeOnSwitchChangeListener(mSettings);
+ }
+ if (mNewSettings != null) {
+ mSwitchBar.removeOnSwitchChangeListener(mNewSettings);
+ }
}
}