OSDN Git Service

Fix bug #15170508 When I initially load settings, all on/off toggles
authorFabrice Di Meglio <fdimeglio@google.com>
Wed, 28 May 2014 18:43:13 +0000 (11:43 -0700)
committerFabrice Di Meglio <fdimeglio@google.com>
Wed, 28 May 2014 18:43:13 +0000 (11:43 -0700)
...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

index 9f0b6fa..d190045 100644 (file)
@@ -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) {