Search in sources :

Example 86 with ListPreference

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

the class BluetoothMaxConnectedAudioDevicesPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    final ListPreference listPreference = (ListPreference) preference;
    final CharSequence[] entries = listPreference.getEntries();
    final String currentValue = SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
    int index = 0;
    if (!currentValue.isEmpty()) {
        index = listPreference.findIndexOfValue(currentValue);
        if (index < 0) {
            // Reset property value when value is illegal
            SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, "");
            index = 0;
        }
    }
    listPreference.setValueIndex(index);
    listPreference.setSummary(entries[index]);
}
Also used : ListPreference(androidx.preference.ListPreference)

Example 87 with ListPreference

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

the class BluetoothSnoopLogPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    final ListPreference listPreference = (ListPreference) preference;
    final String currentValue = SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY);
    int index = getDefaultModeIndex();
    for (int i = 0; i < mListValues.length; i++) {
        if (TextUtils.equals(currentValue, mListValues[i])) {
            index = i;
            break;
        }
    }
    listPreference.setValue(mListValues[index]);
    listPreference.setSummary(mListEntries[index]);
}
Also used : ListPreference(androidx.preference.ListPreference)

Example 88 with ListPreference

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

the class BackgroundProcessLimitPreferenceController method updateAppProcessLimitOptions.

private void updateAppProcessLimitOptions() {
    try {
        final int limit = getActivityManagerService().getProcessLimit();
        // default
        int index = 0;
        for (int i = 0; i < mListValues.length; i++) {
            int val = Integer.parseInt(mListValues[i]);
            if (val >= limit) {
                index = i;
                break;
            }
        }
        final ListPreference listPreference = (ListPreference) mPreference;
        listPreference.setValue(mListValues[index]);
        listPreference.setSummary(mListSummaries[index]);
    } catch (RemoteException e) {
    // intentional no-op
    }
}
Also used : ListPreference(androidx.preference.ListPreference) RemoteException(android.os.RemoteException)

Example 89 with ListPreference

use of androidx.preference.ListPreference 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 90 with ListPreference

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

the class PlaybackPreferencesFragment method buildEnqueueLocationPreference.

private void buildEnqueueLocationPreference() {
    final Resources res = requireActivity().getResources();
    final Map<String, String> options = new ArrayMap<>();
    {
        String[] keys = res.getStringArray(R.array.enqueue_location_values);
        String[] values = res.getStringArray(R.array.enqueue_location_options);
        for (int i = 0; i < keys.length; i++) {
            options.put(keys[i], values[i]);
        }
    }
    ListPreference pref = requirePreference(UserPreferences.PREF_ENQUEUE_LOCATION);
    pref.setSummary(res.getString(R.string.pref_enqueue_location_sum, options.get(pref.getValue())));
    pref.setOnPreferenceChangeListener((preference, newValue) -> {
        if (!(newValue instanceof String)) {
            return false;
        }
        String newValStr = (String) newValue;
        pref.setSummary(res.getString(R.string.pref_enqueue_location_sum, options.get(newValStr)));
        return true;
    });
}
Also used : ArrayMap(androidx.collection.ArrayMap) Resources(android.content.res.Resources) ListPreference(androidx.preference.ListPreference)

Aggregations

ListPreference (androidx.preference.ListPreference)170 Test (org.junit.Test)24 Before (org.junit.Before)23 Preference (androidx.preference.Preference)20 EditTextPreference (androidx.preference.EditTextPreference)10 PreferenceScreen (androidx.preference.PreferenceScreen)10 SwitchPreference (androidx.preference.SwitchPreference)9 Context (android.content.Context)8 ContentResolver (android.content.ContentResolver)7 Intent (android.content.Intent)7 PersistableBundle (android.os.PersistableBundle)6 MultiSelectListPreference (androidx.preference.MultiSelectListPreference)6 Resources (android.content.res.Resources)5 Bundle (android.os.Bundle)5 RemoteException (android.os.RemoteException)5 RestrictionEntry (android.content.RestrictionEntry)4 OverlayInfo (android.content.om.OverlayInfo)4 ApplicationInfo (android.content.pm.ApplicationInfo)4 PackageInfo (android.content.pm.PackageInfo)4 WifiConfiguration (android.net.wifi.WifiConfiguration)4