Search in sources :

Example 1 with LocalClassLoaderContextThemeWrapper

use of com.android.settings.utils.LocalClassLoaderContextThemeWrapper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountPreferenceBase 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 && Utils.showAccount(getActivity(), accountType)) {
                // 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 = getActivity().createPackageContextAsUser(desc.packageName, 0, mUserHandle);
                final Theme baseTheme = getResources().newTheme();
                baseTheme.applyStyle(com.android.settings.R.style.Theme_SettingsBase, true);
                final Context themedCtx = new LocalClassLoaderContextThemeWrapper(getClass(), targetCtx, 0);
                themedCtx.getTheme().setTo(baseTheme);
                prefs = 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(android.support.v7.preference.PreferenceScreen) PackageManager(android.content.pm.PackageManager) Theme(android.content.res.Resources.Theme) LocalClassLoaderContextThemeWrapper(com.android.settings.utils.LocalClassLoaderContextThemeWrapper) Resources(android.content.res.Resources)

Aggregations

AuthenticatorDescription (android.accounts.AuthenticatorDescription)1 Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 Theme (android.content.res.Resources.Theme)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 LocalClassLoaderContextThemeWrapper (com.android.settings.utils.LocalClassLoaderContextThemeWrapper)1