Search in sources :

Example 16 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class NetworkProviderSettings method onSubmit.

@Override
public void onSubmit(WifiDialog2 dialog) {
    final int dialogMode = dialog.getMode();
    final WifiConfiguration config = dialog.getController().getConfig();
    final WifiEntry wifiEntry = dialog.getWifiEntry();
    if (dialogMode == WifiConfigUiBase2.MODE_MODIFY) {
        if (config == null) {
            Toast.makeText(getContext(), R.string.wifi_failed_save_message, Toast.LENGTH_SHORT).show();
        } else {
            mWifiManager.save(config, mSaveListener);
        }
    } else if (dialogMode == WifiConfigUiBase2.MODE_CONNECT || (dialogMode == WifiConfigUiBase2.MODE_VIEW && wifiEntry.canConnect())) {
        if (config == null) {
            connect(wifiEntry, false, /* editIfNoConfig */
            false);
        } else {
            mWifiManager.connect(config, new WifiConnectActionListener());
        }
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 17 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class NetworkProviderSettings method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    // If the preference has a fragment set, open that
    if (preference.getFragment() != null) {
        preference.setOnPreferenceClickListener(null);
        return super.onPreferenceTreeClick(preference);
    }
    if (preference instanceof LongPressWifiEntryPreference) {
        final WifiEntry selectedEntry = ((LongPressWifiEntryPreference) preference).getWifiEntry();
        if (selectedEntry.shouldEditBeforeConnect()) {
            launchConfigNewNetworkFragment(selectedEntry);
            return true;
        }
        connect(selectedEntry, true, /* editIfNoConfig */
        true);
    } else if (preference == mAddWifiNetworkPreference) {
        onAddNetworkPressed();
    } else {
        return super.onPreferenceTreeClick(preference);
    }
    return true;
}
Also used : LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 18 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry 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 19 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class WifiSettingsTest method onSubmit_modeConnectNoConfig_connectWifiEntry.

@Test
public void onSubmit_modeConnectNoConfig_connectWifiEntry() {
    WifiDialog2 dialog = createWifiDialog2(MODE_CONNECT, null);
    final WifiEntry wifiEntry = dialog.getWifiEntry();
    mWifiSettings.onAttach(mContext);
    mWifiSettings.onSubmit(dialog);
    verify(mWifiSettings).connect(wifiEntry, false, /* editIfNoConfig */
    false);
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry) Test(org.junit.Test)

Example 20 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class WifiSettingsTest method createWifiDialog2.

private WifiDialog2 createWifiDialog2(int mode, WifiConfiguration config) {
    final WifiEntry wifiEntry = mock(WifiEntry.class);
    when(wifiEntry.canConnect()).thenReturn(true);
    final WifiConfigController2 controller = mock(WifiConfigController2.class);
    when(controller.getConfig()).thenReturn(config);
    final WifiDialog2 wifiDialog2 = spy(WifiDialog2.createModal(mContext, null, /* listener */
    wifiEntry, mode));
    when(wifiDialog2.getController()).thenReturn(controller);
    return wifiDialog2;
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry)

Aggregations

WifiEntry (com.android.wifitrackerlib.WifiEntry)54 Test (org.junit.Test)28 WifiConfiguration (android.net.wifi.WifiConfiguration)10 WifiEntryPreference (com.android.settingslib.wifi.WifiEntryPreference)10 LongPressWifiEntryPreference (com.android.settingslib.wifi.LongPressWifiEntryPreference)8 Intent (android.content.Intent)7 Preference (androidx.preference.Preference)5 Context (android.content.Context)4 Bundle (android.os.Bundle)4 DataUsagePreference (com.android.settings.datausage.DataUsagePreference)4 WifiManager (android.net.wifi.WifiManager)3 Handler (android.os.Handler)3 View (android.view.View)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)3 AddWifiNetworkPreference (com.android.settings.wifi.AddWifiNetworkPreference)3 ConnectedWifiEntryPreference (com.android.settings.wifi.ConnectedWifiEntryPreference)3 FooterPreference (com.android.settingslib.widget.FooterPreference)3 LayoutPreference (com.android.settingslib.widget.LayoutPreference)3 ArrayList (java.util.ArrayList)3