private StyleData getParent(StyleData style) { String parent = getParentStyleName(style); if (parent == null) return null; if (parent.startsWith("@")) parent = parent.substring(1); ResName styleRef = ResName.qualifyResName(parent, style.getPackageName(), "style"); styleRef = dereferenceResName(styleRef); // TODO: Refactor this to a ResourceLoaderChooser ResourceTable resourceProvider = "android".equals(styleRef.packageName) ? systemResourceTable : appResourceTable; TypedResource typedResource = resourceProvider.getValue(styleRef, config); if (typedResource == null) { StringBuilder builder = new StringBuilder("Could not find any resource") .append(" from reference ").append(styleRef) .append(" from ").append(style) .append(" with ").append(theme); throw new RuntimeException(builder.toString()); } Object data = typedResource.getData(); if (data instanceof StyleData) { return (StyleData) data; } else { StringBuilder builder = new StringBuilder(styleRef.toString()) .append(" does not resolve to a Style.") .append(" got ").append(data).append(" instead. ") .append(" from ").append(style) .append(" with ").append(theme); throw new RuntimeException(builder.toString()); } }
@Test public void testStyleDataIsLoadedCorrectly() throws Exception { TypedResource typedResource = resourceTable.getValue(new ResName("android", "style", "Theme_Holo"), new ResTable_config()); StyleData styleData = (StyleData) typedResource.getData(); assertThat(styleData.getName()).isEqualTo("Theme_Holo"); assertThat(styleData.getParent()).isEqualTo("Theme"); assertThat(styleData.getPackageName()).isEqualTo("android"); assertThat(styleData.getAttrValue(new ResName("android", "attr", "colorForeground")).value) .isEqualTo("@android:color/bright_foreground_holo_dark"); } }
private StyleData getParent(StyleData style) { String parent = getParentStyleName(style); if (parent == null || "Null".equals(parent)) return null; if (parent.startsWith("@")) parent = parent.substring(1); ResName styleRef = ResName.qualifyResName(parent, style.getPackageName(), "style"); styleRef = dereferenceResName(styleRef); // TODO: Refactor this to a ResourceLoaderChooser ResourceTable resourceProvider = "android".equals(styleRef.packageName) ? systemResourceTable : appResourceTable; TypedResource typedResource = resourceProvider.getValue(styleRef, qualifiers); if (typedResource == null) { StringBuilder builder = new StringBuilder("Could not find any resource") .append(" from reference ").append(styleRef) .append(" from ").append(style) .append(" with ").append(theme); throw new RuntimeException(builder.toString()); } Object data = typedResource.getData(); if (data instanceof StyleData) { return (StyleData) data; } else { StringBuilder builder = new StringBuilder(styleRef.toString()) .append(" does not resolve to a Style.") .append(" got ").append(data).append(" instead. ") .append(" from ").append(style) .append(" with ").append(theme); throw new RuntimeException(builder.toString()); } }
private StyleData getParent(StyleData style) { String parent = getParentStyleName(style); if (parent == null) return null; if (parent.startsWith("@")) parent = parent.substring(1); ResName styleRef = ResName.qualifyResName(parent, style.getPackageName(), "style"); styleRef = dereferenceResName(styleRef); // TODO: Refactor this to a ResourceLoaderChooser ResourceTable resourceProvider = "android".equals(styleRef.packageName) ? systemResourceTable : appResourceTable; TypedResource typedResource = resourceProvider.getValue(styleRef, config); if (typedResource == null) { StringBuilder builder = new StringBuilder("Could not find any resource") .append(" from reference ").append(styleRef) .append(" from ").append(style) .append(" with ").append(theme); throw new RuntimeException(builder.toString()); } Object data = typedResource.getData(); if (data instanceof StyleData) { return (StyleData) data; } else { StringBuilder builder = new StringBuilder(styleRef.toString()) .append(" does not resolve to a Style.") .append(" got ").append(data).append(" instead. ") .append(" from ").append(style) .append(" with ").append(theme); throw new RuntimeException(builder.toString()); } }