Search in sources :

Example 56 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageItemPreferenceControllerTest method displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage.

@Test
public void displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage() {
    final StorageItemPreference audio = new StorageItemPreference(mContext);
    final StorageItemPreference image = new StorageItemPreference(mContext);
    final StorageItemPreference games = new StorageItemPreference(mContext);
    final StorageItemPreference apps = new StorageItemPreference(mContext);
    final StorageItemPreference system = new StorageItemPreference(mContext);
    final StorageItemPreference files = new StorageItemPreference(mContext);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(null);
    mController.displayPreference(screen);
    verify(screen).removePreference(files);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) VolumeInfo(android.os.storage.VolumeInfo) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference) Test(org.junit.Test)

Example 57 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageItemPreferenceControllerTest method displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable.

@Test
public void displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable() {
    final StorageItemPreference audio = new StorageItemPreference(mContext);
    final StorageItemPreference image = new StorageItemPreference(mContext);
    final StorageItemPreference games = new StorageItemPreference(mContext);
    final StorageItemPreference apps = new StorageItemPreference(mContext);
    final StorageItemPreference system = new StorageItemPreference(mContext);
    final StorageItemPreference files = new StorageItemPreference(mContext);
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
    when(mVolume.isMountedReadable()).thenReturn(false);
    mController.displayPreference(screen);
    verify(screen).removePreference(files);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) VolumeInfo(android.os.storage.VolumeInfo) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference) Test(org.junit.Test)

Example 58 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ColorModePreferenceFragmentTest method addStaticPreferences_shouldAddPreviewImage.

@Test
public void addStaticPreferences_shouldAddPreviewImage() {
    PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
    LayoutPreference mockPreview = mock(LayoutPreference.class);
    ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
    mFragment.configureAndInstallPreview(mockPreview, mockPreferenceScreen);
    verify(mockPreview, times(1)).setSelectable(false);
    verify(mockPreferenceScreen, times(1)).addPreference(preferenceCaptor.capture());
    assertThat(preferenceCaptor.getValue()).isEqualTo(mockPreview);
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference) PreferenceScreen(androidx.preference.PreferenceScreen) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 59 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class HighlightablePreferenceGroupAdapter method adjustInitialExpandedChildCount.

/**
 * Tries to override initial expanded child count.
 * <p/>
 * Initial expanded child count will be ignored if:
 * 1. fragment contains request to highlight a particular row.
 * 2. count value is invalid.
 */
public static void adjustInitialExpandedChildCount(SettingsPreferenceFragment host) {
    if (host == null) {
        return;
    }
    final PreferenceScreen screen = host.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    final Bundle arguments = host.getArguments();
    if (arguments != null) {
        final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
        if (!TextUtils.isEmpty(highlightKey)) {
            // Has highlight row - expand everything
            screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
            return;
        }
    }
    final int initialCount = host.getInitialExpandedChildCount();
    if (initialCount <= 0) {
        return;
    }
    screen.setInitialExpandedChildrenCount(initialCount);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle)

Example 60 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8