Search in sources :

Example 51 with PreferenceManager

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

the class KeyboardLayoutPickerControllerTest method test_createPreferenceHierarchy_shouldAddOnePreference.

@Test
public void test_createPreferenceHierarchy_shouldAddOnePreference() {
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
    mController.displayPreference(screen);
    // We create a keyboard layouts in initializeOneLayout()
    assertThat(screen.getPreferenceCount()).isEqualTo(1);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 52 with PreferenceManager

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

the class UserDictionaryListControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContentProvider = new FakeProvider();
    ShadowContentResolver.registerProviderInternal(UserDictionary.AUTHORITY, mContentProvider);
    mContext = RuntimeEnvironment.application;
    mController = spy(new UserDictionaryListPreferenceController(mContext, "controller_key"));
    mPreference = new Preference(mContext);
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = preferenceManager.createPreferenceScreen(mContext);
}
Also used : Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 53 with PreferenceManager

use of androidx.preference.PreferenceManager in project kdeconnect-android by KDE.

the class PluginSettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    if (this.plugin != null && this.plugin.supportsDeviceSpecificSettings()) {
        PreferenceManager prefsManager = getPreferenceManager();
        prefsManager.setSharedPreferencesName(this.plugin.getSharedPreferencesName());
        prefsManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
    }
    int resFile = getResources().getIdentifier(pluginKey.toLowerCase(Locale.ENGLISH) + "_preferences", "xml", requireContext().getPackageName());
    addPreferencesFromResource(resFile);
}
Also used : PreferenceManager(androidx.preference.PreferenceManager)

Example 54 with PreferenceManager

use of androidx.preference.PreferenceManager in project fdroidclient by f-droid.

the class PreferencesTest method setup.

/**
 * Manually read the {@code preferences.xml} defaults to a separate
 * instance. Clear the preference state before each test so that each
 * test starts as if it was a first time install.
 */
@Before
public void setup() {
    ShadowLog.stream = System.out;
    String sharedPreferencesName = CONTEXT.getPackageName() + "_preferences_defaults";
    PreferenceManager pm = new PreferenceManager(CONTEXT);
    pm.setSharedPreferencesName(sharedPreferencesName);
    pm.setSharedPreferencesMode(Context.MODE_PRIVATE);
    pm.inflateFromResource(CONTEXT, R.xml.preferences, null);
    defaults = pm.getSharedPreferences();
    assertTrue(defaults.getAll().size() > 0);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(CONTEXT);
    Log.d(TAG, "Clearing DefaultSharedPreferences containing: " + sharedPreferences.getAll().size());
    sharedPreferences.edit().clear().commit();
    assertEquals(0, sharedPreferences.getAll().size());
    SharedPreferences defaultValueSp = CONTEXT.getSharedPreferences(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, Context.MODE_PRIVATE);
    defaultValueSp.edit().remove(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES).commit();
}
Also used : SharedPreferences(android.content.SharedPreferences) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 55 with PreferenceManager

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

the class UnrestrictedDataAccessPreferenceControllerTest method onRebuildComplete_restricted_shouldBeDisabled.

@Test
public void onRebuildComplete_restricted_shouldBeDisabled() {
    mFragment = spy(new UnrestrictedDataAccess());
    doNothing().when(mFragment).setLoading(anyBoolean(), anyBoolean());
    mController.setParentFragment(mFragment);
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(mContext));
    doReturn(mPreferenceManager).when(mFragment).getPreferenceManager();
    doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
    doReturn(0).when(mPreferenceScreen).getPreferenceCount();
    final DataSaverBackend dataSaverBackend = mock(DataSaverBackend.class);
    ReflectionHelpers.setField(mController, "mDataSaverBackend", dataSaverBackend);
    ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
    final String testPkg1 = "com.example.one";
    final String testPkg2 = "com.example.two";
    ShadowRestrictedLockUtilsInternal.setRestrictedPkgs(testPkg2);
    doAnswer((invocation) -> {
        final UnrestrictedDataAccessPreference preference = invocation.getArgument(0);
        final AppEntry entry = preference.getEntry();
        // Verify preference is disabled by admin and the summary is changed accordingly.
        if (testPkg1.equals(entry.info.packageName)) {
            assertThat(preference.isDisabledByAdmin()).isFalse();
            assertThat(preference.getSummary()).isEqualTo("");
        } else if (testPkg2.equals(entry.info.packageName)) {
            assertThat(preference.isDisabledByAdmin()).isTrue();
            assertThat(preference.getSummary()).isEqualTo(mContext.getString(R.string.disabled_by_admin));
        }
        assertThat(preference.isChecked()).isFalse();
        preference.performClick();
        // if the preference is disabled by admin, otherwise the switch is toggled.
        if (testPkg1.equals(entry.info.packageName)) {
            assertThat(preference.isChecked()).isTrue();
            assertThat(ShadowRestrictedLockUtils.hasAdminSupportDetailsIntentLaunched()).isFalse();
        } else if (testPkg2.equals(entry.info.packageName)) {
            assertThat(preference.isChecked()).isFalse();
            assertThat(ShadowRestrictedLockUtils.hasAdminSupportDetailsIntentLaunched()).isTrue();
        }
        ShadowRestrictedLockUtils.clearAdminSupportDetailsIntentLaunch();
        return null;
    }).when(mPreferenceScreen).addPreference(any(UnrestrictedDataAccessPreference.class));
    mController.onRebuildComplete(createAppEntries(testPkg1, testPkg2));
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Aggregations

PreferenceManager (androidx.preference.PreferenceManager)87 Before (org.junit.Before)67 Preference (androidx.preference.Preference)23 PreferenceCategory (androidx.preference.PreferenceCategory)22 PreferenceScreen (androidx.preference.PreferenceScreen)19 Test (org.junit.Test)18 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)15 Context (android.content.Context)5 LifecycleRegistry (androidx.lifecycle.LifecycleRegistry)5 ArrayList (java.util.ArrayList)5 NotificationChannel (android.app.NotificationChannel)4 ShortcutInfo (android.content.pm.ShortcutInfo)4 View (android.view.View)4 NotificationChannelGroup (android.app.NotificationChannelGroup)3 ConversationChannel (android.app.people.ConversationChannel)3 PackageInfo (android.content.pm.PackageInfo)3 PersistableBundle (android.os.PersistableBundle)3 BluetoothManager (android.bluetooth.BluetoothManager)2 SoftApConfiguration (android.net.wifi.SoftApConfiguration)2 WifiManager (android.net.wifi.WifiManager)2