Add progress bar and delay to WifiSettings refresh.
This change shows the progress bar for 0.3 seconds before AccessPoints are about to be refreshed and 1.7 afterwards for a total duration of roughly 2 seconds. This indirectly fixes issues with no longer having a refresh button, indicates ongoing scanning to the user, and should help avoid user errors where the user clicks on the wrong access point while the list is being updated. In order to avoid excess UI movement, the progress bar off state is now set to invisible rather than gone. Bug: b/34774783 Test: Currently blocked on refactor, tracked in b/36403635 and will start next week. Change-Id: I2bb6b5b3d4611cdbfd7138c758785601896d05b9
This commit is contained in:
@@ -629,71 +629,11 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
switch (wifiState) {
|
||||
case WifiManager.WIFI_STATE_ENABLED:
|
||||
// AccessPoints are sorted by the WifiTracker
|
||||
final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
|
||||
|
||||
boolean hasAvailableAccessPoints = false;
|
||||
mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
|
||||
cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
|
||||
|
||||
int index = configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
|
||||
boolean fewerNetworksThanLimit =
|
||||
accessPoints.size() <= index + NETWORKS_TO_INITIALLY_SHOW;
|
||||
int numAccessPointsToShow = mSeeAllNetworks || fewerNetworksThanLimit
|
||||
? accessPoints.size() : index + NETWORKS_TO_INITIALLY_SHOW;
|
||||
|
||||
for (; index < numAccessPointsToShow; index++) {
|
||||
AccessPoint accessPoint = accessPoints.get(index);
|
||||
// Ignore access points that are out of range.
|
||||
if (accessPoint.isReachable()) {
|
||||
String key = accessPoint.getBssid();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
key = accessPoint.getSsidStr();
|
||||
}
|
||||
hasAvailableAccessPoints = true;
|
||||
LongPressAccessPointPreference pref = (LongPressAccessPointPreference)
|
||||
getCachedPreference(key);
|
||||
if (pref != null) {
|
||||
pref.setOrder(index);
|
||||
continue;
|
||||
}
|
||||
LongPressAccessPointPreference
|
||||
preference = createLongPressActionPointPreference(accessPoint);
|
||||
preference.setKey(key);
|
||||
preference.setOrder(index);
|
||||
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
|
||||
&& !accessPoint.isSaved()
|
||||
&& accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
|
||||
onPreferenceTreeClick(preference);
|
||||
mOpenSsid = null;
|
||||
}
|
||||
mAccessPointsPreferenceCategory.addPreference(preference);
|
||||
accessPoint.setListener(this);
|
||||
preference.refresh();
|
||||
}
|
||||
}
|
||||
removeCachedPrefs(mAccessPointsPreferenceCategory);
|
||||
if (!hasAvailableAccessPoints) {
|
||||
setProgressBarVisible(true);
|
||||
Preference pref = new Preference(getPrefContext());
|
||||
pref.setSelectable(false);
|
||||
pref.setSummary(R.string.wifi_empty_list_wifi_on);
|
||||
pref.setOrder(index++);
|
||||
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
|
||||
mAccessPointsPreferenceCategory.addPreference(pref);
|
||||
} else {
|
||||
setProgressBarVisible(false);
|
||||
}
|
||||
if (mSeeAllNetworks || fewerNetworksThanLimit) {
|
||||
mAccessPointsPreferenceCategory.removePreference(mSeeAllNetworksPreference);
|
||||
mAddPreference.setOrder(index);
|
||||
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||
} else {
|
||||
mAccessPointsPreferenceCategory.removePreference(mAddPreference);
|
||||
mSeeAllNetworksPreference.setOrder(index);
|
||||
mAccessPointsPreferenceCategory.addPreference(mSeeAllNetworksPreference);
|
||||
}
|
||||
setConfigureWifiSettingsVisibility();
|
||||
setProgressBarVisible(true);
|
||||
// Have the progress bar displayed before starting to modify APs
|
||||
getView().postDelayed(() -> {
|
||||
updateAccessPointPreferences();
|
||||
}, 300 /* delay milliseconds */);
|
||||
break;
|
||||
|
||||
case WifiManager.WIFI_STATE_ENABLING:
|
||||
@@ -715,6 +655,79 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAccessPointPreferences() {
|
||||
// AccessPoints are sorted by the WifiTracker
|
||||
final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
|
||||
|
||||
boolean hasAvailableAccessPoints = false;
|
||||
mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
|
||||
cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
|
||||
|
||||
int index =
|
||||
configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
|
||||
boolean fewerNetworksThanLimit =
|
||||
accessPoints.size() <= index + NETWORKS_TO_INITIALLY_SHOW;
|
||||
int numAccessPointsToShow = mSeeAllNetworks || fewerNetworksThanLimit
|
||||
? accessPoints.size() : index + NETWORKS_TO_INITIALLY_SHOW;
|
||||
|
||||
for (; index < numAccessPointsToShow; index++) {
|
||||
AccessPoint accessPoint = accessPoints.get(index);
|
||||
// Ignore access points that are out of range.
|
||||
if (accessPoint.isReachable()) {
|
||||
String key = accessPoint.getBssid();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
key = accessPoint.getSsidStr();
|
||||
}
|
||||
hasAvailableAccessPoints = true;
|
||||
LongPressAccessPointPreference pref =
|
||||
(LongPressAccessPointPreference) getCachedPreference(key);
|
||||
if (pref != null) {
|
||||
pref.setOrder(index);
|
||||
continue;
|
||||
}
|
||||
LongPressAccessPointPreference preference =
|
||||
createLongPressActionPointPreference(accessPoint);
|
||||
preference.setKey(key);
|
||||
preference.setOrder(index);
|
||||
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
|
||||
&& !accessPoint.isSaved()
|
||||
&& accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
|
||||
onPreferenceTreeClick(preference);
|
||||
mOpenSsid = null;
|
||||
}
|
||||
mAccessPointsPreferenceCategory.addPreference(preference);
|
||||
accessPoint.setListener(WifiSettings.this);
|
||||
preference.refresh();
|
||||
}
|
||||
}
|
||||
removeCachedPrefs(mAccessPointsPreferenceCategory);
|
||||
if (mSeeAllNetworks || fewerNetworksThanLimit) {
|
||||
mAccessPointsPreferenceCategory.removePreference(mSeeAllNetworksPreference);
|
||||
mAddPreference.setOrder(index);
|
||||
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||
} else {
|
||||
mAccessPointsPreferenceCategory.removePreference(mAddPreference);
|
||||
mSeeAllNetworksPreference.setOrder(index);
|
||||
mAccessPointsPreferenceCategory.addPreference(mSeeAllNetworksPreference);
|
||||
}
|
||||
setConfigureWifiSettingsVisibility();
|
||||
|
||||
if (!hasAvailableAccessPoints) {
|
||||
setProgressBarVisible(true);
|
||||
Preference pref = new Preference(getPrefContext());
|
||||
pref.setSelectable(false);
|
||||
pref.setSummary(R.string.wifi_empty_list_wifi_on);
|
||||
pref.setOrder(index++);
|
||||
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
|
||||
mAccessPointsPreferenceCategory.addPreference(pref);
|
||||
} else {
|
||||
// Continuing showing progress bar for an additional delay to overlap with animation
|
||||
getView().postDelayed(() -> {
|
||||
setProgressBarVisible(false);
|
||||
}, 1700 /* delay millis */);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private LongPressAccessPointPreference createLongPressActionPointPreference(
|
||||
AccessPoint accessPoint) {
|
||||
@@ -844,7 +857,8 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
protected void setProgressBarVisible(boolean visible) {
|
||||
if (mProgressHeader != null) {
|
||||
mProgressHeader.setVisibility(visible && !isUiRestricted() ? View.VISIBLE : View.GONE);
|
||||
mProgressHeader.setVisibility(
|
||||
visible && !isUiRestricted() ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user