Search in sources :

Example 36 with PreferenceGroup

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();
    }
}
Also used : PreferenceGroup(android.support.v7.preference.PreferenceGroup) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference)

Example 37 with PreferenceGroup

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);
    }
}
Also used : Context(android.content.Context) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) UsageStatsManager(android.app.usage.UsageStatsManager) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Intent(android.content.Intent)

Example 38 with PreferenceGroup

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);
        }
    }
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) PreferenceGroup(android.support.v7.preference.PreferenceGroup) RemoteException(android.os.RemoteException)

Example 39 with PreferenceGroup

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")));
}
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 40 with PreferenceGroup

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")));
}
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)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)140 Preference (android.support.v7.preference.Preference)114 Context (android.content.Context)67 Test (org.junit.Test)54 PreferenceManager (android.support.v7.preference.PreferenceManager)50 ArrayList (java.util.ArrayList)50 UserInfo (android.content.pm.UserInfo)48 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)42 Account (android.accounts.Account)36 AuthenticatorDescription (android.accounts.AuthenticatorDescription)36 UserHandle (android.os.UserHandle)36 Intent (android.content.Intent)27 SwitchPreference (android.support.v14.preference.SwitchPreference)21 PreferenceCategory (android.support.v7.preference.PreferenceCategory)20 PackageManager (android.content.pm.PackageManager)16 ResolveInfo (android.content.pm.ResolveInfo)16 TelephonyManager (android.telephony.TelephonyManager)16 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)15 Activity (android.app.Activity)14