Use SettingsLib's MainSwitchBar to replace SwitchBar in Settings.
To log Settings metrics, the MainSwitch extends MainSwitchBar and replace the SwitchBar in SettingsActivity. Bug: 175181773 Test: Run robotest and apply the widget in Settings and see the ui Change-Id: I3add3702e9058ad9192b5172c7cf0e2ccfb55a70
This commit is contained in:
@@ -11,6 +11,7 @@ import android.os.ServiceManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@@ -21,8 +22,7 @@ import androidx.preference.PreferenceViewHolder;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.ToggleSwitch;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
|
||||
/**
|
||||
* Fragment to display a bunch of text about backup and restore, and allow the user to enable/
|
||||
@@ -41,8 +41,7 @@ public class ToggleBackupSettingFragment extends SettingsPreferenceFragment
|
||||
|
||||
private IBackupManager mBackupManager;
|
||||
|
||||
protected SwitchBar mSwitchBar;
|
||||
protected ToggleSwitch mToggleSwitch;
|
||||
protected SettingsMainSwitchBar mSwitchBar;
|
||||
|
||||
private Preference mSummaryPreference;
|
||||
|
||||
@@ -79,7 +78,6 @@ public class ToggleBackupSettingFragment extends SettingsPreferenceFragment
|
||||
|
||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mToggleSwitch = mSwitchBar.getSwitch();
|
||||
|
||||
// Set up UI.
|
||||
// If the user has not seen legal text for full data backup (if they OTA from L to M) then
|
||||
@@ -105,7 +103,7 @@ public class ToggleBackupSettingFragment extends SettingsPreferenceFragment
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
||||
mSwitchBar.setOnBeforeCheckedChangeListener(null);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@@ -115,11 +113,11 @@ public class ToggleBackupSettingFragment extends SettingsPreferenceFragment
|
||||
|
||||
// Set up toggle listener. We need this b/c we have to intercept the toggle event in order
|
||||
// to pop up the dialogue.
|
||||
mToggleSwitch.setOnBeforeCheckedChangeListener(
|
||||
new ToggleSwitch.OnBeforeCheckedChangeListener() {
|
||||
mSwitchBar.setOnBeforeCheckedChangeListener(
|
||||
new SettingsMainSwitchBar.OnBeforeCheckedChangeListener() {
|
||||
@Override
|
||||
public boolean onBeforeCheckedChanged(
|
||||
ToggleSwitch toggleSwitch, boolean checked) {
|
||||
Switch toggleSwitch, boolean checked) {
|
||||
if (!checked) {
|
||||
// Don't change Switch status until user makes choice in dialog
|
||||
// so return true here.
|
||||
|
Reference in New Issue
Block a user