Fix the problem that the ToggleSubscriptionDialogActivity
appears twice when switch changed. - Don't trigger the switch change event if the state of Switch and SwitchSettingsMainSwitchPreference are the same. Fix: 190767461 Test: robotest and operate the switch preference manually Change-Id: I6ab4b7e5ca1455948ca9118bb4a674fdc4fdbd50
This commit is contained in:
@@ -86,9 +86,12 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
||||
mEnforcedAdmin = mRestrictedHelper.checkRestrictionEnforced();
|
||||
}
|
||||
mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
|
||||
initMainSwitchBar();
|
||||
if (mIsVisible) {
|
||||
mMainSwitchBar.show();
|
||||
updateStatus(isChecked());
|
||||
if (mMainSwitchBar.isChecked() != isChecked()) {
|
||||
setChecked(isChecked());
|
||||
}
|
||||
registerListenerToSwitchBar();
|
||||
} else {
|
||||
mMainSwitchBar.hide();
|
||||
@@ -144,18 +147,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
||||
super.setChecked(isChecked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the switch status of preference
|
||||
*/
|
||||
public void updateStatus(boolean checked) {
|
||||
setChecked(checked);
|
||||
if (mMainSwitchBar != null) {
|
||||
mMainSwitchBar.setTitle(mTitle);
|
||||
mMainSwitchBar.setDisabledByAdmin(mEnforcedAdmin);
|
||||
mMainSwitchBar.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the MainSwitchBar
|
||||
*/
|
||||
@@ -251,6 +242,13 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
||||
}
|
||||
}
|
||||
|
||||
private void initMainSwitchBar() {
|
||||
if (mMainSwitchBar != null) {
|
||||
mMainSwitchBar.setTitle(mTitle);
|
||||
mMainSwitchBar.setDisabledByAdmin(mEnforcedAdmin);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListenerToSwitchBar() {
|
||||
for (OnBeforeCheckedChangeListener listener : mBeforeCheckedChangeListeners) {
|
||||
mMainSwitchBar.setOnBeforeCheckedChangeListener(listener);
|
||||
|
Reference in New Issue
Block a user