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:
@@ -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;
|
||||
}
|
||||
|
@@ -61,7 +61,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
private DreamBackend mBackend;
|
||||
private DreamInfoAdapter mAdapter;
|
||||
private SwitchBar mSwitchBar;
|
||||
private Switch mSwitch;
|
||||
private MenuItem[] mMenuItemsWhenEnabled;
|
||||
private boolean mRefreshing;
|
||||
|
||||
@@ -105,6 +104,9 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
public void onDestroyView() {
|
||||
logd("onDestroyView()");
|
||||
super.onDestroyView();
|
||||
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +126,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
final SettingsActivity sa = (SettingsActivity) getActivity();
|
||||
mSwitchBar = sa.getSwitchBar();
|
||||
mSwitch = mSwitchBar.getSwitch();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,9 +215,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
super.onPause();
|
||||
|
||||
mContext.unregisterReceiver(mPackageReceiver);
|
||||
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,9 +231,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||
filter.addDataScheme(PACKAGE_SCHEME);
|
||||
mContext.registerReceiver(mPackageReceiver , filter);
|
||||
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
public static int getSummaryResource(Context context) {
|
||||
@@ -263,8 +260,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
logd("refreshFromBackend()");
|
||||
mRefreshing = true;
|
||||
boolean dreamsEnabled = mBackend.isEnabled();
|
||||
if (mSwitch.isChecked() != dreamsEnabled)
|
||||
mSwitch.setChecked(dreamsEnabled);
|
||||
if (mSwitchBar.isChecked() != dreamsEnabled)
|
||||
mSwitchBar.setChecked(dreamsEnabled);
|
||||
|
||||
mAdapter.clear();
|
||||
if (dreamsEnabled) {
|
||||
|
@@ -142,27 +142,30 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
||||
refreshPreviewText();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
final boolean enabled = mCaptioningManager.isEnabled();
|
||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mSwitchBar.setTextViewLabel(enabled);
|
||||
mToggleSwitch = mSwitchBar.getSwitch();
|
||||
mToggleSwitch.setCheckedInternal(enabled);
|
||||
|
||||
getPreferenceScreen().setEnabled(enabled);
|
||||
|
||||
refreshPreviewText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
installSwitchBarToggleSwitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
removeSwitchBarToggleSwitch();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
private void refreshPreviewText() {
|
||||
|
@@ -95,17 +95,17 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
installActionBarToggleSwitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
removeActionBarToggleSwitch();
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
super.onPause();
|
||||
removeActionBarToggleSwitch();
|
||||
}
|
||||
|
||||
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
|
||||
|
@@ -89,6 +89,16 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
|
||||
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
}
|
||||
|
||||
public void setupSwitchBar() {
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
public void teardownSwitchBar() {
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
public void resume(Context context) {
|
||||
if (mLocalAdapter == null) {
|
||||
mSwitch.setEnabled(false);
|
||||
@@ -103,8 +113,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
|
||||
handleStateChanged(mLocalAdapter.getBluetoothState());
|
||||
|
||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
mValidListener = true;
|
||||
}
|
||||
|
||||
@@ -114,8 +122,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
|
||||
}
|
||||
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
mValidListener = false;
|
||||
}
|
||||
|
||||
|
@@ -119,6 +119,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
|
||||
mBluetoothEnabler = new BluetoothEnabler(activity, mSwitchBar);
|
||||
mBluetoothEnabler.setupSwitchBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mBluetoothEnabler.teardownSwitchBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -73,6 +73,16 @@ public class LocationSettings extends LocationSettingsBase
|
||||
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mSwitch = mSwitchBar.getSwitch();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,8 +94,6 @@ public class LocationSettings extends LocationSettingsBase
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
createPreferenceHierarchy();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
mValidListener = true;
|
||||
}
|
||||
|
||||
@@ -97,8 +105,6 @@ public class LocationSettings extends LocationSettingsBase
|
||||
// Ignore exceptions caused by race condition
|
||||
}
|
||||
super.onPause();
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
mValidListener = false;
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,6 @@ public class AndroidBeam extends Fragment
|
||||
private View mView;
|
||||
private NfcAdapter mNfcAdapter;
|
||||
private SwitchBar mSwitchBar;
|
||||
private Switch mSwitch;
|
||||
private CharSequence mOldActivityTitle;
|
||||
|
||||
@Override
|
||||
@@ -63,46 +62,33 @@ public class AndroidBeam extends Fragment
|
||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mSwitch = mSwitchBar.getSwitch();
|
||||
mSwitch.setChecked(mNfcAdapter.isNdefPushEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
mSwitchBar.setChecked(mNfcAdapter.isNdefPushEnabled());
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (mOldActivityTitle != null) {
|
||||
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
||||
}
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean desiredState) {
|
||||
boolean success = false;
|
||||
mSwitch.setEnabled(false);
|
||||
mSwitchBar.setEnabled(false);
|
||||
if (desiredState) {
|
||||
success = mNfcAdapter.enableNdefPush();
|
||||
} else {
|
||||
success = mNfcAdapter.disableNdefPush();
|
||||
}
|
||||
if (success) {
|
||||
mSwitch.setChecked(desiredState);
|
||||
mSwitchBar.setChecked(desiredState);
|
||||
}
|
||||
mSwitch.setEnabled(true);
|
||||
mSwitchBar.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
@@ -107,7 +107,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
private final SettingsObserver mSettingsObserver = new SettingsObserver();
|
||||
|
||||
private SwitchBar mSwitchBar;
|
||||
private Switch mSwitch;
|
||||
private Context mContext;
|
||||
private PackageManager mPM;
|
||||
private ZenModeConfig mConfig;
|
||||
@@ -159,7 +158,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
|
||||
|
||||
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
|
||||
mSwitch = mSwitchBar.getSwitch();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
|
||||
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
|
||||
|
||||
@@ -400,14 +400,17 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
updateControls();
|
||||
updateZenMode();
|
||||
mSettingsObserver.register();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mSettingsObserver.unregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
@@ -415,8 +418,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
private void updateZenMode() {
|
||||
final boolean zenMode = Global.getInt(getContentResolver(),
|
||||
Global.ZEN_MODE, Global.ZEN_MODE_OFF) != Global.ZEN_MODE_OFF;
|
||||
if (mSwitch.isChecked() != zenMode) {
|
||||
mSwitch.setChecked(zenMode);
|
||||
if (mSwitchBar.isChecked() != zenMode) {
|
||||
mSwitchBar.setChecked(zenMode);
|
||||
mIgnoreNext = true;
|
||||
}
|
||||
}
|
||||
|
@@ -143,16 +143,12 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
mSettingsContentObserver.register(getContentResolver());
|
||||
updateEmptyView();
|
||||
updateUiForServiceState();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mSettingsContentObserver.unregister(getContentResolver());
|
||||
super.onPause();
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -168,6 +164,8 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
||||
}
|
||||
super.onDestroyView();
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
private void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
@@ -292,6 +290,8 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
|
||||
mToggleSwitch = mSwitchBar.getSwitch();
|
||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() {
|
||||
|
@@ -17,10 +17,11 @@
|
||||
package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.transition.TransitionManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
@@ -72,12 +73,11 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
||||
mTextView.setText(R.string.switch_off_text);
|
||||
|
||||
mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
|
||||
mSwitch.setOnCheckedChangeListener(this);
|
||||
|
||||
addOnSwitchChangeListener(new OnSwitchChangeListener() {
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
mTextView.setText(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
||||
setTextViewLabel(isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -90,18 +90,41 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
||||
setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public ToggleSwitch getSwitch() {
|
||||
public void setTextViewLabel(boolean isChecked) {
|
||||
mTextView.setText(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
setTextViewLabel(checked);
|
||||
mSwitch.setChecked(checked);
|
||||
}
|
||||
|
||||
public boolean isChecked() {
|
||||
return mSwitch.isChecked();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
mTextView.setEnabled(enabled);
|
||||
mSwitch.setEnabled(false);
|
||||
}
|
||||
|
||||
public final ToggleSwitch getSwitch() {
|
||||
return mSwitch;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
TransitionManager.beginDelayedTransition((ViewGroup) getParent());
|
||||
setVisibility(View.VISIBLE);
|
||||
if (!isShowing()) {
|
||||
setVisibility(View.VISIBLE);
|
||||
mSwitch.setOnCheckedChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
TransitionManager.beginDelayedTransition((ViewGroup) getParent());
|
||||
setVisibility(View.GONE);
|
||||
if (isShowing()) {
|
||||
setVisibility(View.GONE);
|
||||
mSwitch.setOnCheckedChangeListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
@@ -139,4 +162,69 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
||||
}
|
||||
mSwitchChangeListeners.remove(listener);
|
||||
}
|
||||
|
||||
static class SavedState extends BaseSavedState {
|
||||
boolean checked;
|
||||
boolean visible;
|
||||
|
||||
SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor called from {@link #CREATOR}
|
||||
*/
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
checked = (Boolean)in.readValue(null);
|
||||
visible = (Boolean)in.readValue(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeValue(checked);
|
||||
out.writeValue(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SwitchBar.SavedState{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " checked=" + checked
|
||||
+ " visible=" + visible + "}";
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR
|
||||
= new Parcelable.Creator<SavedState>() {
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
|
||||
SavedState ss = new SavedState(superState);
|
||||
ss.checked = mSwitch.isChecked();
|
||||
ss.visible = isShowing();
|
||||
return ss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState ss = (SavedState) state;
|
||||
|
||||
super.onRestoreInstanceState(ss.getSuperState());
|
||||
mSwitch.setChecked(ss.checked);
|
||||
setTextViewLabel(ss.checked);
|
||||
setVisibility(ss.visible ? View.VISIBLE : View.GONE);
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
@@ -96,20 +96,26 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
||||
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
}
|
||||
|
||||
public void resume(Context context) {
|
||||
mContext = context;
|
||||
// Wi-Fi state is sticky, so just let the receiver update UI
|
||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||
public void setupSwitchBar() {
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
public void teardownSwitchBar() {
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
public void resume(Context context) {
|
||||
mContext = context;
|
||||
// Wi-Fi state is sticky, so just let the receiver update UI
|
||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void handleWifiStateChanged(int state) {
|
||||
switch (state) {
|
||||
case WifiManager.WIFI_STATE_ENABLING:
|
||||
|
@@ -404,6 +404,15 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
if (mWifiEnabler != null) {
|
||||
mWifiEnabler.teardownSwitchBar();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
@@ -414,6 +423,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mWifiEnabler = new WifiEnabler(activity, mSwitchBar);
|
||||
mWifiEnabler.setupSwitchBar();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user