use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method withResolveRefsTrue_shouldResolveResource.
@Test
public void withResolveRefsTrue_shouldResolveResource() 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, true);
assertThat(resolved).isTrue();
assertThat(value.type).isEqualTo(TypedValue.TYPE_DIMENSION);
assertThat(value.resourceId).isEqualTo(R.dimen.test_dp_dimen);
assertThat(value.coerceToString()).isEqualTo("8.0dip");
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method whenAThemeHasExplicitlyEmptyParentAttr_shouldHaveNoParent.
@Test
public void whenAThemeHasExplicitlyEmptyParentAttr_shouldHaveNoParent() throws Exception {
Resources.Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_Robolectric_EmptyParent, true);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).hasValue(0)).isFalse();
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method shouldLookUpStylesFromStyleResId.
@Test
public void shouldLookUpStylesFromStyleResId() throws Exception {
Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_AnotherTheme, true);
TypedArray a = theme.obtainStyledAttributes(R.style.MyCustomView, R.styleable.CustomView);
boolean enabled = a.getBoolean(R.styleable.CustomView_aspectRatioEnabled, false);
assertThat(enabled).isTrue();
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeValues.
@Test
@Ignore("todo: incorrect behavior on robolectric vs framework?")
public void applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeValues() throws Exception {
Resources.Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_Robolectric, false);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.Robolectric");
theme.applyStyle(R.style.Theme_AnotherTheme, true);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.AnotherTheme");
// force apply the original theme; values should be overwritten
theme.applyStyle(R.style.Theme_Robolectric, true);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.Robolectric");
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method withResolveRefsFalse_shouldResolveValue.
@Test
public void withResolveRefsFalse_shouldResolveValue() throws Exception {
Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_AnotherTheme, true);
TypedValue value = new TypedValue();
boolean resolved = theme.resolveAttribute(R.attr.logoWidth, value, false);
assertThat(resolved).isTrue();
assertThat(value.type).isEqualTo(TypedValue.TYPE_REFERENCE);
assertThat(value.data).isEqualTo(R.dimen.test_dp_dimen);
}
Aggregations