Search in sources :

Example 81 with ListPreference

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();
}
Also used : ListPreference(androidx.preference.ListPreference) Before(org.junit.Before)

Example 82 with ListPreference

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);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ListPreference(androidx.preference.ListPreference)

Example 83 with ListPreference

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashSet(java.util.HashSet) Set(java.util.Set) RestrictionEntry(android.content.RestrictionEntry) MultiSelectListPreference(androidx.preference.MultiSelectListPreference) ListPreference(androidx.preference.ListPreference)

Example 84 with ListPreference

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]);
}
Also used : ListPreference(androidx.preference.ListPreference)

Example 85 with ListPreference

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;
}
Also used : 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