Search in sources :

Example 21 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class HighlightablePreferenceGroupAdapter method adjustInitialExpandedChildCount.

/**
 * Tries to override initial expanded child count.
 * <p/>
 * Initial expanded child count will be ignored if:
 * 1. fragment contains request to highlight a particular row.
 * 2. count value is invalid.
 */
public static void adjustInitialExpandedChildCount(SettingsPreferenceFragment host) {
    if (host == null) {
        return;
    }
    final PreferenceScreen screen = host.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    final Bundle arguments = host.getArguments();
    if (arguments != null) {
        final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
        if (!TextUtils.isEmpty(highlightKey)) {
            // Has highlight row - expand everything
            screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
            return;
        }
    }
    final int initialCount = host.getInitialExpandedChildCount();
    if (initialCount <= 0) {
        return;
    }
    screen.setInitialExpandedChildrenCount(initialCount);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle)

Example 22 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class RadioButtonPickerFragment method updateCandidates.

public void updateCandidates() {
    mCandidates.clear();
    final List<? extends CandidateInfo> candidateList = getCandidates();
    if (candidateList != null) {
        for (CandidateInfo info : candidateList) {
            mCandidates.put(info.getKey(), info);
        }
    }
    final String defaultKey = getDefaultKey();
    final String systemDefaultKey = getSystemDefaultKey();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    if (mIllustrationId != 0) {
        addIllustration(screen);
    }
    if (!mAppendStaticPreferences) {
        addStaticPreferences(screen);
    }
    final int customLayoutResId = getRadioButtonPreferenceCustomLayoutResId();
    if (shouldShowItemNone()) {
        final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
        if (customLayoutResId > 0) {
            nonePref.setLayoutResource(customLayoutResId);
        }
        nonePref.setIcon(R.drawable.ic_remove_circle);
        nonePref.setTitle(R.string.app_list_preference_none);
        nonePref.setChecked(TextUtils.isEmpty(defaultKey));
        nonePref.setOnClickListener(this);
        screen.addPreference(nonePref);
    }
    if (candidateList != null) {
        for (CandidateInfo info : candidateList) {
            RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
            if (customLayoutResId > 0) {
                pref.setLayoutResource(customLayoutResId);
            }
            bindPreference(pref, info.getKey(), info, defaultKey);
            bindPreferenceExtra(pref, info.getKey(), info, defaultKey, systemDefaultKey);
            screen.addPreference(pref);
        }
    }
    mayCheckOnlyRadioButton();
    if (mAppendStaticPreferences) {
        addStaticPreferences(screen);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) CandidateInfo(com.android.settingslib.widget.CandidateInfo) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 23 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class TestingSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.testing_settings);
    final UserManager um = UserManager.get(getContext());
    if (!um.isAdminUser()) {
        PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("radio_info_settings");
        getPreferenceScreen().removePreference(preferenceScreen);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) UserManager(android.os.UserManager)

Example 24 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class AccountPreferenceController method updateProfileUi.

private void updateProfileUi(final UserInfo userInfo) {
    if (mFragment.getPreferenceManager() == null) {
        return;
    }
    final ProfileData data = mProfiles.get(userInfo.id);
    if (data != null) {
        data.pendingRemoval = false;
        data.userInfo = userInfo;
        if (userInfo.isEnabled()) {
            // recreate the authentication helper to refresh the list of enabled accounts
            data.authenticatorHelper = new AuthenticatorHelper(mContext, userInfo.getUserHandle(), this);
        }
        return;
    }
    final Context context = mContext;
    final ProfileData profileData = new ProfileData();
    profileData.userInfo = userInfo;
    AccessiblePreferenceCategory preferenceGroup = mHelper.createAccessiblePreferenceCategory(mFragment.getPreferenceManager().getContext());
    preferenceGroup.setOrder(mAccountProfileOrder++);
    // default title; may be modified below
    preferenceGroup.setTitle(R.string.account_settings);
    if (isSingleProfile()) {
        final String title = context.getString(R.string.account_for_section_header, BidiFormatter.getInstance().unicodeWrap(userInfo.name));
        preferenceGroup.setTitle(title);
        preferenceGroup.setContentDescription(title);
    } else if (userInfo.isManagedProfile()) {
        if (mType == ProfileSelectFragment.ProfileType.ALL) {
            preferenceGroup.setTitle(R.string.category_work);
            final String workGroupSummary = getWorkGroupSummary(context, userInfo);
            preferenceGroup.setSummary(workGroupSummary);
            preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_work, workGroupSummary));
        }
        profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference();
        mHelper.enforceRestrictionOnPreference(profileData.removeWorkProfilePreference, DISALLOW_REMOVE_MANAGED_PROFILE, UserHandle.myUserId());
        profileData.managedProfilePreference = newManagedProfileSettings();
    } else {
        if (mType == ProfileSelectFragment.ProfileType.ALL) {
            preferenceGroup.setTitle(R.string.category_personal);
            preferenceGroup.setContentDescription(mContext.getString(R.string.accessibility_category_personal));
        }
    }
    final PreferenceScreen screen = mFragment.getPreferenceScreen();
    if (screen != null) {
        screen.addPreference(preferenceGroup);
    }
    profileData.preferenceGroup = preferenceGroup;
    if (userInfo.isEnabled()) {
        profileData.authenticatorHelper = new AuthenticatorHelper(context, userInfo.getUserHandle(), this);
        profileData.addAccountPreference = newAddAccountPreference();
        mHelper.enforceRestrictionOnPreference(profileData.addAccountPreference, DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
    }
    mProfiles.put(userInfo.id, profileData);
}
Also used : Context(android.content.Context) AuthenticatorHelper(com.android.settingslib.accounts.AuthenticatorHelper) PreferenceScreen(androidx.preference.PreferenceScreen) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory)

Example 25 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class AccountPreferenceController method cleanUpPreferences.

void cleanUpPreferences() {
    PreferenceScreen screen = mFragment.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    final int count = mProfiles.size();
    for (int i = count - 1; i >= 0; i--) {
        final ProfileData data = mProfiles.valueAt(i);
        if (data.pendingRemoval) {
            screen.removePreference(data.preferenceGroup);
            mProfiles.removeAt(i);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8