use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class AccountPreferenceControllerTest method onResume_oneNewAccountType_shouldAddOneAccountPreference.
@Test
public void onResume_oneNewAccountType_shouldAddOneAccountPreference() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
infos.add(new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isLinkedUser()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
// First time resume will build the UI with no account
mController.onResume();
// Add new account
Account[] accounts = { new Account("Acct1", "com.acct1") };
when(mAccountManager.getAccountsAsUser(2)).thenReturn(accounts);
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accounts);
AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
// Resume should show the newly added account
mController.onResume();
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct1")));
}
use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class AccountPreferenceControllerTest method onResume_twoAccountsOfSameType_shouldAddThreePreferences.
@Test
public void onResume_twoAccountsOfSameType_shouldAddThreePreferences() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isLinkedUser()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
Account[] accounts = { new Account("Account1", "com.acct1") };
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
Account[] accountType1 = new Account[2];
accountType1[0] = new Account("Account11", "com.acct1");
accountType1[1] = new Account("Account12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
// should add 2 individual account and the Add account preference
verify(preferenceGroup, times(3)).addPreference(any(Preference.class));
}
use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class AccountTypePreferenceLoaderTest method updatePreferenceIntents_shouldRunRecursively.
@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class })
public void updatePreferenceIntents_shouldRunRecursively() {
final PreferenceManager preferenceManager = mock(PreferenceManager.class);
// Top level
PreferenceGroup prefRoot = spy(new PreferenceScreen(mContext, null));
when(prefRoot.getPreferenceManager()).thenReturn(preferenceManager);
Preference pref1 = mock(Preference.class);
PreferenceGroup prefGroup2 = spy(new PreferenceScreen(mContext, null));
when(prefGroup2.getPreferenceManager()).thenReturn(preferenceManager);
Preference pref3 = mock(Preference.class);
PreferenceGroup prefGroup4 = spy(new PreferenceScreen(mContext, null));
when(prefGroup4.getPreferenceManager()).thenReturn(preferenceManager);
prefRoot.addPreference(pref1);
prefRoot.addPreference(prefGroup2);
prefRoot.addPreference(pref3);
prefRoot.addPreference(prefGroup4);
// 2nd level
Preference pref21 = mock(Preference.class);
Preference pref22 = mock(Preference.class);
prefGroup2.addPreference(pref21);
prefGroup2.addPreference(pref22);
PreferenceGroup prefGroup41 = spy(new PreferenceScreen(mContext, null));
when(prefGroup41.getPreferenceManager()).thenReturn(preferenceManager);
Preference pref42 = mock(Preference.class);
prefGroup4.addPreference(prefGroup41);
prefGroup4.addPreference(pref42);
// 3rd level
Preference pref411 = mock(Preference.class);
Preference pref412 = mock(Preference.class);
prefGroup41.addPreference(pref411);
prefGroup41.addPreference(pref412);
final String acctType = "testType";
mPrefLoader.updatePreferenceIntents(prefRoot, acctType, mAccount);
verify(mPrefLoader).updatePreferenceIntents(prefGroup2, acctType, mAccount);
verify(mPrefLoader).updatePreferenceIntents(prefGroup4, acctType, mAccount);
verify(mPrefLoader).updatePreferenceIntents(prefGroup41, acctType, mAccount);
}
use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class SecuritySettingsTest method testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification.
@Test
public void testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification() {
final Preference preference = mock(Preference.class);
final PreferenceGroup group = mock(PreferenceGroup.class);
when(group.findPreference(SecuritySettings.KEY_LOCKSCREEN_PREFERENCES)).thenReturn(preference);
final LockScreenNotificationPreferenceController controller = mock(LockScreenNotificationPreferenceController.class);
final SecuritySettings securitySettings = new SecuritySettings();
ReflectionHelpers.setField(securitySettings, "mLockScreenNotificationPreferenceController", controller);
when(controller.getSummaryResource()).thenReturn(1234);
securitySettings.setLockscreenPreferencesSummary(group);
verify(preference).setSummary(1234);
}
use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class VpnSettings method setShownPreferences.
@VisibleForTesting
@UiThread
public void setShownPreferences(final Collection<Preference> updates) {
mLegacyVpnPreferences.values().retainAll(updates);
mAppPreferences.values().retainAll(updates);
// Change {@param updates} in-place to only contain new preferences that were not already
// added to the preference screen.
final PreferenceGroup vpnGroup = getPreferenceScreen();
for (int i = vpnGroup.getPreferenceCount() - 1; i >= 0; i--) {
Preference p = vpnGroup.getPreference(i);
if (updates.contains(p)) {
updates.remove(p);
} else {
vpnGroup.removePreference(p);
}
}
// Show any new preferences on the screen
for (Preference pref : updates) {
vpnGroup.addPreference(pref);
}
}
Aggregations