use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class EnterpriseSetDefaultAppsListPreferenceController method createPreferences.
private void createPreferences(Context prefContext, PreferenceGroup group, EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>> apps) {
if (group == null) {
return;
}
for (EnterpriseDefaultApps typeOfDefault : EnterpriseDefaultApps.values()) {
final List<ApplicationInfo> appsForCategory = apps.get(typeOfDefault);
if (appsForCategory == null || appsForCategory.isEmpty()) {
continue;
}
final Preference preference = new Preference(prefContext);
preference.setTitle(getTitle(prefContext, typeOfDefault, appsForCategory.size()));
preference.setSummary(buildSummaryString(prefContext, appsForCategory));
preference.setOrder(typeOfDefault.ordinal());
preference.setSelectable(false);
group.addPreference(preference);
}
}
use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class PowerUsageAdvancedTest method testPrefs_shouldNotBeSelectable.
@Test
public void testPrefs_shouldNotBeSelectable() {
PreferenceManager pm = new PreferenceManager(mShadowContext);
when(mPowerUsageAdvanced.getPreferenceManager()).thenReturn(pm);
PreferenceGroup prefGroup = spy(new PreferenceCategory(mShadowContext));
when(prefGroup.getPreferenceManager()).thenReturn(pm);
mPowerUsageAdvanced.refreshPowerUsageDataList(mBatteryStatsHelper, prefGroup);
assertThat(prefGroup.getPreferenceCount()).isAtLeast(1);
for (int i = 0, count = prefGroup.getPreferenceCount(); i < count; i++) {
PowerGaugePreference pref = (PowerGaugePreference) prefGroup.getPreference(i);
assertThat(pref.isSelectable()).isFalse();
}
}
use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.
the class AccountPreferenceControllerTest method onResume_twoAccountsOfSameName_shouldAddFivePreferences.
@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class, ShadowAuthenticatorHelper.class })
public void onResume_twoAccountsOfSameName_shouldAddFivePreferences() {
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);
final Account[] accountType1 = new Account[2];
accountType1[0] = new Account("Account1", "com.acct1");
accountType1[1] = new Account("Account2", "com.acct1");
final Account[] accountType2 = new Account[2];
accountType2[0] = new Account("Account1", "com.acct2");
accountType2[1] = new Account("Account2", "com.acct2");
final Account[] allAccounts = new Account[4];
allAccounts[0] = accountType1[0];
allAccounts[1] = accountType1[1];
allAccounts[2] = accountType2[0];
allAccounts[3] = accountType2[1];
final AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false), new AuthenticatorDescription("com.acct2", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(allAccounts);
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct2"), any(UserHandle.class))).thenReturn(accountType2);
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 4 individual account and the Add account preference
verify(preferenceGroup, times(5)).addPreference(any(Preference.class));
}
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));
}
Aggregations