Search in sources :

Example 46 with Theme

use of android.content.res.Resources.Theme in project AndroidDynamicLoader by mmin18.

the class MainActivity method setOverrideResources.

void setOverrideResources(MyResources myres) {
    if (myres == null) {
        this.myResources = null;
        this.resources = null;
        this.assetManager = null;
        this.theme = null;
    } else {
        this.myResources = myres;
        this.resources = myres.getResources();
        this.assetManager = myres.getAssets();
        Theme t = myres.getResources().newTheme();
        t.setTo(getTheme());
        this.theme = t;
    }
}
Also used : Theme(android.content.res.Resources.Theme)

Example 47 with Theme

use of android.content.res.Resources.Theme in project GreenDroid by cyrilmottier.

the class ActionBarDrawable method getColorFromTheme.

private static int getColorFromTheme(Context context, int attr, int defaultColor) {
    synchronized (sTypedValue) {
        final TypedValue value = sTypedValue;
        final Theme theme = context.getTheme();
        if (theme != null) {
            theme.resolveAttribute(attr, value, true);
            if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) {
                return value.data;
            }
        }
        return defaultColor;
    }
}
Also used : Theme(android.content.res.Resources.Theme) TypedValue(android.util.TypedValue)

Example 48 with Theme

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

the class ThemeTest method shouldApplyStylesFromResourceReference.

@Test
public void shouldApplyStylesFromResourceReference() throws Exception {
    Theme theme = resources.newTheme();
    theme.applyStyle(R.style.Theme_AnotherTheme, true);
    TypedArray a = theme.obtainStyledAttributes(null, R.styleable.CustomView, R.attr.animalStyle, 0);
    int animalStyleId = a.getResourceId(R.styleable.CustomView_animalStyle, 0);
    assertThat(animalStyleId).isEqualTo(R.style.Gastropod);
    assertThat(a.getFloat(R.styleable.CustomView_aspectRatio, 0.2f)).isEqualTo(1.69f);
}
Also used : Theme(android.content.res.Resources.Theme) Test(org.junit.Test)

Example 49 with Theme

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

the class ThemeTest method withResolveRefsFalse_shouldNotResolveResource.

@Test
public void withResolveRefsFalse_shouldNotResolveResource() throws Exception {
    Theme theme = resources.newTheme();
    theme.applyStyle(R.style.Theme_AnotherTheme, true);
    TypedValue value = new TypedValue();
    boolean resolved = theme.resolveAttribute(R.attr.logoHeight, value, false);
    assertThat(resolved).isTrue();
    assertThat(value.type).isEqualTo(TypedValue.TYPE_REFERENCE);
    assertThat(value.data).isEqualTo(R.dimen.test_dp_dimen);
}
Also used : Theme(android.content.res.Resources.Theme) TypedValue(android.util.TypedValue) Test(org.junit.Test)

Example 50 with Theme

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

the class ThemeTest method forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild.

@Test
@Ignore("todo: incorrect behavior on robolectric vs framework?")
public void forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild() throws Exception {
    Resources.Theme theme = resources.newTheme();
    theme.applyStyle(R.style.Theme_Robolectric_ImplicitChild, true);
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.Robolectric");
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string3 }).getString(0)).isEqualTo("string 3 from Theme.Robolectric.ImplicitChild");
}
Also used : Theme(android.content.res.Resources.Theme) Ignore(org.junit.Ignore) Test(org.junit.Test)

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