Better decoupling of Index updates in WiFi Settings
- use a Handler
Change-Id: I1e35f2e437021001900468d0df2b75e53b8c62f6
diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java
index 9f141ff..7adf806 100644
--- a/src/com/android/settings/wifi/WifiEnabler.java
+++ b/src/com/android/settings/wifi/WifiEnabler.java
@@ -24,6 +24,8 @@
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.os.Message;
import android.provider.Settings;
import android.widget.CompoundButton;
import android.widget.Switch;
@@ -64,6 +66,22 @@
}
};
+ private static final String EVENT_DATA_IS_WIFI_ON = "is_wifi_on";
+ private static final int EVENT_UPDATE_INDEX = 0;
+
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case EVENT_UPDATE_INDEX:
+ final boolean isWiFiOn = msg.getData().getBoolean(EVENT_DATA_IS_WIFI_ON);
+ Index.getInstance(mContext).updateFromClassNameResource(
+ WifiSettings.class.getName(), false, isWiFiOn);
+ break;
+ }
+ }
+ };
+
public WifiEnabler(Context context, Switch switch_) {
mContext = context;
mSwitch = switch_;
@@ -154,8 +172,12 @@
}
private void updateSearchIndex(boolean isWiFiOn) {
- Index.getInstance(mContext).updateFromClassNameResource(
- WifiSettings.class.getName(), false, isWiFiOn);
+ mHandler.removeMessages(EVENT_UPDATE_INDEX);
+
+ Message msg = new Message();
+ msg.what = EVENT_UPDATE_INDEX;
+ msg.getData().putBoolean(EVENT_DATA_IS_WIFI_ON, isWiFiOn);
+ mHandler.sendMessage(msg);
}
private void setSwitchChecked(boolean checked) {