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);
}
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);
}
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);
}
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();
}
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));
}
Aggregations