Fix Wifi setup for xl.

- Show the title "Add network" correctly
- Handle ProgressBar on "Add network" flow correctly
- Handle possible NPE cases.

Bug: 3361270
Change-Id: Ic0fb808086bfce7b0f88e5703e617a62bc71667a
This commit is contained in:
Daisuke Miyakawa
2011-01-19 10:31:45 -08:00
parent 15649f8667
commit 4781d280d4

View File

@@ -93,9 +93,12 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
private Button mAddNetworkButton; private Button mAddNetworkButton;
private Button mRefreshButton; private Button mRefreshButton;
private Button mSkipOrNextButton; private Button mSkipOrNextButton;
private Button mConnectButton;
private Button mBackButton; private Button mBackButton;
private static int CONNECT_BUTTON_TAG_ADD_NETWORK = 1;
private Button mConnectButton;
private View mConnectingStatusLayout; private View mConnectingStatusLayout;
private TextView mConnectingStatusView; private TextView mConnectingStatusView;
@@ -113,6 +116,8 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
private int mPreviousSecurityFieldsVisibility = View.GONE; private int mPreviousSecurityFieldsVisibility = View.GONE;
private int mPreviousTypeVisibility = View.GONE; private int mPreviousTypeVisibility = View.GONE;
private DetailedState mPreviousState = DetailedState.DISCONNECTED;
// At first, we set "Skip" button disabled so that users won't press it soon after the screen // At first, we set "Skip" button disabled so that users won't press it soon after the screen
// migration. The button is enabled after the wifi module returns some result // migration. The button is enabled after the wifi module returns some result
// (a list of available network, etc.) One possible problem is that the notification from the // (a list of available network, etc.) One possible problem is that the notification from the
@@ -275,6 +280,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
showDisconnectedStatus(Summary.get(this, state)); showDisconnectedStatus(Summary.get(this, state));
break; break;
} }
mPreviousState = state;
} }
private void showDisconnectedStatus(String stateString) { private void showDisconnectedStatus(String stateString) {
@@ -299,31 +305,54 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
mTitleView.setText(getString(R.string.wifi_setup_title)); mTitleView.setText(getString(R.string.wifi_setup_title));
} }
private void showAddNetworkTitle() {
mNetworkName = "";
mTitleView.setText(R.string.wifi_setup_title_add_network);
}
private void showEditingTitle() { private void showEditingTitle() {
if (TextUtils.isEmpty(mNetworkName) && mWifiConfig != null) { if (TextUtils.isEmpty(mNetworkName) && mWifiConfig != null) {
mNetworkName = mWifiConfig.getController().getConfig().SSID; if (mWifiConfig.getController() != null &&
mWifiConfig.getController().getConfig() != null) {
mNetworkName = mWifiConfig.getController().getConfig().SSID;
} else {
Log.w(TAG, "Unexpected null found (WifiController or WifiConfig is null). " +
"Ignore them.");
}
} }
mTitleView.setText(getString(R.string.wifi_setup_title_editing_network, mNetworkName)); mTitleView.setText(getString(R.string.wifi_setup_title_editing_network, mNetworkName));
} }
private void showConnectingTitle() { private void showConnectingTitle() {
if (TextUtils.isEmpty(mNetworkName) && mWifiConfig != null) { if (TextUtils.isEmpty(mNetworkName) && mWifiConfig != null) {
mNetworkName = mWifiConfig.getController().getConfig().SSID; if (mWifiConfig.getController() != null &&
mWifiConfig.getController().getConfig() != null) {
mNetworkName = mWifiConfig.getController().getConfig().SSID;
} else {
Log.w(TAG, "Unexpected null found (WifiController or WifiConfig is null). " +
"Ignore them.");
}
} }
mTitleView.setText(getString(R.string.wifi_setup_title_connecting_network, mNetworkName)); mTitleView.setText(getString(R.string.wifi_setup_title_connecting_network, mNetworkName));
} }
private void showConnectedTitle() { private void showConnectedTitle() {
if (TextUtils.isEmpty(mNetworkName) && mWifiConfig != null) { if (TextUtils.isEmpty(mNetworkName) && mWifiConfig != null) {
mNetworkName = mWifiConfig.getController().getConfig().SSID; if (mWifiConfig.getController() != null &&
mWifiConfig.getController().getConfig() != null) {
mNetworkName = mWifiConfig.getController().getConfig().SSID;
} else {
Log.w(TAG, "Unexpected null found (WifiController or WifiConfig is null). " +
"Ignore them.");
}
} }
mTitleView.setText(getString(R.string.wifi_setup_title_connected_network, mNetworkName)); mTitleView.setText(getString(R.string.wifi_setup_title_connected_network, mNetworkName));
} }
private void showScanningStatus() { private void showScanningStatus() {
mProgressBar.setIndeterminate(true); mProgressBar.setIndeterminate(true);
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(false); mAddNetworkButton.setEnabled(false);
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(false); mRefreshButton.setEnabled(false);
} }
private void onAddNetworkButtonPressed() { private void onAddNetworkButtonPressed() {
@@ -356,47 +385,49 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
parent.setVisibility(View.VISIBLE); parent.setVisibility(View.VISIBLE);
parent.removeAllViews(); parent.removeAllViews();
mWifiConfig = new WifiConfigUiForSetupWizardXL(this, parent, selectedAccessPoint, edit); mWifiConfig = new WifiConfigUiForSetupWizardXL(this, parent, selectedAccessPoint, edit);
final View view = mWifiConfig.getView();
if (selectedAccessPoint != null) {
mNetworkName = selectedAccessPoint.getTitle().toString();
mTitleView.setText(getString(R.string.wifi_setup_title_editing_network, mNetworkName));
} else {
mNetworkName = "";
mTitleView.setText(R.string.wifi_setup_title_add_network);
view.findViewById(R.id.wifi_general_info).setVisibility(View.GONE);
}
if (selectedAccessPoint != null && // For safety, we forget the tag once. Tag will be updated in this method when needed.
selectedAccessPoint.security == AccessPoint.SECURITY_NONE) { mConnectButton.setTag(null);
if (selectedAccessPoint == null) { // "Add network" flow
showAddNetworkTitle();
if (mWifiConfig != null) {
mWifiConfig.getView().findViewById(R.id.wifi_general_info).setVisibility(View.GONE);
}
mConnectButton.setVisibility(View.VISIBLE);
mConnectButton.setTag(CONNECT_BUTTON_TAG_ADD_NETWORK);
showEditingButtonState();
} else if (selectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
mNetworkName = selectedAccessPoint.getTitle().toString();
// onConnectButtonPressed() will change visibility status. // onConnectButtonPressed() will change visibility status.
mConnectButton.performClick(); mConnectButton.performClick();
} else if (selectedAccessPoint != null &&
selectedAccessPoint.security == AccessPoint.SECURITY_EAP) {
mConnectButton.setVisibility(View.GONE);
showEditingTitle();
mSkipOrNextButton.setVisibility(View.GONE);
mAddNetworkButton.setVisibility(View.GONE);
mRefreshButton.setVisibility(View.GONE);
mBackButton.setVisibility(View.VISIBLE);
mBackButton.setText(R.string.wifi_setup_back);
} else { } else {
mConnectButton.setVisibility(View.VISIBLE); mNetworkName = selectedAccessPoint.getTitle().toString();
// WifiConfigController shows Connect button as "Save" when edit==true and a user
// tried to connect the network.
// In SetupWizard, we just show the button as "Connect" instead.
mConnectButton.setText(R.string.wifi_connect);
showEditingTitle(); showEditingTitle();
mSkipOrNextButton.setVisibility(View.GONE); showEditingButtonState();
mAddNetworkButton.setVisibility(View.GONE); if (selectedAccessPoint.security == AccessPoint.SECURITY_EAP) {
mRefreshButton.setVisibility(View.GONE); mConnectButton.setVisibility(View.GONE);
mBackButton.setVisibility(View.VISIBLE); mBackButton.setText(R.string.wifi_setup_back);
mBackButton.setText(R.string.wifi_setup_cancel); } else {
mConnectButton.setVisibility(View.VISIBLE);
// WifiConfigController shows Connect button as "Save" when edit==true and a user
// tried to connect the network.
// In SetupWizard, we just show the button as "Connect" instead.
mConnectButton.setText(R.string.wifi_connect);
mBackButton.setText(R.string.wifi_setup_cancel);
}
} }
} }
private void showEditingButtonState() {
mSkipOrNextButton.setVisibility(View.GONE);
mAddNetworkButton.setVisibility(View.GONE);
mRefreshButton.setVisibility(View.GONE);
mBackButton.setVisibility(View.VISIBLE);
}
// May be called when user press "connect" button in WifiDialog // May be called when user press "connect" button in WifiDialog
/* package */ void onConnectButtonPressed() { /* package */ void onConnectButtonPressed() {
mAfterConnectAction = true; mAfterConnectAction = true;
@@ -455,8 +486,6 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
// the "Connect" request and refresh the whole wifi status. // the "Connect" request and refresh the whole wifi status.
restoreFirstButtonVisibilityState(); restoreFirstButtonVisibilityState();
mAddNetworkButton.setEnabled(false);
mRefreshButton.setEnabled(false);
mSkipOrNextButton.setEnabled(true); mSkipOrNextButton.setEnabled(true);
changeNextButtonState(false); // Skip changeNextButtonState(false); // Skip
@@ -503,7 +532,15 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
} }
private void refreshAccessPoints(boolean disconnectNetwork) { private void refreshAccessPoints(boolean disconnectNetwork) {
showScanningStatus(); final Object tag = mConnectButton.getTag();
if (tag != null && (tag instanceof Integer) &&
((Integer)tag == CONNECT_BUTTON_TAG_ADD_NETWORK)) {
// In "Add network" flow, we won't get DetaledState available for changing ProgressBar
// state. Instead we manually show previous status here.
showDisconnectedStatus(Summary.get(this, mPreviousState));
} else {
showScanningStatus();
}
if (disconnectNetwork) { if (disconnectNetwork) {
mWifiManager.disconnect(); mWifiManager.disconnect();