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