Search in sources :

Example 56 with Theme

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

the class ThemeTest method shouldApplyParentStylesFromAttrs.

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

Example 57 with Theme

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

the class ThemeTest method applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues.

@Test
@Ignore("todo: incorrect behavior on robolectric vs framework?")
public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues() 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, false);
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.Robolectric");
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string2 }).getString(0)).isEqualTo("string 2 from Theme.AnotherTheme");
}
Also used : Theme(android.content.res.Resources.Theme) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 58 with Theme

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

the class ShadowThemeTest method applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues.

@Test
public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues() {
    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, false);
    assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from style A");
}
Also used : Resources(android.content.res.Resources) Theme(android.content.res.Resources.Theme) Test(org.junit.Test)

Example 59 with Theme

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

the class ShadowThemeTest method whenStyleSpecifiesAttr_obtainStyledAttribute_findsCorrectValue.

@Test
public void whenStyleSpecifiesAttr_obtainStyledAttribute_findsCorrectValue() {
    Resources.Theme theme = resources.newTheme();
    theme.applyStyle(R.style.Theme_Robolectric, false);
    theme.applyStyle(R.style.Theme_ThemeContainingStyleReferences, true);
    assertThat(theme.obtainStyledAttributes(Robolectric.buildAttributeSet().setStyleAttribute("?attr/styleReference").build(), new int[] { R.attr.string2 }, 0, 0).getString(0)).isEqualTo("string 2 from YetAnotherStyle");
    assertThat(theme.obtainStyledAttributes(Robolectric.buildAttributeSet().setStyleAttribute("?styleReference").build(), new int[] { R.attr.string2 }, 0, 0).getString(0)).isEqualTo("string 2 from YetAnotherStyle");
}
Also used : Resources(android.content.res.Resources) Theme(android.content.res.Resources.Theme) Test(org.junit.Test)

Example 60 with Theme

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

the class ShadowThemeTest method obtainStyledAttributes_shouldFindAttributeInDefaultStyle.

@Test
public void obtainStyledAttributes_shouldFindAttributeInDefaultStyle() {
    Theme theme = resources.newTheme();
    TypedArray typedArray = theme.obtainStyledAttributes(R.style.StyleA, new int[] { R.attr.string1 });
    assertThat(typedArray.getString(0)).isEqualTo("string 1 from style A");
}
Also used : TypedArray(android.content.res.TypedArray) Theme(android.content.res.Resources.Theme) 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