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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations