Search in sources :

Example 96 with PreferenceCategory

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

the class UsbDetailsPowerRoleControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mLifecycle = new Lifecycle(() -> mLifecycle);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getActivity()).thenReturn(mActivity);
    when(mActivity.getApplicationContext()).thenReturn(mContext);
    when(mFragment.getContext()).thenReturn(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
    mDetailsPowerRoleController = new UsbDetailsPowerRoleController(mContext, mFragment, mUsbBackend);
    mPreference = new PreferenceCategory(mContext);
    mPreference.setKey(mDetailsPowerRoleController.getPreferenceKey());
    mScreen.addPreference(mPreference);
    mDetailsPowerRoleController.mHandler = mHandler;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 97 with PreferenceCategory

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

the class UsbDetailsDataRoleControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mLifecycle = new Lifecycle(() -> mLifecycle);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getActivity()).thenReturn(mActivity);
    when(mActivity.getApplicationContext()).thenReturn(mContext);
    when(mFragment.getContext()).thenReturn(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
    mDetailsDataRoleController = new UsbDetailsDataRoleController(mContext, mFragment, mUsbBackend);
    mPreference = new PreferenceCategory(mContext);
    mPreference.setKey(mDetailsDataRoleController.getPreferenceKey());
    mScreen.addPreference(mPreference);
    mDetailsDataRoleController.mHandler = mHandler;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 98 with PreferenceCategory

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

the class SettingsPreferenceFragmentTest method removePreference_nested_shouldRemove.

@Test
public void removePreference_nested_shouldRemove() {
    final String key = "test_key";
    final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
    when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    final PreferenceCategory nestedCategory = new ProgressCategory(mContext);
    final Preference preference = new Preference(mContext);
    preference.setKey(key);
    preference.setPersistent(false);
    mScreen.addPreference(nestedCategory);
    nestedCategory.addPreference(preference);
    assertThat(mFragment.removePreference(mScreen, key)).isTrue();
    assertThat(nestedCategory.getPreferenceCount()).isEqualTo(0);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 99 with PreferenceCategory

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

the class PlatformCompatDashboardTest method createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries.

@Test
public void createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries() {
    Set<Long> enabledChanges = new HashSet<>();
    enabledChanges.add(mChanges[0].getId());
    enabledChanges.add(mChanges[1].getId());
    enabledChanges.add(mChanges[2].getId());
    Set<Long> disabledChanges = new HashSet<>();
    disabledChanges.add(mChanges[3].getId());
    disabledChanges.add(mChanges[4].getId());
    CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(enabledChanges, disabledChanges));
    List<CompatibilityChangeInfo> changesToAdd = new ArrayList<>();
    for (int i = 0; i < mChanges.length; ++i) {
        changesToAdd.add(new CompatibilityChangeInfo(mChanges[i].getId(), mChanges[i].getName(), -1, mChanges[i].getEnableSinceTargetSdk(), mChanges[i].getDisabled(), mChanges[i].getLoggingOnly(), mChanges[i].getDescription(), mChanges[i].getOverridable()));
    }
    PreferenceCategory category = mDashboard.createChangeCategoryPreference(changesToAdd, config, "foo");
    assertThat(category.getTitle()).isEqualTo("foo");
    assertThat(category.getPreferenceCount()).isEqualTo(mChanges.length);
    for (int i = 0; i < mChanges.length; ++i) {
        Preference childPreference = category.getPreference(i);
        assertThat(childPreference instanceof SwitchPreference).isTrue();
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArrayList(java.util.ArrayList) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) HashSet(java.util.HashSet) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) Test(org.junit.Test)

Example 100 with PreferenceCategory

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

the class GraphicsDriverAppPreferenceControllerTest method loadConfig.

private void loadConfig(String optIn, String prereleaseOptIn, String optOut) {
    Settings.Global.putString(mResolver, Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS, optIn);
    Settings.Global.putString(mResolver, Settings.Global.UPDATABLE_DRIVER_PRERELEASE_OPT_IN_APPS, prereleaseOptIn);
    Settings.Global.putString(mResolver, Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS, optOut);
    mController = new GraphicsDriverAppPreferenceController(mContext, "testKey");
    mController.mEntryList = mContext.getResources().getStringArray(R.array.graphics_driver_app_preference_values);
    mGroup = spy(new PreferenceCategory(mContext));
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    when(mGroup.getContext()).thenReturn(mContext);
    when(mGroup.getPreferenceManager()).thenReturn(preferenceManager);
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mGroup);
    mController.displayPreference(mScreen);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager)

Aggregations

PreferenceCategory (androidx.preference.PreferenceCategory)111 Preference (androidx.preference.Preference)38 PreferenceManager (androidx.preference.PreferenceManager)24 Before (org.junit.Before)24 PreferenceScreen (androidx.preference.PreferenceScreen)22 Test (org.junit.Test)19 SwitchPreference (androidx.preference.SwitchPreference)13 NotificationChannel (android.app.NotificationChannel)11 ArrayList (java.util.ArrayList)11 NotificationChannelGroup (android.app.NotificationChannelGroup)9 ShortcutInfo (android.content.pm.ShortcutInfo)9 Context (android.content.Context)8 ConversationChannel (android.app.people.ConversationChannel)7 View (android.view.View)7 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)7 ListPreference (androidx.preference.ListPreference)6 ComponentName (android.content.ComponentName)5 ContentResolver (android.content.ContentResolver)5 Bundle (android.os.Bundle)5