use of com.android.settings.wifi.ConnectedWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class NetworkProviderSettings method updateWifiEntryPreferences.
protected void updateWifiEntryPreferences() {
// bypass the update if the activity and the view are not ready, or it's restricted UI.
if (getActivity() == null || getView() == null || mIsRestricted) {
return;
}
// in case state has changed
if (mWifiPickerTracker.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
return;
}
boolean hasAvailableWifiEntries = false;
mWifiEntryPreferenceCategory.setVisible(true);
final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry();
PreferenceCategory connectedWifiPreferenceCategory = getConnectedWifiPreferenceCategory();
connectedWifiPreferenceCategory.setVisible(connectedEntry != null);
if (connectedEntry != null) {
final LongPressWifiEntryPreference connectedPref = connectedWifiPreferenceCategory.findPreference(connectedEntry.getKey());
if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) {
connectedWifiPreferenceCategory.removeAll();
final ConnectedWifiEntryPreference pref = createConnectedWifiEntryPreference(connectedEntry);
pref.setKey(connectedEntry.getKey());
pref.refresh();
connectedWifiPreferenceCategory.addPreference(pref);
pref.setOnPreferenceClickListener(preference -> {
if (connectedEntry.canSignIn()) {
connectedEntry.signIn(null);
} else {
launchNetworkDetailsFragment(pref);
}
return true;
});
pref.setOnGearClickListener(preference -> {
launchNetworkDetailsFragment(pref);
});
if (mClickedConnect) {
mClickedConnect = false;
scrollToPreference(connectedWifiPreferenceCategory);
}
}
} else {
connectedWifiPreferenceCategory.removeAll();
}
int index = 0;
cacheRemoveAllPrefs(mWifiEntryPreferenceCategory);
List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
for (WifiEntry wifiEntry : wifiEntries) {
hasAvailableWifiEntries = true;
String key = wifiEntry.getKey();
LongPressWifiEntryPreference pref = (LongPressWifiEntryPreference) getCachedPreference(key);
if (pref != null) {
if (pref.getWifiEntry() == wifiEntry) {
pref.setOrder(index++);
continue;
} else {
// Create a new preference if the underlying WifiEntry object has changed
removePreference(key);
}
}
pref = createLongPressWifiEntryPreference(wifiEntry);
pref.setKey(wifiEntry.getKey());
pref.setOrder(index++);
pref.refresh();
if (wifiEntry.getHelpUriString() != null) {
pref.setOnButtonClickListener(preference -> {
openSubscriptionHelpPage(wifiEntry);
});
}
mWifiEntryPreferenceCategory.addPreference(pref);
}
removeCachedPrefs(mWifiEntryPreferenceCategory);
if (!hasAvailableWifiEntries) {
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);
mWifiEntryPreferenceCategory.addPreference(pref);
} else {
// Continuing showing progress bar for an additional delay to overlap with animation
getView().postDelayed(mHideProgressBarRunnable, 1700);
}
mAddWifiNetworkPreference.setOrder(index++);
mWifiEntryPreferenceCategory.addPreference(mAddWifiNetworkPreference);
setAdditionalSettingsSummaries();
}
use of com.android.settings.wifi.ConnectedWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class NetworkProviderSettingsTest method createConnectedWifiEntryPreference_internetWiFi_createConnectedPreference.
@Test
public void createConnectedWifiEntryPreference_internetWiFi_createConnectedPreference() {
final WifiEntry wifiEntry = mock(WifiEntry.class);
doReturn(InternetUpdater.INTERNET_WIFI).when(mInternetUpdater).getInternetType();
final Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(wifiEntry);
assertThat(p instanceof ConnectedWifiEntryPreference).isTrue();
}
Aggregations