From c75417a75864f0fe1a4837c2cc3347cd1d8d83c5 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Wed, 28 May 2014 11:43:13 -0700 Subject: [PATCH] Fix bug #15170508 When I initially load settings, all on/off toggles ...start in off position then move to on after pane loads Another look at this issue. - start the Switch as View.GONE and make it View.VISIBLE when the Wi-Fi state is defined. Change-Id: I2f3077f779fc4030b2ba9ff3b21be8148add33c3 --- src/com/android/settings/wifi/WifiEnabler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java index 9f0b6fa53d4..d19004507d3 100644 --- a/src/com/android/settings/wifi/WifiEnabler.java +++ b/src/com/android/settings/wifi/WifiEnabler.java @@ -27,6 +27,7 @@ import android.net.wifi.WifiManager; import android.os.Handler; import android.os.Message; import android.provider.Settings; +import android.view.View; import android.widget.CompoundButton; import android.widget.Switch; import android.widget.Toast; @@ -88,6 +89,11 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { mContext = context; mSwitchBar = switchBar; mSwitch = switchBar.getSwitch(); + // This is a trick: as the Wi-Fi initial state is asynchronously coming from the + // BroadcastReceiver we cannot have the Switch visible at first otherwise you will notice + // its state change later on. So start it as VIEW.GONE and make it View.VISIBLE later + // when its state is defined. + mSwitch.setVisibility(View.GONE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); @@ -133,6 +139,7 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { mSwitch.setEnabled(true); updateSearchIndex(false); } + mSwitch.setVisibility(View.VISIBLE); } private void updateSearchIndex(boolean isWiFiOn) {