[WifiSetup] Restore enableNext behavior
Partial revert of ag/475394 which moved enable-next-on-connect behavior to setup wizard specific code. But account creation was using it outside of setup wizard context. Change-Id: I575976207a3ba2b5dac7e5467036e6ec7f519d9d
This commit is contained in:
@@ -39,6 +39,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
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;
|
||||||
@@ -96,8 +97,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private static final int WIFI_DIALOG_ID = 1;
|
private static final int WIFI_DIALOG_ID = 1;
|
||||||
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
||||||
private static final int WPS_PIN_DIALOG_ID = 3;
|
private static final int WPS_PIN_DIALOG_ID = 3;
|
||||||
/* package */ static final int WIFI_SKIPPED_DIALOG_ID = 4;
|
|
||||||
/* package */ static final int WIFI_AND_MOBILE_SKIPPED_DIALOG_ID = 5;
|
|
||||||
private static final int WRITE_NFC_DIALOG_ID = 6;
|
private static final int WRITE_NFC_DIALOG_ID = 6;
|
||||||
|
|
||||||
// Combo scans can take 5-6s to complete - set to 10s.
|
// Combo scans can take 5-6s to complete - set to 10s.
|
||||||
@@ -131,6 +130,13 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
private TextView mEmptyView;
|
private TextView mEmptyView;
|
||||||
|
|
||||||
|
// this boolean extra specifies whether to disable the Next button when not connected. Used by
|
||||||
|
// account creation outside of setup wizard.
|
||||||
|
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
|
||||||
|
|
||||||
|
// should Next button only be enabled when we have a connection?
|
||||||
|
private boolean mEnableNextOnConnection;
|
||||||
|
|
||||||
// Save the dialog details
|
// Save the dialog details
|
||||||
private boolean mDlgEdit;
|
private boolean mDlgEdit;
|
||||||
private AccessPoint mDlgAccessPoint;
|
private AccessPoint mDlgAccessPoint;
|
||||||
@@ -222,6 +228,23 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mAccessPointSavedState = savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
mAccessPointSavedState = savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we're supposed to enable/disable the Next button based on our current connection
|
||||||
|
// state, start it off in the right state
|
||||||
|
Intent intent = getActivity().getIntent();
|
||||||
|
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
||||||
|
|
||||||
|
if (mEnableNextOnConnection) {
|
||||||
|
if (hasNextButton()) {
|
||||||
|
final ConnectivityManager connectivity = (ConnectivityManager)
|
||||||
|
getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (connectivity != null) {
|
||||||
|
NetworkInfo info = connectivity.getNetworkInfo(
|
||||||
|
ConnectivityManager.TYPE_WIFI);
|
||||||
|
changeNextButtonState(info.isConnected());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.wifi_settings);
|
addPreferencesFromResource(R.xml.wifi_settings);
|
||||||
|
|
||||||
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
|
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
|
||||||
@@ -675,6 +698,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
||||||
WifiManager.EXTRA_NETWORK_INFO);
|
WifiManager.EXTRA_NETWORK_INFO);
|
||||||
mConnected.set(info.isConnected());
|
mConnected.set(info.isConnected());
|
||||||
|
changeNextButtonState(info.isConnected());
|
||||||
updateAccessPoints();
|
updateAccessPoints();
|
||||||
updateConnectionState(info.getDetailedState());
|
updateConnectionState(info.getDetailedState());
|
||||||
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
|
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
|
||||||
@@ -770,6 +794,18 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames/replaces "Next" button when appropriate. "Next" button usually exists in
|
||||||
|
* Wifi setup screens, not in usual wifi settings screen.
|
||||||
|
*
|
||||||
|
* @param enabled true when the device is connected to a wifi network.
|
||||||
|
*/
|
||||||
|
private void changeNextButtonState(boolean enabled) {
|
||||||
|
if (mEnableNextOnConnection && hasNextButton()) {
|
||||||
|
getNextButton().setEnabled(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int button) {
|
public void onClick(DialogInterface dialogInterface, int button) {
|
||||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
||||||
@@ -822,6 +858,9 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mScanner.resume();
|
mScanner.resume();
|
||||||
}
|
}
|
||||||
updateAccessPoints();
|
updateAccessPoints();
|
||||||
|
|
||||||
|
// We need to rename/replace "Next" button in wifi setup context.
|
||||||
|
changeNextButtonState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -54,18 +54,12 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
|
|
||||||
/* Used in Wifi Setup context */
|
/* Used in Wifi Setup context */
|
||||||
|
|
||||||
// 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";
|
|
||||||
|
|
||||||
// this boolean extra specifies whether to auto finish when connection is established
|
// this boolean extra specifies whether to auto finish when connection is established
|
||||||
private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
|
private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
|
||||||
|
|
||||||
// show a text regarding data charges when wifi connection is required during setup wizard
|
// show a text regarding data charges when wifi connection is required during setup wizard
|
||||||
protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
|
protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
|
||||||
|
|
||||||
// should Next button only be enabled when we have a connection?
|
|
||||||
private boolean mEnableNextOnConnection;
|
|
||||||
|
|
||||||
// should activity finish once we have a connection?
|
// should activity finish once we have a connection?
|
||||||
private boolean mAutoFinishOnConnection;
|
private boolean mAutoFinishOnConnection;
|
||||||
|
|
||||||
@@ -83,7 +77,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
||||||
WifiManager.EXTRA_NETWORK_INFO);
|
WifiManager.EXTRA_NETWORK_INFO);
|
||||||
changeNextButtonState(info.isConnected());
|
|
||||||
if (mAutoFinishOnConnection && info.isConnected()) {
|
if (mAutoFinishOnConnection && info.isConnected()) {
|
||||||
Log.d(TAG, "mReceiver.onReceive context=" + context + " intent=" + intent);
|
Log.d(TAG, "mReceiver.onReceive context=" + context + " intent=" + intent);
|
||||||
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
||||||
@@ -177,22 +170,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're supposed to enable/disable the Next button based on our current connection
|
|
||||||
// state, start it off in the right state
|
|
||||||
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
|
||||||
|
|
||||||
if (mEnableNextOnConnection) {
|
|
||||||
if (hasNextButton()) {
|
|
||||||
final ConnectivityManager connectivity = (ConnectivityManager)
|
|
||||||
activity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
if (connectivity != null) {
|
|
||||||
NetworkInfo info = connectivity.getNetworkInfo(
|
|
||||||
ConnectivityManager.TYPE_WIFI);
|
|
||||||
changeNextButtonState(info.isConnected());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -233,23 +210,4 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
ta.recycle();
|
ta.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
/* package */ void forget() {
|
|
||||||
super.forget();
|
|
||||||
|
|
||||||
// We need to rename/replace "Next" button in wifi setup context.
|
|
||||||
changeNextButtonState(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renames/replaces "Next" button when appropriate. "Next" button usually exists in
|
|
||||||
* Wifi setup screens, not in usual wifi settings screen.
|
|
||||||
*
|
|
||||||
* @param enabled true when the device is connected to a wifi network.
|
|
||||||
*/
|
|
||||||
private void changeNextButtonState(boolean enabled) {
|
|
||||||
if (mEnableNextOnConnection && hasNextButton()) {
|
|
||||||
getNextButton().setEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user