private StyleData createStyle(String styleName, AttributeResource... attributeResources) { return new StyleData("package", styleName, null, asList(attributeResources)); }
@Override public void onEnd(XMLStreamReader xml, XmlContext xmlContext) throws XMLStreamException { String styleParent = parent; if (styleParent == null) { int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { styleParent = name.substring(0, lastDot); } } StyleData styleData = new StyleData(xmlContext.getPackageName(), name, styleParent, attributeResources); resourceTable.addResource("style", styleData.getName(), new TypedResource<>(styleData, resType, xmlContext)); } }
@Test public void getAttrValue_willReturnTrimmedAttributeValues() throws Exception { StyleData styleData = new StyleData("library.resource", "Theme_MyApp", "Theme_Material", asList( new AttributeResource(myLibSearchViewStyle, "\n lib_value ", "library.resource") )); assertThat(styleData.getAttrValue(myAppSearchViewStyle).value).isEqualTo("\n lib_value "); assertThat(styleData.getAttrValue(myLibSearchViewStyle).trimmedValue).isEqualTo("lib_value"); }
@Test public void getAttrValue_willFindLibraryResourcesWithSameName() { StyleData styleData = new StyleData("library.resource", "Theme_MyApp", "Theme_Material", asList( new AttributeResource(myLibSearchViewStyle, "lib_value", "library.resource") )); assertThat(styleData.getAttrValue(myAppSearchViewStyle).value).isEqualTo("lib_value"); assertThat(styleData.getAttrValue(myLibSearchViewStyle).value).isEqualTo("lib_value"); assertThat(styleData.getAttrValue(androidSearchViewStyle)).isNull(); }
@Test public void getAttrValue_willNotFindFrameworkResourcesWithSameName() { StyleData styleData = new StyleData("android", "Theme_Material", "Theme", asList( new AttributeResource(androidSearchViewStyle, "android_value", "android") )); assertThat(styleData.getAttrValue(androidSearchViewStyle).value).isEqualTo("android_value"); assertThat(styleData.getAttrValue(myAppSearchViewStyle)).isNull(); assertThat(styleData.getAttrValue(myLibSearchViewStyle)).isNull(); }
@Test public void getAttrValue_willChooseBetweenAmbiguousAttributes() { StyleData styleData = new StyleData("android", "Theme_Material", "Theme", asList( new AttributeResource(myLibSearchViewStyle, "lib_value", "library.resource"), new AttributeResource(androidSearchViewStyle, "android_value", "android") )); assertThat(styleData.getAttrValue(androidSearchViewStyle).value).isEqualTo("android_value"); assertThat(styleData.getAttrValue(myLibSearchViewStyle).value).isEqualTo("lib_value"); // todo: any packageNames that aren't 'android' should be treated as equivalent // assertThat(styleData.getAttrValue(myAppSearchViewStyle).value).isEqualTo("lib_value"); }
@Override public void onEnd(XMLStreamReader xml, XmlContext xmlContext) throws XMLStreamException { String styleParent = parent; if (styleParent == null) { int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { styleParent = name.substring(0, lastDot); } } StyleData styleData = new StyleData(xmlContext.getPackageName(), name, styleParent, attributeResources); resourceTable.addResource("style", styleData.getName(), new TypedResource<>(styleData, resType, xmlContext)); } }
@Override public void onEnd(XMLStreamReader xml, XmlContext xmlContext) throws XMLStreamException { String styleParent = parent; if (styleParent == null) { int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { styleParent = name.substring(0, lastDot); } } String styleNameWithUnderscores = underscorize(name); StyleData styleData = new StyleData(xmlContext.getPackageName(), styleNameWithUnderscores, underscorize(styleParent), attributeResources); resourceTable.addResource("style", styleData.getName(), new TypedResource<>(styleData, resType, xmlContext)); }