Methods Summary |
---|
private android.preference.Preference | getDependencyPreference()
String depKey = mWifiCheckBoxPref.getDependency();
if (TextUtils.isEmpty(depKey)) {
return null;
}
return mWifiCheckBoxPref.getPreferenceManager().findPreference(depKey);
|
private static java.lang.String | getHumanReadableWifiState(int wifiState)
switch (wifiState) {
case WIFI_STATE_DISABLED:
return "Disabled";
case WIFI_STATE_DISABLING:
return "Disabling";
case WIFI_STATE_ENABLED:
return "Enabled";
case WIFI_STATE_ENABLING:
return "Enabling";
case WIFI_STATE_UNKNOWN:
return "Unknown";
default:
return "Some other state!";
}
|
private void | handleNetworkStateChanged(android.net.NetworkInfo networkInfo)
if (LOCAL_LOGD) {
Log.d(TAG, "Received network state changed to " + networkInfo);
}
if (mWifiManager.isWifiEnabled()) {
String summary = WifiStatus.getStatus(mContext,
mWifiManager.getConnectionInfo().getSSID(), networkInfo.getDetailedState());
mWifiCheckBoxPref.setSummary(summary);
}
|
private void | handleWifiStateChanged(int wifiState, int previousWifiState)
if (LOCAL_LOGD) {
Log.d(TAG, "Received wifi state changed from "
+ getHumanReadableWifiState(previousWifiState) + " to "
+ getHumanReadableWifiState(wifiState));
}
if (wifiState == WIFI_STATE_DISABLED || wifiState == WIFI_STATE_ENABLED) {
mWifiCheckBoxPref.setChecked(wifiState == WIFI_STATE_ENABLED);
mWifiCheckBoxPref
.setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null);
mWifiCheckBoxPref.setEnabled(isEnabledByDependency());
} else if (wifiState == WIFI_STATE_DISABLING || wifiState == WIFI_STATE_ENABLING) {
mWifiCheckBoxPref.setSummary(wifiState == WIFI_STATE_ENABLING ? R.string.wifi_starting
: R.string.wifi_stopping);
} else if (wifiState == WIFI_STATE_UNKNOWN) {
int message = R.string.wifi_error;
if (previousWifiState == WIFI_STATE_ENABLING) message = R.string.error_starting;
else if (previousWifiState == WIFI_STATE_DISABLING) message = R.string.error_stopping;
mWifiCheckBoxPref.setChecked(false);
mWifiCheckBoxPref.setSummary(message);
mWifiCheckBoxPref.setEnabled(true);
}
|
private boolean | isEnabledByDependency()
Preference dep = getDependencyPreference();
if (dep == null) {
return true;
}
return !dep.shouldDisableDependents();
|
public boolean | onPreferenceChange(android.preference.Preference preference, java.lang.Object value)
// Turn on/off Wi-Fi
setWifiEnabled((Boolean) value);
// Don't update UI to opposite state until we're sure
return false;
|
public void | pause()
mContext.unregisterReceiver(mWifiStateReceiver);
mWifiCheckBoxPref.setOnPreferenceChangeListener(null);
|
public void | resume()
int state = mWifiManager.getWifiState();
// This is the widget enabled state, not the preference toggled state
mWifiCheckBoxPref.setEnabled(state == WIFI_STATE_ENABLED || state == WIFI_STATE_DISABLED
|| state == WIFI_STATE_UNKNOWN);
mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
mWifiCheckBoxPref.setOnPreferenceChangeListener(this);
|
private void | setWifiEnabled(boolean enable)
// Disable button
mWifiCheckBoxPref.setEnabled(false);
if (!mWifiManager.setWifiEnabled(enable)) {
mWifiCheckBoxPref.setSummary(enable ? R.string.error_starting : R.string.error_stopping);
}
|