Search in sources :

Example 6 with LongPressWifiEntryPreference

use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.

the class WifiSettings method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
    Preference preference = (Preference) view.getTag();
    if (!(preference instanceof LongPressWifiEntryPreference)) {
        // Do nothing.
        return;
    }
    // Cache the WifiEntry for onContextItemSelected. Don't use it in other methods.
    mSelectedWifiEntry = ((LongPressWifiEntryPreference) preference).getWifiEntry();
    menu.setHeaderTitle(mSelectedWifiEntry.getTitle());
    if (mSelectedWifiEntry.canConnect()) {
        menu.add(Menu.NONE, MENU_ID_CONNECT, 0, /* order */
        R.string.wifi_connect);
    }
    if (mSelectedWifiEntry.canDisconnect()) {
        menu.add(Menu.NONE, MENU_ID_SHARE, 0, /* order */
        R.string.share);
        menu.add(Menu.NONE, MENU_ID_DISCONNECT, 1, /* order */
        R.string.wifi_disconnect_button_text);
    }
    // could only be disconnected and be put in blocklists so it won't be used again.
    if (canForgetNetwork()) {
        menu.add(Menu.NONE, MENU_ID_FORGET, 0, /* order */
        R.string.forget);
    }
    WifiConfiguration config = mSelectedWifiEntry.getWifiConfiguration();
    // Some configs are ineditable
    if (WifiUtils.isNetworkLockedDown(getActivity(), config)) {
        return;
    }
    if (mSelectedWifiEntry.isSaved() && mSelectedWifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) {
        menu.add(Menu.NONE, MENU_ID_MODIFY, 0, /* order */
        R.string.wifi_modify);
    }
}
Also used : LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiConfiguration(android.net.wifi.WifiConfiguration) DataUsagePreference(com.android.settings.datausage.DataUsagePreference) Preference(androidx.preference.Preference) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference)

Example 7 with LongPressWifiEntryPreference

use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.

the class WifiSettings 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 8 with LongPressWifiEntryPreference

use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.

the class NetworkProviderSettingsTest method onCreateContextMenu_shouldHaveForgetAndDisconnectMenuForConnectedWifiEntry.

@Test
public void onCreateContextMenu_shouldHaveForgetAndDisconnectMenuForConnectedWifiEntry() {
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(activity.getApplicationContext()).thenReturn(mContext);
    when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
    final WifiEntry wifiEntry = mock(WifiEntry.class);
    when(wifiEntry.canDisconnect()).thenReturn(true);
    when(wifiEntry.canForget()).thenReturn(true);
    when(wifiEntry.isSaved()).thenReturn(true);
    when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
    final LongPressWifiEntryPreference connectedWifiEntryPreference = mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
    final View view = mock(View.class);
    when(view.getTag()).thenReturn(connectedWifiEntryPreference);
    final ContextMenu menu = mock(ContextMenu.class);
    mNetworkProviderSettings.onCreateContextMenu(menu, view, null);
    verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_FORGET), anyInt(), anyInt());
    verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_DISCONNECT), anyInt(), anyInt());
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry) ContextMenu(android.view.ContextMenu) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Test(org.junit.Test)

Aggregations

LongPressWifiEntryPreference (com.android.settingslib.wifi.LongPressWifiEntryPreference)8 WifiEntry (com.android.wifitrackerlib.WifiEntry)6 Preference (androidx.preference.Preference)4 DataUsagePreference (com.android.settings.datausage.DataUsagePreference)4 WifiConfiguration (android.net.wifi.WifiConfiguration)2 ContextMenu (android.view.ContextMenu)2 View (android.view.View)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)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 Test (org.junit.Test)2 PreferenceCategory (androidx.preference.PreferenceCategory)1