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;
}
}
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;
}
}
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);
}
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);
}
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");
}
Aggregations