diff options
author | Vinit Deshpande <vinitd@google.com> | 2014-09-15 20:18:35 -0700 |
---|---|---|
committer | Vinit Deshpande <vinitd@google.com> | 2014-09-15 20:18:35 -0700 |
commit | e2c1d504fc02c08078284841424dc9e6ce49c7d7 (patch) | |
tree | de83e12943ce7e6f43d0af4f176d3d5e669dc071 /src/com/android/settings/wifi/WifiEnabler.java | |
parent | 13fbd848d4d39e81bb79231f1d6f63722a7b36f6 (diff) | |
download | packages_apps_Settings-e2c1d504fc02c08078284841424dc9e6ce49c7d7.tar.gz packages_apps_Settings-e2c1d504fc02c08078284841424dc9e6ce49c7d7.tar.bz2 packages_apps_Settings-e2c1d504fc02c08078284841424dc9e6ce49c7d7.zip |
Fix automatic Wi-fi toggle
It is happening because there previous view doesn't disconnect
itself from setting change; and then two views alternatively
enable/disable wifi.
Bug: 17157005
Change-Id: I42916a7bbd735960a26efbae670c9b927ec8574d
Diffstat (limited to 'src/com/android/settings/wifi/WifiEnabler.java')
-rw-r--r-- | src/com/android/settings/wifi/WifiEnabler.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java index ffc10a0b3..8426439d3 100644 --- a/src/com/android/settings/wifi/WifiEnabler.java +++ b/src/com/android/settings/wifi/WifiEnabler.java @@ -40,6 +40,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { private Context mContext; private SwitchBar mSwitchBar; + private boolean mListeningToOnSwitchChange = false; private AtomicBoolean mConnected = new AtomicBoolean(false); private final WifiManager mWifiManager; @@ -99,23 +100,41 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { public void setupSwitchBar() { final int state = mWifiManager.getWifiState(); handleWifiStateChanged(state); - mSwitchBar.addOnSwitchChangeListener(this); + if (!mListeningToOnSwitchChange) { + mSwitchBar.addOnSwitchChangeListener(this); + mListeningToOnSwitchChange = true; + } mSwitchBar.show(); + + mContext.registerReceiver(mReceiver, mIntentFilter); } public void teardownSwitchBar() { - mSwitchBar.removeOnSwitchChangeListener(this); + if (mListeningToOnSwitchChange) { + mSwitchBar.removeOnSwitchChangeListener(this); + mListeningToOnSwitchChange = false; + } mSwitchBar.hide(); + + mContext.unregisterReceiver(mReceiver); } public void resume(Context context) { mContext = context; // Wi-Fi state is sticky, so just let the receiver update UI mContext.registerReceiver(mReceiver, mIntentFilter); + if (!mListeningToOnSwitchChange) { + mSwitchBar.addOnSwitchChangeListener(this); + mListeningToOnSwitchChange = true; + } } public void pause() { mContext.unregisterReceiver(mReceiver); + if (mListeningToOnSwitchChange) { + mSwitchBar.removeOnSwitchChangeListener(this); + mListeningToOnSwitchChange = false; + } } private void handleWifiStateChanged(int state) { |