Make the SwitchBar appear immediately

- change the way the SwitchBar is shown and hidden
- save its state
- remove the delay transition code

Change-Id: I07260430e6709b42517ca011f6d3c3446a626731
This commit is contained in:
Fabrice Di Meglio
2014-06-11 20:14:15 -07:00
parent 601aad2022
commit 138ff8c045
13 changed files with 197 additions and 86 deletions

View File

@@ -167,7 +167,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
private WifiManager mWifiManager;
private SwitchBar mSwitchBar;
private Switch mEnabledSwitch;
private boolean mLastEnabledState;
private boolean mHaveDebugSettings;
private boolean mDontPokeProperties;
@@ -386,11 +385,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
final SettingsActivity activity = (SettingsActivity) getActivity();
mSwitchBar = activity.getSwitchBar();
mEnabledSwitch = mSwitchBar.getSwitch();
if (mUnavailable) {
mEnabledSwitch.setEnabled(false);
if (mUnavailable) {
mSwitchBar.setEnabled(false);
return;
}
mSwitchBar.addOnSwitchChangeListener(this);
}
private boolean removePreferenceForProduction(Preference preference) {
@@ -441,7 +441,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
final ContentResolver cr = getActivity().getContentResolver();
mLastEnabledState = Settings.Global.getInt(cr,
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
mEnabledSwitch.setChecked(mLastEnabledState);
mSwitchBar.setChecked(mLastEnabledState);
setPrefsEnabledState(mLastEnabledState);
if (mHaveDebugSettings && !mLastEnabledState) {
@@ -452,17 +452,15 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mLastEnabledState = true;
mEnabledSwitch.setChecked(mLastEnabledState);
mSwitchBar.setChecked(mLastEnabledState);
setPrefsEnabledState(mLastEnabledState);
}
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
}
@Override
public void onPause() {
super.onPause();
public void onDestroyView() {
super.onDestroyView();
mSwitchBar.removeOnSwitchChangeListener(this);
mSwitchBar.hide();
@@ -1210,7 +1208,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
if (switchView != mEnabledSwitch) {
if (switchView != mSwitchBar.getSwitch()) {
return;
}
if (isChecked != mLastEnabledState) {
@@ -1463,7 +1461,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
setPrefsEnabledState(mLastEnabledState);
} else {
// Reset the toggle
mEnabledSwitch.setChecked(false);
mSwitchBar.setChecked(false);
}
}
}
@@ -1477,7 +1475,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
mAdbDialog = null;
} else if (dialog == mEnableDialog) {
if (!mDialogClicked) {
mEnabledSwitch.setChecked(false);
mSwitchBar.setChecked(false);
}
mEnableDialog = null;
}