Search in sources :

Example 61 with Theme

use of android.content.res.Resources.Theme in project robolectric by robolectric.

the class ShadowThemeTest method forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild.

@Test
public void forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild() {
    Resources.Theme theme = resources.newTheme();
    theme.applyStyle(R.style.Theme_Robolectric_EmptyParent, true);
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).hasValue(0)).isFalse();
}
Also used : Resources(android.content.res.Resources) Theme(android.content.res.Resources.Theme) Test(org.junit.Test)

Example 62 with Theme

use of android.content.res.Resources.Theme in project robolectric by robolectric.

the class ShadowThemeTest method applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeValues.

@Test
public void applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeValues() {
    Resources.Theme theme = resources.newTheme();
    theme.applyStyle(R.style.StyleA, false);
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from style A");
    theme.applyStyle(R.style.StyleB, true);
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from style B");
}
Also used : Resources(android.content.res.Resources) Theme(android.content.res.Resources.Theme) Test(org.junit.Test)

Example 63 with Theme

use of android.content.res.Resources.Theme in project android_packages_apps_Settings by SudaMod.

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(android.support.v7.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 64 with Theme

use of android.content.res.Resources.Theme in project platform_packages_apps_Settings by BlissRoms.

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(android.support.v7.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 65 with Theme

use of android.content.res.Resources.Theme in project XposedInstaller by rovo89.

the class ThemeUtil method getThemeColor.

public static int getThemeColor(Context context, int id) {
    Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(new int[] { id });
    int result = a.getColor(0, 0);
    a.recycle();
    return result;
}
Also used : TypedArray(android.content.res.TypedArray) Theme(android.content.res.Resources.Theme)

Aggregations

Theme (android.content.res.Resources.Theme)67 Resources (android.content.res.Resources)28 Test (org.junit.Test)27 Context (android.content.Context)17 TypedValue (android.util.TypedValue)15 Configuration (android.content.res.Configuration)9 AuthenticatorDescription (android.accounts.AuthenticatorDescription)8 PackageManager (android.content.pm.PackageManager)8 LocalClassLoaderContextThemeWrapper (com.android.settings.utils.LocalClassLoaderContextThemeWrapper)8 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 Method (java.lang.reflect.Method)7 PreferenceScreen (android.support.v7.preference.PreferenceScreen)6 ComponentCallbacks2 (android.content.ComponentCallbacks2)5 NotFoundException (android.content.res.Resources.NotFoundException)5 XmlResourceParser (android.content.res.XmlResourceParser)5 INotificationManager (android.app.INotificationManager)4 TypedArray (android.content.res.TypedArray)4 RemoteException (android.os.RemoteException)4 IMountService (android.os.storage.IMountService)4 DisplayMetrics (android.util.DisplayMetrics)4