use of androidx.preference.ListPreference in project android_packages_apps_Settings by omnirom.
the class BluetoothSnoopLogPreferenceControllerTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
doReturn(mSpyResources).when(mSpyContext).getResources();
// Get XML values without mock
// Setup test list preference using XML values
mPreference = new ListPreference(mSpyContext);
mPreference.setEntries(R.array.bt_hci_snoop_log_entries);
mPreference.setEntryValues(R.array.bt_hci_snoop_log_values);
// Init the actual controller
mController = new BluetoothSnoopLogPreferenceController(mSpyContext);
// Construct preference in the controller via a mocked preference screen object
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
mListValues = mPreference.getEntryValues();
mListEntries = mPreference.getEntries();
}
use of androidx.preference.ListPreference in project android_packages_apps_Settings by omnirom.
the class ThemePreferenceController method updateState.
@Override
public void updateState(Preference preference) {
ListPreference pref = (ListPreference) preference;
String[] pkgs = getAvailableThemes(false);
CharSequence[] labels = new CharSequence[pkgs.length];
for (int i = 0; i < pkgs.length; i++) {
try {
labels[i] = mPackageManager.getApplicationInfo(pkgs[i], 0).loadLabel(mPackageManager);
} catch (NameNotFoundException e) {
labels[i] = pkgs[i];
}
}
pref.setEntries(labels);
pref.setEntryValues(pkgs);
String theme = getCurrentTheme();
CharSequence themeLabel = null;
for (int i = 0; i < pkgs.length; i++) {
if (TextUtils.equals(pkgs[i], theme)) {
themeLabel = labels[i];
break;
}
}
if (TextUtils.isEmpty(themeLabel)) {
themeLabel = mContext.getString(R.string.default_theme);
}
pref.setSummary(themeLabel);
pref.setValue(theme);
}
use of androidx.preference.ListPreference in project android_packages_apps_Settings by omnirom.
the class AppRestrictionsFragment method onPreferenceChange.
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (key != null && key.contains(DELIMITER)) {
StringTokenizer st = new StringTokenizer(key, DELIMITER);
final String packageName = st.nextToken();
final String restrictionKey = st.nextToken();
AppRestrictionsPreference appPref = (AppRestrictionsPreference) mAppList.findPreference(PKG_PREFIX + packageName);
ArrayList<RestrictionEntry> restrictions = appPref.getRestrictions();
if (restrictions != null) {
for (RestrictionEntry entry : restrictions) {
if (entry.getKey().equals(restrictionKey)) {
switch(entry.getType()) {
case RestrictionEntry.TYPE_BOOLEAN:
entry.setSelectedState((Boolean) newValue);
break;
case RestrictionEntry.TYPE_CHOICE:
case RestrictionEntry.TYPE_CHOICE_LEVEL:
ListPreference listPref = (ListPreference) preference;
entry.setSelectedString((String) newValue);
String readable = findInArray(entry.getChoiceEntries(), entry.getChoiceValues(), (String) newValue);
listPref.setSummary(readable);
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
Set<String> set = (Set<String>) newValue;
String[] selectedValues = new String[set.size()];
set.toArray(selectedValues);
entry.setAllSelectedStrings(selectedValues);
break;
default:
continue;
}
mUserManager.setApplicationRestrictions(packageName, RestrictionsManager.convertRestrictionsToBundle(restrictions), mUser);
break;
}
}
}
return true;
}
return false;
}
use of androidx.preference.ListPreference in project android_packages_apps_Settings by omnirom.
the class BluetoothAvrcpVersionPreferenceController method updateState.
@Override
public void updateState(Preference preference) {
final ListPreference listPreference = (ListPreference) preference;
final String currentValue = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY);
// Defaults to AVRCP 1.5
int index = 0;
for (int i = 0; i < mListValues.length; i++) {
if (TextUtils.equals(currentValue, mListValues[i])) {
index = i;
break;
}
}
listPreference.setValue(mListValues[index]);
listPreference.setSummary(mListSummaries[index]);
}
use of androidx.preference.ListPreference in project android_packages_apps_Settings by omnirom.
the class BluetoothMaxConnectedAudioDevicesPreferenceController method onPreferenceChange.
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String newValueString = newValue.toString();
final ListPreference listPreference = (ListPreference) preference;
if (listPreference.findIndexOfValue(newValueString) <= 0) {
// Reset property value when default is chosen or when value is illegal
newValueString = "";
}
SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValueString);
updateState(preference);
return true;
}
Aggregations