private Style resolveStyle(@Nonnull ResName themeStyleName, Style themeStyleSet) { TypedResource themeStyleResource = resourceTable.getValue(themeStyleName, config); if (themeStyleResource == null) return null; StyleData themeStyleData = (StyleData) themeStyleResource.getData(); if (themeStyleSet == null) { themeStyleSet = new ThemeStyleSet(); } return new StyleResolver(resourceTable, legacyShadowOf(AssetManager.getSystem()).getResourceTable(), themeStyleData, themeStyleSet, themeStyleName, config); }
private ResName dereferenceResName(ResName res) { ResName styleRef = res; boolean dereferencing = true; while ("attr".equals(styleRef.type) && dereferencing) { dereferencing = false; for (StyleData parentStyle : styles) { AttributeResource value = parentStyle.getAttrValue(styleRef); if (value != null) { styleRef = dereferenceAttr(value); dereferencing = true; break; } } if (!dereferencing && theme != null) { AttributeResource value = theme.getAttrValue(styleRef); if (value != null) { styleRef = dereferenceAttr(value); dereferencing = true; } } } return styleRef; }
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()); } }
@Override public AttributeResource getAttrValue(ResName resName) { for (StyleData style : styles) { AttributeResource value = style.getAttrValue(resName); if (value != null) return value; } int initialSize = styles.size(); while (hasParent(styles.get(styles.size() - 1))) { StyleData parent = getParent(styles.get(styles.size() - 1)); if (parent != null) { styles.add(parent); } else { break; } } for (int i = initialSize; i < styles.size(); i++) { StyleData style = styles.get(i); AttributeResource value = style.getAttrValue(resName); if (value != null) return value; } // todo: is this tested? if (theme != null) { AttributeResource value = theme.getAttrValue(resName); if (value != null) return value; } return null; }
@Override public AttributeResource getAttrValue(ResName resName) { for (StyleData style : styles) { AttributeResource value = style.getAttrValue(resName); if (value != null) return value; } int initialSize = styles.size(); while (hasParent(styles.get(styles.size() - 1))) { StyleData parent = getParent(styles.get(styles.size() - 1)); if (parent != null) { styles.add(parent); } else { break; } } for (int i = initialSize; i < styles.size(); i++) { StyleData style = styles.get(i); AttributeResource value = style.getAttrValue(resName); if (value != null) return value; } // todo: is this tested? if (theme != null) { AttributeResource value = theme.getAttrValue(resName); if (value != null) return value; } return null; }
Style resolveStyle(@NotNull ResName themeStyleName, Style themeStyleSet) { TypedResource themeStyleResource = resourceLoader.getValue(themeStyleName, RuntimeEnvironment.getQualifiers()); if (themeStyleResource == null) return null; StyleData themeStyleData = (StyleData) themeStyleResource.getData(); if (themeStyleSet == null) { themeStyleSet = new ThemeStyleSet(); } return new StyleResolver(resourceLoader, themeStyleData, themeStyleSet, themeStyleName, RuntimeEnvironment.getQualifiers()); }
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()); } }
@Override public AttributeResource getAttrValue(ResName resName) { for (StyleData style : styles) { AttributeResource value = style.getAttrValue(resName); if (value != null) return value; } int initialSize = styles.size(); while (hasParent(styles.get(styles.size() - 1))) { StyleData parent = getParent(styles.get(styles.size() - 1)); if (parent != null) { styles.add(parent); } else { break; } } for (int i = initialSize; i < styles.size(); i++) { StyleData style = styles.get(i); AttributeResource value = style.getAttrValue(resName); if (value != null) return value; } // todo: is this tested? if (theme != null) { AttributeResource value = theme.getAttrValue(resName); if (value != null) return value; } return null; }
private ResName dereferenceResName(ResName res) { ResName styleRef = res; boolean dereferencing = true; while ("attr".equals(styleRef.type) && dereferencing) { dereferencing = false; for (StyleData parentStyle : styles) { AttributeResource value = parentStyle.getAttrValue(styleRef); if (value != null) { styleRef = dereferenceAttr(value); dereferencing = true; break; } } if (!dereferencing && theme != null) { AttributeResource value = theme.getAttrValue(styleRef); if (value != null) { styleRef = dereferenceAttr(value); dereferencing = true; } } } return styleRef; }
private Style resolveStyle(@Nonnull ResName themeStyleName, Style themeStyleSet) { TypedResource themeStyleResource = resourceTable.getValue(themeStyleName, config); if (themeStyleResource == null) return null; StyleData themeStyleData = (StyleData) themeStyleResource.getData(); if (themeStyleSet == null) { themeStyleSet = new ThemeStyleSet(); } return new StyleResolver(resourceTable, legacyShadowOf(AssetManager.getSystem()).getResourceTable(), themeStyleData, themeStyleSet, themeStyleName, config); }
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()); } }
private ResName dereferenceResName(ResName res) { ResName styleRef = res; boolean dereferencing = true; while ("attr".equals(styleRef.type) && dereferencing) { dereferencing = false; for (StyleData parentStyle : styles) { AttributeResource value = parentStyle.getAttrValue(styleRef); if (value != null) { styleRef = dereferenceAttr(value); dereferencing = true; break; } } if (!dereferencing && theme != null) { AttributeResource value = theme.getAttrValue(styleRef); if (value != null) { styleRef = dereferenceAttr(value); dereferencing = true; } } } return styleRef; }
private Style resolveStyle(@NotNull ResName themeStyleName, Style themeStyleSet) { TypedResource themeStyleResource = resourceTable.getValue(themeStyleName, RuntimeEnvironment.getQualifiers()); if (themeStyleResource == null) return null; StyleData themeStyleData = (StyleData) themeStyleResource.getData(); if (themeStyleSet == null) { themeStyleSet = new ThemeStyleSet(); } return new StyleResolver(resourceTable, shadowOf(AssetManager.getSystem()).getResourceTable(), themeStyleData, themeStyleSet, themeStyleName, RuntimeEnvironment.getQualifiers()); }
private Style resolveStyle(@Nonnull ResName themeStyleName, Style themeStyleSet) { TypedResource themeStyleResource = resourceTable.getValue(themeStyleName, RuntimeEnvironment.getQualifiers()); if (themeStyleResource == null) return null; StyleData themeStyleData = (StyleData) themeStyleResource.getData(); if (themeStyleSet == null) { themeStyleSet = new ThemeStyleSet(); } return new StyleResolver(resourceTable, shadowOf(AssetManager.getSystem()).getResourceTable(), themeStyleData, themeStyleSet, themeStyleName, RuntimeEnvironment.getQualifiers()); }