use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.
the class SecondaryUserController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
if (mStoragePreference == null) {
mStoragePreference = new StorageItemPreference(screen.getContext());
PreferenceGroup group = (PreferenceGroup) screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
mStoragePreference.setTitle(mUser.name);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
if (mSize != SIZE_NOT_SET) {
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
}
group.setVisible(true);
group.addPreference(mStoragePreference);
maybeSetIcon();
}
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.
the class InactiveApps method init.
private void init() {
PreferenceGroup screen = getPreferenceScreen();
screen.removeAll();
screen.setOrderingAsAdded(false);
final Context context = getActivity();
final PackageManager pm = context.getPackageManager();
final UsageStatsManager usm = context.getSystemService(UsageStatsManager.class);
Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps = pm.queryIntentActivities(launcherIntent, 0);
for (ResolveInfo app : apps) {
String packageName = app.activityInfo.applicationInfo.packageName;
Preference p = new Preference(getPrefContext());
p.setTitle(app.loadLabel(pm));
p.setIcon(app.loadIcon(pm));
p.setKey(packageName);
updateSummary(p);
p.setOnPreferenceClickListener(this);
screen.addPreference(p);
}
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.
the class UserSettings method updateUserList.
private void updateUserList() {
if (getActivity() == null)
return;
List<UserInfo> users = mUserManager.getUsers(true);
final Context context = getActivity();
final boolean voiceCapable = Utils.isVoiceCapable(context);
final ArrayList<Integer> missingIcons = new ArrayList<>();
final ArrayList<UserPreference> userPreferences = new ArrayList<>();
int guestId = UserPreference.USERID_GUEST_DEFAULTS;
userPreferences.add(mMePreference);
for (UserInfo user : users) {
if (!user.supportsSwitchToByUser()) {
// e.g. Managed profiles appear under Accounts Settings instead
continue;
}
UserPreference pref;
if (user.id == UserHandle.myUserId()) {
pref = mMePreference;
} else if (user.isGuest()) {
// Skip over Guest. We add generic Guest settings after this loop
guestId = user.id;
continue;
} else {
// With Telephony:
// Secondary user: Settings
// Guest: Settings
// Restricted Profile: There is no Restricted Profile
// Without Telephony:
// Secondary user: Delete
// Guest: Nothing
// Restricted Profile: Settings
final boolean showSettings = mUserCaps.mIsAdmin && (voiceCapable || user.isRestricted());
final boolean showDelete = mUserCaps.mIsAdmin && (!voiceCapable && !user.isRestricted() && !user.isGuest());
pref = new UserPreference(getPrefContext(), null, user.id, showSettings ? this : null, showDelete ? this : null);
pref.setKey("id=" + user.id);
userPreferences.add(pref);
if (user.isAdmin()) {
pref.setSummary(R.string.user_admin);
}
pref.setTitle(user.name);
pref.setSelectable(false);
}
if (pref == null) {
continue;
}
if (!isInitialized(user)) {
if (user.isRestricted()) {
pref.setSummary(R.string.user_summary_restricted_not_set_up);
} else {
pref.setSummary(R.string.user_summary_not_set_up);
}
pref.setOnPreferenceClickListener(this);
pref.setSelectable(true);
} else if (user.isRestricted()) {
pref.setSummary(R.string.user_summary_restricted_profile);
}
if (user.iconPath != null) {
if (mUserIcons.get(user.id) == null) {
// Icon not loaded yet, print a placeholder
missingIcons.add(user.id);
pref.setIcon(getEncircledDefaultIcon());
} else {
setPhotoId(pref, user);
}
} else {
// Icon not available yet, print a placeholder
pref.setIcon(getEncircledDefaultIcon());
}
}
// Add a temporary entry for the user being created
if (mAddingUser) {
UserPreference pref = new UserPreference(getPrefContext(), null, UserPreference.USERID_UNKNOWN, null, null);
pref.setEnabled(false);
pref.setTitle(mAddingUserName);
pref.setIcon(getEncircledDefaultIcon());
userPreferences.add(pref);
}
// Check if Guest tile should be added.
if (!mUserCaps.mIsGuest && (mUserCaps.mCanAddGuest || mUserCaps.mDisallowAddUserSetByAdmin)) {
// Add a virtual Guest user for guest defaults
UserPreference pref = new UserPreference(getPrefContext(), null, UserPreference.USERID_GUEST_DEFAULTS, mUserCaps.mIsAdmin && voiceCapable ? this : null, /* settings icon handler */
null);
pref.setTitle(R.string.user_guest);
pref.setIcon(getEncircledDefaultIcon());
userPreferences.add(pref);
pref.setDisabledByAdmin(mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
int finalGuestId = guestId;
pref.setOnPreferenceClickListener(preference -> {
int id = finalGuestId;
if (id == UserPreference.USERID_GUEST_DEFAULTS) {
UserInfo guest = mUserManager.createGuest(getContext(), preference.getTitle().toString());
if (guest != null) {
id = guest.id;
}
}
try {
ActivityManager.getService().switchUser(id);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
return true;
});
}
// Sort list of users by serialNum
Collections.sort(userPreferences, UserPreference.SERIAL_NUMBER_COMPARATOR);
getActivity().invalidateOptionsMenu();
// Load the icons
if (missingIcons.size() > 0) {
loadIconsAsync(missingIcons);
}
PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
// If profiles are supported, userPreferences will be added to the category labeled
// "User & Profiles", otherwise the category is skipped and elements are added directly
// to preferenceScreen
PreferenceGroup groupToAddUsers;
if (mUserCaps.mCanAddRestrictedProfile) {
mUserListCategory.removeAll();
mUserListCategory.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mUserListCategory);
groupToAddUsers = mUserListCategory;
} else {
groupToAddUsers = preferenceScreen;
}
for (UserPreference userPreference : userPreferences) {
userPreference.setOrder(Preference.DEFAULT_ORDER);
groupToAddUsers.addPreference(userPreference);
}
// Append Add user to the end of the list
if ((mUserCaps.mCanAddUser || mUserCaps.mDisallowAddUserSetByAdmin) && Utils.isDeviceProvisioned(getActivity())) {
boolean moreUsers = mUserManager.canAddMoreUsers();
mAddUser.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mAddUser);
mAddUser.setEnabled(moreUsers && !mAddingUser);
if (!moreUsers) {
mAddUser.setSummary(getString(R.string.user_add_max_count, getMaxRealUsers()));
} else {
mAddUser.setSummary(null);
}
if (mAddUser.isEnabled()) {
mAddUser.setDisabledByAdmin(mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
}
}
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.
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 android_packages_apps_Settings by omnirom.
the class AccountPreferenceControllerTest method onResume_noAccountChange_shouldNotAddAccountPreference.
@Test
public void onResume_noAccountChange_shouldNotAddAccountPreference() {
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("Acct1", "com.acct1") };
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
Account[] accountType1 = new Account[2];
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "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();
mController.onResume();
// each account should be added only once
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct11")));
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct12")));
}
Aggregations