Search in sources :

Example 96 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class HighlightablePreferenceGroupAdapterTest method adjustInitialExpandedChildCount_hasCountOverride_shouldDoNothing.

@Test
public void adjustInitialExpandedChildCount_hasCountOverride_shouldDoNothing() {
    when(mFragment.getInitialExpandedChildCount()).thenReturn(10);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(mFragment.getPreferenceScreen()).thenReturn(screen);
    HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
    verify(mFragment).getInitialExpandedChildCount();
    verify(screen).setInitialExpandedChildrenCount(10);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Test(org.junit.Test)

Example 97 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class HighlightablePreferenceGroupAdapterTest method adjustInitialExpandedChildCount_noKeyOrChildCountOverride_shouldDoNothing.

@Test
public void adjustInitialExpandedChildCount_noKeyOrChildCountOverride_shouldDoNothing() {
    final Bundle args = new Bundle();
    when(mFragment.getArguments()).thenReturn(args);
    when(mFragment.getInitialExpandedChildCount()).thenReturn(-1);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(mFragment.getPreferenceScreen()).thenReturn(screen);
    HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
    verify(mFragment).getInitialExpandedChildCount();
    verifyZeroInteractions(screen);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 98 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class HighlightablePreferenceGroupAdapterTest method adjustInitialExpandedChildCount_hasHightlightKey_shouldExpandAllChildren.

@Test
public void adjustInitialExpandedChildCount_hasHightlightKey_shouldExpandAllChildren() {
    final Bundle args = new Bundle();
    when(mFragment.getArguments()).thenReturn(args);
    args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, "testkey");
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(mFragment.getPreferenceScreen()).thenReturn(screen);
    HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
    verify(screen).setInitialExpandedChildrenCount(Integer.MAX_VALUE);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 99 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class WifiTetherSecurityPreferenceControllerTest method setUp.

@Before
public void setUp() {
    final Context context = spy(ApplicationProvider.getApplicationContext());
    mConfig = new SoftApConfiguration.Builder().setSsid("test_1234").setPassphrase(null, SoftApConfiguration.SECURITY_TYPE_OPEN).build();
    when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
    when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig);
    mController = new WifiTetherSecurityPreferenceController(context, mListener);
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    final PreferenceManager preferenceManager = new PreferenceManager(context);
    final PreferenceScreen screen = preferenceManager.createPreferenceScreen(context);
    mPreference = new ListPreference(context);
    mPreference.setKey(PREF_KEY);
    screen.addPreference(mPreference);
    mController.displayPreference(screen);
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) ListPreference(androidx.preference.ListPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 100 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project AntennaPod by AntennaPod.

the class AutoDownloadPreferencesFragment method buildAutodownloadSelectedNetworksPreference.

// getConfiguredNetworks needs location permission starting with API 29
@SuppressLint("MissingPermission")
private void buildAutodownloadSelectedNetworksPreference() {
    if (Build.VERSION.SDK_INT >= 29) {
        return;
    }
    final Activity activity = getActivity();
    if (selectedNetworks != null) {
        clearAutodownloadSelectedNetworsPreference();
    }
    // get configured networks
    WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
    if (networks == null) {
        Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
        return;
    }
    Collections.sort(networks, (x, y) -> blankIfNull(x.SSID).compareToIgnoreCase(blankIfNull(y.SSID)));
    selectedNetworks = new CheckBoxPreference[networks.size()];
    List<String> prefValues = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
    PreferenceScreen prefScreen = getPreferenceScreen();
    Preference.OnPreferenceClickListener clickListener = preference -> {
        if (preference instanceof CheckBoxPreference) {
            String key = preference.getKey();
            List<String> prefValuesList = new ArrayList<>(Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks()));
            boolean newValue = ((CheckBoxPreference) preference).isChecked();
            Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
            int index = prefValuesList.indexOf(key);
            if (index >= 0 && !newValue) {
                // remove network
                prefValuesList.remove(index);
            } else if (index < 0 && newValue) {
                prefValuesList.add(key);
            }
            UserPreferences.setAutodownloadSelectedNetworks(prefValuesList.toArray(new String[0]));
            return true;
        } else {
            return false;
        }
    };
    // value
    for (int i = 0; i < networks.size(); i++) {
        WifiConfiguration config = networks.get(i);
        CheckBoxPreference pref = new CheckBoxPreference(activity);
        String key = Integer.toString(config.networkId);
        pref.setTitle(config.SSID);
        pref.setKey(key);
        pref.setOnPreferenceClickListener(clickListener);
        pref.setPersistent(false);
        pref.setChecked(prefValues.contains(key));
        selectedNetworks[i] = pref;
        prefScreen.addPreference(pref);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) Arrays(java.util.Arrays) Bundle(android.os.Bundle) R(de.danoeh.antennapod.R) Preference(androidx.preference.Preference) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) ArrayList(java.util.ArrayList) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) WifiManager(android.net.wifi.WifiManager) SuppressLint(android.annotation.SuppressLint) CheckBoxPreference(androidx.preference.CheckBoxPreference) List(java.util.List) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) ListPreference(androidx.preference.ListPreference) Build(android.os.Build) Activity(android.app.Activity) Collections(java.util.Collections) Log(android.util.Log) Resources(android.content.res.Resources) WifiConfiguration(android.net.wifi.WifiConfiguration) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) PreferenceScreen(androidx.preference.PreferenceScreen) CheckBoxPreference(androidx.preference.CheckBoxPreference) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Activity(android.app.Activity) SuppressLint(android.annotation.SuppressLint) Preference(androidx.preference.Preference) CheckBoxPreference(androidx.preference.CheckBoxPreference) ListPreference(androidx.preference.ListPreference) ArrayList(java.util.ArrayList) List(java.util.List) SuppressLint(android.annotation.SuppressLint)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)229 Preference (androidx.preference.Preference)76 Test (org.junit.Test)60 PreferenceManager (androidx.preference.PreferenceManager)36 Context (android.content.Context)34 ContentResolver (android.content.ContentResolver)20 Bundle (android.os.Bundle)20 PreferenceCategory (androidx.preference.PreferenceCategory)20 ArrayList (java.util.ArrayList)20 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 SwitchPreference (androidx.preference.SwitchPreference)16 ListPreference (androidx.preference.ListPreference)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 PackageManager (android.content.pm.PackageManager)12 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8