Search in sources :

Example 26 with PreferenceScreen

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

the class AccountTypePreferenceLoader method addPreferencesForType.

/**
 * Gets the preferences.xml file associated with a particular account type.
 * @param accountType the type of account
 * @return a PreferenceScreen inflated from accountPreferenceId.
 */
public PreferenceScreen addPreferencesForType(final String accountType, PreferenceScreen parent) {
    PreferenceScreen prefs = null;
    if (mAuthenticatorHelper.containsAccountType(accountType)) {
        AuthenticatorDescription desc = null;
        try {
            desc = mAuthenticatorHelper.getAccountTypeDescription(accountType);
            if (desc != null && desc.accountPreferencesId != 0) {
                // Load the context of the target package, then apply the
                // base Settings theme (no references to local resources)
                // and create a context theme wrapper so that we get the
                // correct text colors. Control colors will still be wrong,
                // but there's not much we can do about it since we can't
                // reference local color resources.
                final Context targetCtx = mFragment.getActivity().createPackageContextAsUser(desc.packageName, 0, mUserHandle);
                final Theme baseTheme = mFragment.getResources().newTheme();
                baseTheme.applyStyle(R.style.Theme_SettingsBase, true);
                final Context themedCtx = new LocalClassLoaderContextThemeWrapper(getClass(), targetCtx, 0);
                themedCtx.getTheme().setTo(baseTheme);
                prefs = mFragment.getPreferenceManager().inflateFromResource(themedCtx, desc.accountPreferencesId, parent);
            }
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "Couldn't load preferences.xml file from " + desc.packageName);
        } catch (Resources.NotFoundException e) {
            Log.w(TAG, "Couldn't load preferences.xml file from " + desc.packageName);
        }
    }
    return prefs;
}
Also used : Context(android.content.Context) AuthenticatorDescription(android.accounts.AuthenticatorDescription) PreferenceScreen(androidx.preference.PreferenceScreen) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) Theme(android.content.res.Resources.Theme) LocalClassLoaderContextThemeWrapper(com.android.settings.utils.LocalClassLoaderContextThemeWrapper) Resources(android.content.res.Resources)

Example 27 with PreferenceScreen

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

the class ToggleFeaturePreferenceFragment method updatePreferenceOrder.

private void updatePreferenceOrder() {
    final List<String> lists = getPreferenceOrderList();
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.setOrderingAsAdded(false);
    final int size = lists.size();
    for (int i = 0; i < size; i++) {
        final Preference preference = preferenceScreen.findPreference(lists.get(i));
        if (preference != null) {
            preference.setOrder(i);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference) IllustrationPreference(com.android.settingslib.widget.IllustrationPreference) Preference(androidx.preference.Preference)

Example 28 with PreferenceScreen

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

the class ToggleFeaturePreferenceFragment method initHtmlTextPreference.

private void initHtmlTextPreference() {
    if (TextUtils.isEmpty(mHtmlDescription)) {
        return;
    }
    final PreferenceScreen screen = getPreferenceScreen();
    final CharSequence htmlDescription = Html.fromHtml(mHtmlDescription.toString(), Html.FROM_HTML_MODE_COMPACT, mImageGetter, /* tagHandler= */
    null);
    final String iconContentDescription = getString(R.string.accessibility_introduction_title, mPackageName);
    final AccessibilityFooterPreference htmlFooterPreference = new AccessibilityFooterPreference(screen.getContext());
    htmlFooterPreference.setKey(KEY_HTML_DESCRIPTION_PREFERENCE);
    htmlFooterPreference.setSummary(htmlDescription);
    htmlFooterPreference.setContentDescription(generateFooterContentDescription(htmlDescription));
    // Only framework tools support help link
    if (getHelpResource() != 0) {
        htmlFooterPreference.setLearnMoreAction(view -> {
            final Intent helpIntent = HelpUtils.getHelpIntent(getContext(), getContext().getString(getHelpResource()), getContext().getClass().getName());
            view.startActivityForResult(helpIntent, 0);
        });
        final String learnMoreContentDescription = getPrefContext().getString(R.string.footer_learn_more_content_description, mPackageName);
        htmlFooterPreference.setLearnMoreContentDescription(learnMoreContentDescription);
        htmlFooterPreference.setLinkEnabled(true);
    } else {
        htmlFooterPreference.setLinkEnabled(false);
    }
    screen.addPreference(htmlFooterPreference);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Intent(android.content.Intent)

Example 29 with PreferenceScreen

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

the class DashboardFragment method displayResourceTiles.

/**
 * Displays resource based tiles.
 */
private void displayResourceTiles() {
    final int resId = getPreferenceScreenResId();
    if (resId <= 0) {
        return;
    }
    addPreferencesFromResource(resId);
    final PreferenceScreen screen = getPreferenceScreen();
    screen.setOnExpandButtonClickListener(this);
    displayResourceTilesToScreen(screen);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Example 30 with PreferenceScreen

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

the class DashboardFragment method updatePreferenceStates.

/**
 * Update state of each preference managed by PreferenceController.
 */
protected void updatePreferenceStates() {
    final PreferenceScreen screen = getPreferenceScreen();
    Collection<List<AbstractPreferenceController>> controllerLists = mPreferenceControllers.values();
    for (List<AbstractPreferenceController> controllerList : controllerLists) {
        for (AbstractPreferenceController controller : controllerList) {
            if (!controller.isAvailable()) {
                continue;
            }
            final String key = controller.getPreferenceKey();
            if (TextUtils.isEmpty(key)) {
                Log.d(TAG, String.format("Preference key is %s in Controller %s", key, controller.getClass().getSimpleName()));
                continue;
            }
            final Preference preference = screen.findPreference(key);
            if (preference == null) {
                Log.d(TAG, String.format("Cannot find preference with key %s in Controller %s", key, controller.getClass().getSimpleName()));
                continue;
            }
            controller.updateState(preference);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) PrimarySwitchPreference(com.android.settings.widget.PrimarySwitchPreference) ArrayList(java.util.ArrayList) List(java.util.List)

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