Search in sources :

Example 1 with ConnectedWifiEntryPreference

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();
}
Also used : LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) PreferenceCategory(androidx.preference.PreferenceCategory) FooterPreference(com.android.settingslib.widget.FooterPreference) DataUsagePreference(com.android.settings.datausage.DataUsagePreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) ConnectedWifiEntryPreference(com.android.settings.wifi.ConnectedWifiEntryPreference) AddWifiNetworkPreference(com.android.settings.wifi.AddWifiNetworkPreference) Preference(androidx.preference.Preference) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry) ConnectedWifiEntryPreference(com.android.settings.wifi.ConnectedWifiEntryPreference)

Example 2 with ConnectedWifiEntryPreference

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();
}
Also used : FooterPreference(com.android.settingslib.widget.FooterPreference) DataUsagePreference(com.android.settings.datausage.DataUsagePreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) ConnectedWifiEntryPreference(com.android.settings.wifi.ConnectedWifiEntryPreference) AddWifiNetworkPreference(com.android.settings.wifi.AddWifiNetworkPreference) Preference(androidx.preference.Preference) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry) ConnectedWifiEntryPreference(com.android.settings.wifi.ConnectedWifiEntryPreference) Test(org.junit.Test)

Aggregations

Preference (androidx.preference.Preference)2 DataUsagePreference (com.android.settings.datausage.DataUsagePreference)2 AddWifiNetworkPreference (com.android.settings.wifi.AddWifiNetworkPreference)2 ConnectedWifiEntryPreference (com.android.settings.wifi.ConnectedWifiEntryPreference)2 FooterPreference (com.android.settingslib.widget.FooterPreference)2 LayoutPreference (com.android.settingslib.widget.LayoutPreference)2 LongPressWifiEntryPreference (com.android.settingslib.wifi.LongPressWifiEntryPreference)2 WifiEntry (com.android.wifitrackerlib.WifiEntry)2 PreferenceCategory (androidx.preference.PreferenceCategory)1 Test (org.junit.Test)1