Search in sources :

Example 56 with ListPreference

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

the class ZenRuleMessagesPreferenceController method updateFromContactsValue.

private void updateFromContactsValue(Preference preference) {
    if (mRule == null || mRule.getZenPolicy() == null) {
        return;
    }
    ListPreference listPreference = (ListPreference) preference;
    listPreference.setSummary(mBackend.getContactsMessagesSummary(mRule.getZenPolicy()));
    final String currentVal = ZenModeBackend.getKeyFromZenPolicySetting(mRule.getZenPolicy().getPriorityMessageSenders());
    listPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
}
Also used : ListPreference(androidx.preference.ListPreference)

Example 57 with ListPreference

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

the class ThemePreferenceControllerTest method testUpdateState.

@Test
public void testUpdateState() throws Exception {
    OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android", "", OverlayInfo.CATEGORY_THEME, "", OverlayInfo.STATE_ENABLED, 0, 0, true);
    OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android", "", OverlayInfo.CATEGORY_THEME, "", 0, 0, 0, true);
    when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
        ApplicationInfo info = mock(ApplicationInfo.class);
        if ("com.android.Theme1".equals(inv.getArguments()[0])) {
            when(info.loadLabel(any())).thenReturn("Theme1");
        } else {
            when(info.loadLabel(any())).thenReturn("Theme2");
        }
        return info;
    });
    when(mMockPackageManager.getPackageInfo(anyString(), anyInt())).thenReturn(new PackageInfo());
    when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt())).thenReturn(list(info1, info2));
    ListPreference pref = mock(ListPreference.class);
    mPreferenceController.updateState(pref);
    ArgumentCaptor<String[]> arg = ArgumentCaptor.forClass(String[].class);
    verify(pref).setEntries(arg.capture());
    CharSequence[] entries = arg.getValue();
    assertThat(entries).asList().containsExactly("Theme1", "Theme2");
    verify(pref).setEntryValues(arg.capture());
    CharSequence[] entryValues = arg.getValue();
    assertThat(entryValues).asList().containsExactly("com.android.Theme1", "com.android.Theme2");
    verify(pref).setValue(eq("com.android.Theme1"));
}
Also used : PackageInfo(android.content.pm.PackageInfo) OverlayInfo(android.content.om.OverlayInfo) ApplicationInfo(android.content.pm.ApplicationInfo) ListPreference(androidx.preference.ListPreference) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 58 with ListPreference

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

the class WifiTetherSecurityPreferenceController method updateDisplay.

@Override
public void updateDisplay() {
    // keyword searching only.
    if (mPreference == null) {
        return;
    }
    final ListPreference preference = (ListPreference) mPreference;
    // If the device is not support WPA3 then remove the WPA3 options.
    if (!mIsWpa3Supported && mSecurityMap.keySet().removeIf(key -> key > SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)) {
        preference.setEntries(mSecurityMap.values().stream().toArray(CharSequence[]::new));
        preference.setEntryValues(mSecurityMap.keySet().stream().map(Integer::toBinaryString).toArray(CharSequence[]::new));
    }
    final int securityType = mWifiManager.getSoftApConfiguration().getSecurityType();
    mSecurityValue = mSecurityMap.get(securityType) != null ? securityType : SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
    preference.setSummary(mSecurityMap.get(mSecurityValue));
    preference.setValue(String.valueOf(mSecurityValue));
}
Also used : Context(android.content.Context) FeatureFlags(com.android.settings.core.FeatureFlags) NonNull(android.annotation.NonNull) Preference(androidx.preference.Preference) SoftApConfiguration(android.net.wifi.SoftApConfiguration) FeatureFlagUtils(android.util.FeatureFlagUtils) LinkedHashMap(java.util.LinkedHashMap) WifiManager(android.net.wifi.WifiManager) ListPreference(androidx.preference.ListPreference) SoftApCapability(android.net.wifi.SoftApCapability) Map(java.util.Map) DEDUP_POSTFIX(com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX) VisibleForTesting(androidx.annotation.VisibleForTesting) Log(android.util.Log) R(com.android.settings.R) ListPreference(androidx.preference.ListPreference)

Example 59 with ListPreference

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

the class GraphicsDriverAppPreferenceControllerTest method createPreference_configSystem_shouldSetSystemAttributes.

@Test
public void createPreference_configSystem_shouldSetSystemAttributes() {
    loadConfig("", "", TEST_PKG_NAME);
    final ListPreference preference = mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
    assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
    assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
    assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
    assertThat(preference.getEntries()).isEqualTo(mValueList);
    assertThat(preference.getEntryValues()).isEqualTo(mValueList);
    assertThat(preference.getEntry()).isEqualTo(mValueList[SYSTEM]);
    assertThat(preference.getValue()).isEqualTo(mValueList[SYSTEM]);
    assertThat(preference.getSummary()).isEqualTo(mValueList[SYSTEM]);
}
Also used : ListPreference(androidx.preference.ListPreference) Test(org.junit.Test)

Example 60 with ListPreference

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

the class GraphicsDriverAppPreferenceControllerTest method createPreference_configDefault_shouldSetDefaultAttributes.

@Test
public void createPreference_configDefault_shouldSetDefaultAttributes() {
    loadDefaultConfig();
    final ListPreference preference = mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
    assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
    assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
    assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
    assertThat(preference.getEntries()).isEqualTo(mValueList);
    assertThat(preference.getEntryValues()).isEqualTo(mValueList);
    assertThat(preference.getEntry()).isEqualTo(mValueList[DEFAULT]);
    assertThat(preference.getValue()).isEqualTo(mValueList[DEFAULT]);
    assertThat(preference.getSummary()).isEqualTo(mValueList[DEFAULT]);
}
Also used : ListPreference(androidx.preference.ListPreference) Test(org.junit.Test)

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