Update Network & internet->Wi-Fi to use MasterSwitchPreference.

- Add a preference controller for Network & internet->Wi-Fi to control
  the preference toggling and summary update.
- Refactor WifiSettings and WifiEnabler to share code between the new
  wifi preference controller and the wifi setting.
- Refactor BluetoothSummaryHelper to have a common base class with the
  WifiSummaryHelper.
- Rename the summary helper to summary updater.

Bug: 34280769
Test: make RunSettingsRoboTests
Change-Id: I00ebfc161bcef89331bb41ba405ed8cb8232d248
This commit is contained in:
Doris Ling
2017-01-23 16:16:06 -08:00
parent 42c61c10cc
commit c4c9f4d50e
24 changed files with 926 additions and 171 deletions

View File

@@ -24,6 +24,7 @@ import android.widget.CompoundButton;
import android.widget.Switch;
import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
/**
* A custom preference that provides inline switch toggle. It has a mandatory field for title, and
@@ -76,7 +77,7 @@ public class MasterSwitchPreference extends Preference {
}
public boolean isChecked() {
return isEnabled() && mChecked;
return mSwitch != null && mSwitch.isEnabled() && mChecked;
}
public void setChecked(boolean checked) {
@@ -87,7 +88,7 @@ public class MasterSwitchPreference extends Preference {
}
public boolean isSwitchEnabled() {
return isEnabled() && mSwitch != null && mSwitch.isEnabled();
return mSwitch != null && mSwitch.isEnabled();
}
public void setSwitchEnabled(boolean enabled) {
@@ -96,6 +97,18 @@ public class MasterSwitchPreference extends Preference {
}
}
/**
* If admin is not null, disables the switch.
* Otherwise, keep it enabled.
*/
public void setDisabledByAdmin(EnforcedAdmin admin) {
setSwitchEnabled(admin == null);
}
public Switch getSwitch() {
return mSwitch;
}
private void init() {
setWidgetLayoutResource(R.layout.preference_widget_master_switch);
}