Search in sources :

Example 11 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.

the class LegalSettings method onCreate.

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.about_legal);
    final Activity act = getActivity();
    // These are contained in the "container" preference group
    PreferenceGroup parentPreference = getPreferenceScreen();
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
}
Also used : Activity(android.app.Activity) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 12 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.

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 13 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.

the class SettingsPreferenceFragment method cacheRemoveAllPrefs.

protected void cacheRemoveAllPrefs(PreferenceGroup group) {
    mPreferenceCache = new ArrayMap<String, Preference>();
    final int N = group.getPreferenceCount();
    for (int i = 0; i < N; i++) {
        Preference p = group.getPreference(i);
        if (TextUtils.isEmpty(p.getKey())) {
            continue;
        }
        mPreferenceCache.put(p.getKey(), p);
    }
}
Also used : CustomEditTextPreference(com.android.settingslib.CustomEditTextPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) CustomDialogPreference(com.android.settingslib.CustomDialogPreference) Preference(android.support.v7.preference.Preference)

Example 14 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.

the class SettingsPreferenceFragment method removePreference.

@VisibleForTesting
boolean removePreference(PreferenceGroup group, String key) {
    final int preferenceCount = group.getPreferenceCount();
    for (int i = 0; i < preferenceCount; i++) {
        final Preference preference = group.getPreference(i);
        final String curKey = preference.getKey();
        if (TextUtils.equals(curKey, key)) {
            return group.removePreference(preference);
        }
        if (preference instanceof PreferenceGroup) {
            if (removePreference((PreferenceGroup) preference, key)) {
                return true;
            }
        }
    }
    return false;
}
Also used : CustomEditTextPreference(com.android.settingslib.CustomEditTextPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) CustomDialogPreference(com.android.settingslib.CustomDialogPreference) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 15 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.

the class TrustAgentSettings method updateAgents.

private void updateAgents() {
    final Context context = getActivity();
    if (mAvailableAgents == null) {
        mAvailableAgents = findAvailableTrustAgents();
    }
    if (mLockPatternUtils == null) {
        mLockPatternUtils = new LockPatternUtils(getActivity());
    }
    loadActiveAgents();
    PreferenceGroup category = (PreferenceGroup) getPreferenceScreen().findPreference("trust_agents");
    category.removeAll();
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(context, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId());
    final int count = mAvailableAgents.size();
    for (int i = 0; i < count; i++) {
        AgentInfo agent = mAvailableAgents.valueAt(i);
        final RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
        preference.useAdminDisabledSummary(true);
        agent.preference = preference;
        preference.setPersistent(false);
        preference.setTitle(agent.label);
        preference.setIcon(agent.icon);
        preference.setPersistent(false);
        preference.setOnPreferenceChangeListener(this);
        preference.setChecked(mActiveAgents.contains(agent.component));
        if (admin != null && mDpm.getTrustAgentConfiguration(null, agent.component) == null) {
            preference.setChecked(false);
            preference.setDisabledByAdmin(admin);
        }
        category.addPreference(agent.preference);
    }
}
Also used : Context(android.content.Context) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) LockPatternUtils(com.android.internal.widget.LockPatternUtils) PreferenceGroup(android.support.v7.preference.PreferenceGroup) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

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