public ThemeStyleSet copy() { ThemeStyleSet themeStyleSet = new ThemeStyleSet(); themeStyleSet.styles.addAll(this.styles); return themeStyleSet; }
@Test public void shouldFindAttributesFromAnAppliedStyle() throws Exception { themeStyleSet = new ThemeStyleSet(); themeStyleSet.apply(createStyle("style1", createAttribute("string1", "string1 value from style1"), createAttribute("string2", "string2 value from style1") ), false); themeStyleSet.apply(createStyle("style2", createAttribute("string2", "string2 value from style2")), false); assertThat(themeStyleSet.getAttrValue(attrName("string1")).value).isEqualTo("string1 value from style1"); assertThat(themeStyleSet.getAttrValue(attrName("string2")).value).isEqualTo("string2 value from style1"); }
@HiddenApi @Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1) public static void copyTheme(long destPtr, long sourcePtr) { NativeTheme destNativeTheme = getNativeTheme(destPtr); NativeTheme sourceNativeTheme = getNativeTheme(sourcePtr); destNativeTheme.themeStyleSet = sourceNativeTheme.themeStyleSet.copy(); }
@Test public void shouldFindAttributesFromAnAppliedFromForcedStyle() throws Exception { themeStyleSet.apply(createStyle("style1", createAttribute("string1", "string1 value from style1"), createAttribute("string2", "string2 value from style1") ), false); themeStyleSet.apply(createStyle("style2", createAttribute("string1", "string1 value from style2")), true); assertThat(themeStyleSet.getAttrValue(attrName("string1")).value).isEqualTo("string1 value from style2"); assertThat(themeStyleSet.getAttrValue(attrName("string2")).value).isEqualTo("string2 value from style1"); }
@HiddenApi @Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1) public static void applyThemeStyle(long themePtr, int styleRes, boolean force) { NativeTheme nativeTheme = getNativeTheme(themePtr); Style style = nativeTheme.getShadowAssetManager().resolveStyle(styleRes, null); nativeTheme.themeStyleSet.apply(style, force); }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) { ResName resName = resourceTable.getResName(ident); ThemeStyleSet themeStyleSet = getNativeTheme(themePtr).themeStyleSet; AttributeResource attrValue = themeStyleSet.getAttrValue(resName); while(attrValue != null && attrValue.isStyleReference()) { ResName attrResName = attrValue.getStyleReference(); if (attrValue.resName.equals(attrResName)) { Logger.info("huh... circular reference for %s?", attrResName.getFullyQualifiedName()); return false; } attrValue = themeStyleSet.getAttrValue(attrResName); } if (attrValue != null) { convertAndFill(attrValue, outValue, config, resolveRefs); return true; } return false; }
void doApplyStyle(int styleRes, boolean force) { Style style = getShadowAssetManager().resolveStyle(styleRes, null); themeStyleSet.apply(style, force); }
@HiddenApi @Implementation public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) { ResourceIndex resourceIndex = resourceLoader.getResourceIndex(); ResName resName = resourceIndex.getResName(ident); ThemeStyleSet themeStyleSet = shadowOf(getTheme(themePtr)).getThemeStyleSet(); AttributeResource attrValue = themeStyleSet.getAttrValue(resName); while(resolveRefs && attrValue != null && attrValue.isStyleReference()) { ResName attrResName = new ResName(attrValue.contextPackageName, "attr", attrValue.value.substring(1)); attrValue = themeStyleSet.getAttrValue(attrResName); } if (attrValue != null) { Converter.convertAndFill(attrValue, outValue, resourceLoader, RuntimeEnvironment.getQualifiers(), resolveRefs); return true; } return false; }
@HiddenApi @Implementation public Number createTheme() { synchronized (nativeThemes) { long nativePtr = nextInternalThemeId++; nativeThemes.put(nativePtr, new NativeTheme(new ThemeStyleSet())); return castNativePtr(nativePtr); } }
@HiddenApi @Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1) public static void applyThemeStyle(long themePtr, int styleRes, boolean force) { NativeTheme nativeTheme = getNativeTheme(themePtr); Style style = nativeTheme.getShadowAssetManager().resolveStyle(styleRes, null); nativeTheme.themeStyleSet.apply(style, force); }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) { ResName resName = resourceTable.getResName(ident); ThemeStyleSet themeStyleSet = getNativeTheme(themePtr).themeStyleSet; AttributeResource attrValue = themeStyleSet.getAttrValue(resName); while(attrValue != null && attrValue.isStyleReference()) { ResName attrResName = attrValue.getStyleReference(); if (attrValue.resName.equals(attrResName)) { Logger.info("huh... circular reference for %s?", attrResName.getFullyQualifiedName()); return false; } attrValue = themeStyleSet.getAttrValue(attrResName); } if (attrValue != null) { convertAndFill(attrValue, outValue, config, resolveRefs); return true; } return false; }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public static void copyTheme(long destPtr, long sourcePtr) { NativeTheme destNativeTheme = getNativeTheme(destPtr); NativeTheme sourceNativeTheme = getNativeTheme(sourcePtr); destNativeTheme.themeStyleSet = sourceNativeTheme.themeStyleSet.copy(); }
@Before public void setUp() throws Exception { themeStyleSet = new ThemeStyleSet(); }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public static void applyThemeStyle(long themePtr, int styleRes, boolean force) { NativeTheme nativeTheme = getNativeTheme(themePtr); Style style = nativeTheme.getShadowAssetManager().resolveStyle(styleRes, null); nativeTheme.themeStyleSet.apply(style, force); }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) { ResName resName = resourceTable.getResName(ident); ThemeStyleSet themeStyleSet = getNativeTheme(themePtr).themeStyleSet; AttributeResource attrValue = themeStyleSet.getAttrValue(resName); while(attrValue != null && attrValue.isStyleReference()) { ResName attrResName = attrValue.getStyleReference(); if (attrValue.resName.equals(attrResName)) { Logger.info("huh... circular reference for %s?", attrResName.getFullyQualifiedName()); return false; } attrValue = themeStyleSet.getAttrValue(attrResName); } if (attrValue != null) { convertAndFill(attrValue, outValue, RuntimeEnvironment.getQualifiers(), resolveRefs); return true; } return false; }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public static void copyTheme(long destPtr, long sourcePtr) { NativeTheme destNativeTheme = getNativeTheme(destPtr); NativeTheme sourceNativeTheme = getNativeTheme(sourcePtr); destNativeTheme.themeStyleSet = sourceNativeTheme.themeStyleSet.copy(); }
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); }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public static void applyThemeStyle(long themePtr, int styleRes, boolean force) { NativeTheme nativeTheme = getNativeTheme(themePtr); Style style = nativeTheme.getShadowAssetManager().resolveStyle(styleRes, null); nativeTheme.themeStyleSet.apply(style, force); }
@HiddenApi @Implementation(minSdk = LOLLIPOP) public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) { ResName resName = resourceTable.getResName(ident); ThemeStyleSet themeStyleSet = getNativeTheme(themePtr).themeStyleSet; AttributeResource attrValue = themeStyleSet.getAttrValue(resName); while(attrValue != null && attrValue.isStyleReference()) { ResName attrResName = attrValue.getStyleReference(); if (attrValue.resName.equals(attrResName)) { Logger.info("huh... circular reference for %s?", attrResName.getFullyQualifiedName()); return false; } attrValue = themeStyleSet.getAttrValue(attrResName); } if (attrValue != null) { convertAndFill(attrValue, outValue, RuntimeEnvironment.getQualifiers(), resolveRefs); return true; } return false; }
@HiddenApi @Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1) public static void copyTheme(long destPtr, long sourcePtr) { NativeTheme destNativeTheme = getNativeTheme(destPtr); NativeTheme sourceNativeTheme = getNativeTheme(sourcePtr); destNativeTheme.themeStyleSet = sourceNativeTheme.themeStyleSet.copy(); }