Search in sources :

Example 66 with PreferenceGroup

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")));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Example 67 with PreferenceGroup

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));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) Preference(android.support.v7.preference.Preference) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Example 68 with PreferenceGroup

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);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test) Config(org.robolectric.annotation.Config) TestConfig(com.android.settings.TestConfig)

Example 69 with PreferenceGroup

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);
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) LockScreenNotificationPreferenceController(com.android.settings.notification.LockScreenNotificationPreferenceController) Test(org.junit.Test)

Example 70 with PreferenceGroup

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);
    }
}
Also used : GearPreference(com.android.settings.widget.GearPreference) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) UiThread(android.annotation.UiThread)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)104 Preference (android.support.v7.preference.Preference)70 Context (android.content.Context)28 PreferenceScreen (android.support.v7.preference.PreferenceScreen)28 Test (org.junit.Test)26 PreferenceManager (android.support.v7.preference.PreferenceManager)22 SwitchPreference (android.support.v14.preference.SwitchPreference)19 ArrayList (java.util.ArrayList)19 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 UserInfo (android.content.pm.UserInfo)16 Intent (android.content.Intent)14 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)14 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)14 Account (android.accounts.Account)12 AuthenticatorDescription (android.accounts.AuthenticatorDescription)12 UserHandle (android.os.UserHandle)12 TelephonyManager (android.telephony.TelephonyManager)12 Activity (android.app.Activity)11 RestrictedPreference (com.android.settingslib.RestrictedPreference)11 RemoteException (android.os.RemoteException)8