Better decoupling of Index updates in WiFi Settings

- use a Handler

Change-Id: I1e35f2e437021001900468d0df2b75e53b8c62f6
This commit is contained in:
Fabrice Di Meglio
2014-04-21 10:57:07 -07:00
parent f2dee29d66
commit 784f266cbd

View File

@@ -24,6 +24,8 @@ import android.net.NetworkInfo;
import android.net.wifi.SupplicantState; import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings; import android.provider.Settings;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.Switch; import android.widget.Switch;
@@ -64,6 +66,22 @@ public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
} }
}; };
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_) { public WifiEnabler(Context context, Switch switch_) {
mContext = context; mContext = context;
mSwitch = switch_; mSwitch = switch_;
@@ -154,8 +172,12 @@ public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
} }
private void updateSearchIndex(boolean isWiFiOn) { private void updateSearchIndex(boolean isWiFiOn) {
Index.getInstance(mContext).updateFromClassNameResource( mHandler.removeMessages(EVENT_UPDATE_INDEX);
WifiSettings.class.getName(), false, isWiFiOn);
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) { private void setSwitchChecked(boolean checked) {