wifi settings option to only enable Next button once a wifi connection is established
Change-Id: I4b346648bce4b93f4885f1577a1510dcd18d8df5
This commit is contained in:
@@ -24,6 +24,7 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
@@ -62,6 +63,9 @@ public class WifiSettings extends PreferenceActivity implements DialogInterface.
|
|||||||
private static final int MENU_ID_FORGET = Menu.FIRST + 3;
|
private static final int MENU_ID_FORGET = Menu.FIRST + 3;
|
||||||
private static final int MENU_ID_MODIFY = Menu.FIRST + 4;
|
private static final int MENU_ID_MODIFY = Menu.FIRST + 4;
|
||||||
|
|
||||||
|
// this boolean extra specifies whether to disable the Next button when not connected
|
||||||
|
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
|
||||||
|
|
||||||
private final IntentFilter mFilter;
|
private final IntentFilter mFilter;
|
||||||
private final BroadcastReceiver mReceiver;
|
private final BroadcastReceiver mReceiver;
|
||||||
private final Scanner mScanner;
|
private final Scanner mScanner;
|
||||||
@@ -82,6 +86,9 @@ public class WifiSettings extends PreferenceActivity implements DialogInterface.
|
|||||||
private AccessPoint mSelected;
|
private AccessPoint mSelected;
|
||||||
private WifiDialog mDialog;
|
private WifiDialog mDialog;
|
||||||
|
|
||||||
|
// should Next button only be enabled when we have a connection?
|
||||||
|
private boolean mEnableNextOnConnection;
|
||||||
|
|
||||||
public WifiSettings() {
|
public WifiSettings() {
|
||||||
mFilter = new IntentFilter();
|
mFilter = new IntentFilter();
|
||||||
mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||||
@@ -107,6 +114,18 @@ public class WifiSettings extends PreferenceActivity implements DialogInterface.
|
|||||||
|
|
||||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||||
|
|
||||||
|
// if we're supposed to enable/disable the Next button based on our current connection
|
||||||
|
// state, start it off in the right state
|
||||||
|
mEnableNextOnConnection = getIntent().getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
||||||
|
if (mEnableNextOnConnection && hasNextButton()) {
|
||||||
|
ConnectivityManager connectivity = (ConnectivityManager)
|
||||||
|
getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (connectivity != null) {
|
||||||
|
NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
|
getNextButton().setEnabled(info.isConnected());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (getIntent().getBooleanExtra("only_access_points", false)) {
|
if (getIntent().getBooleanExtra("only_access_points", false)) {
|
||||||
addPreferencesFromResource(R.xml.wifi_access_points);
|
addPreferencesFromResource(R.xml.wifi_access_points);
|
||||||
} else {
|
} else {
|
||||||
@@ -420,8 +439,12 @@ public class WifiSettings extends PreferenceActivity implements DialogInterface.
|
|||||||
updateConnectionState(WifiInfo.getDetailedStateOf((SupplicantState)
|
updateConnectionState(WifiInfo.getDetailedStateOf((SupplicantState)
|
||||||
intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE)));
|
intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE)));
|
||||||
} else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
|
} else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
|
||||||
updateConnectionState(((NetworkInfo) intent.getParcelableExtra(
|
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
||||||
WifiManager.EXTRA_NETWORK_INFO)).getDetailedState());
|
WifiManager.EXTRA_NETWORK_INFO);
|
||||||
|
if (mEnableNextOnConnection && hasNextButton()) {
|
||||||
|
getNextButton().setEnabled(info.isConnected());
|
||||||
|
}
|
||||||
|
updateConnectionState(info.getDetailedState());
|
||||||
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
|
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
|
||||||
updateConnectionState(null);
|
updateConnectionState(null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user