Modify implementation around SetupWizard XL

Bug: 3005211
Change-Id: Ia01957725956d570370aceeab01750d77069001a
This commit is contained in:
Daisuke Miyakawa
2010-09-23 19:14:25 -07:00
parent e82a459392
commit 86eaa09aa4
4 changed files with 79 additions and 31 deletions

View File

@@ -87,6 +87,12 @@ public class WifiSettings extends SettingsPreferenceFragment
// Note: this is only effective in Setup Wizard with XL screen size.
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
// In SetupWizard XL, We limit the number of showable access points so that the
// ListView won't become larger than the screen.
//
// This constant doesn't affect other contexts other than SetupWizard XL.
private static int MAX_MENU_COUNT_IN_XL = 7;
private final IntentFilter mFilter;
private final BroadcastReceiver mReceiver;
private final Scanner mScanner;
@@ -113,6 +119,10 @@ public class WifiSettings extends SettingsPreferenceFragment
private WifiConfigPreference mConfigPreference;
private WifiDialog mDialog;
// Used only in SetupWizard XL, which remembers the network a user selected and
// refrain other available networks when trying to connect it.
private AccessPoint mConnectingAccessPoint;
private boolean mRefrainListUpdate;
public WifiSettings() {
@@ -370,7 +380,10 @@ public class WifiSettings extends SettingsPreferenceFragment
mConfigPreference = new WifiConfigPreference(this, this, accessPoint, edit);
toggleButtonsVisibility(false);
final Activity activity = getActivity();
if (activity instanceof WifiSettingsForSetupWizardXL) {
((WifiSettingsForSetupWizardXL)activity).onWifiConfigPreferenceAttached(edit);
}
updateAccessPoints();
mScanner.pause();
}
@@ -422,8 +435,10 @@ public class WifiSettings extends SettingsPreferenceFragment
}
}
if (mConfigPreference != null) {
mAccessPoints.removeAll();
mAccessPoints.removeAll();
if (mConnectingAccessPoint != null) {
mAccessPoints.addPreference(mConnectingAccessPoint);
} else if (mConfigPreference != null) {
final AccessPoint parent = mConfigPreference.getAccessPoint();
if (parent != null) {
parent.setSelectable(false);
@@ -433,9 +448,14 @@ public class WifiSettings extends SettingsPreferenceFragment
} else {
// AccessPoints are automatically sorted with TreeSet.
final Collection<AccessPoint> accessPoints = constructAccessPoints();
mAccessPoints.removeAll();
int count = MAX_MENU_COUNT_IN_XL;
for (AccessPoint accessPoint : accessPoints) {
mAccessPoints.addPreference(accessPoint);
count--;
if (count <= 0) {
break;
}
}
}
}
@@ -520,7 +540,8 @@ public class WifiSettings extends SettingsPreferenceFragment
// Maybe there's a WifiConfigPreference
Preference preference = mAccessPoints.getPreference(i);
if (preference instanceof AccessPoint) {
((AccessPoint) preference).update(mLastInfo, mLastState);
final AccessPoint accessPoint = (AccessPoint) preference;
accessPoint.update(mLastInfo, mLastState);
}
}
@@ -634,6 +655,11 @@ public class WifiSettings extends SettingsPreferenceFragment
break;
}
if (mInXlSetupWizard && mConfigPreference != null) {
mConnectingAccessPoint = mSelectedAccessPoint;
mConnectingAccessPoint.setSelectable(false);
}
detachConfigPreference();
}
@@ -656,6 +682,7 @@ public class WifiSettings extends SettingsPreferenceFragment
}
mConfigPreference = null;
mConnectingAccessPoint = null;
mAccessPoints.removeAll();
final Activity activity = getActivity();

View File

@@ -56,6 +56,13 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
private WifiSettings mWifiSettings;
private TextView mStatusText;
// This count reduces every time when there's a notification about WiFi status change.
// During the term this is >0, The system shows the message "connecting", regardless
// of the actual WiFi status. After this count's becoming 0, the status message correctly
// reflects what WiFi Picker told it. This is a tweak for letting users not confused
// with instable WiFi state during the first scan.
private int mIgnoringWifiNotificationCount = 5;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -70,6 +77,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
public void setup() {
mProgressText = (TextView)findViewById(R.id.scanning_progress_text);
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
mProgressBar = (ProgressBar)findViewById(R.id.scanning_progress_bar);
mProgressBar.setMax(2);
mProgressBar.setIndeterminate(true);
@@ -104,11 +112,13 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
mWifiSettings.forget();
break;
case R.id.wifi_setup_cancel:
mStatusText.setText(R.string.wifi_setup_status_select_network);
mWifiSettings.detachConfigPreference();
break;
}
}
// Called from WifiSettings
public void updateConnectionState(DetailedState originalState) {
final DetailedState state = stateMap.get(originalState);
switch (state) {
@@ -136,23 +146,29 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
mProgressBar.setProgress(2);
mStatusText.setText(R.string.wifi_setup_status_connected);
mProgressText.setText(Summary.get(this, state));
setResult(Activity.RESULT_OK);
finish();
break;
}
default: // Not connected.
mProgressBar.setIndeterminate(false);
mProgressBar.setProgress(0);
mStatusText.setText(R.string.wifi_setup_status_select_network);
mProgressText.setText(getString(R.string.wifi_setup_not_connected));
if (mWifiSettings.getAccessPointsCount() == 0 &&
mIgnoringWifiNotificationCount > 0) {
mIgnoringWifiNotificationCount--;
mProgressBar.setIndeterminate(true);
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
return;
} else {
mProgressBar.setIndeterminate(false);
mProgressBar.setProgress(0);
mStatusText.setText(R.string.wifi_setup_status_select_network);
mProgressText.setText(getString(R.string.wifi_setup_not_connected));
}
break;
}
}
public void onWifiConfigPreferenceAttached(boolean isNewNetwork) {
if (isNewNetwork) {
mStatusText.setText(R.string.wifi_setup_status_new_network);
} else {
mStatusText.setText(R.string.wifi_setup_status_existing_network);
}
mStatusText.setText(R.string.wifi_setup_status_edit_network);
}
public void onForget() {