use of android.content.res.BridgeTypedArray in project android_frameworks_base by AOSPA.
the class BridgeContext method createStyleBasedTypedArray.
// ------------- private new methods
/**
* Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
* values found in the given style. If no style is specified, the default theme, along with the
* styles applied to it are used.
*
* @see #obtainStyledAttributes(int, int[])
*/
private Pair<BridgeTypedArray, PropertiesMap> createStyleBasedTypedArray(@Nullable StyleResourceValue style, int[] attrs) throws Resources.NotFoundException {
List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length, false);
PropertiesMap defaultPropMap = new PropertiesMap();
// for each attribute, get its name so that we can search it in the style
for (int i = 0; i < attrs.length; i++) {
Pair<String, Boolean> attribute = attributes.get(i);
if (attribute != null) {
// look for the value in the given style
ResourceValue resValue;
String attrName = attribute.getFirst();
boolean frameworkAttr = attribute.getSecond();
if (style != null) {
resValue = mRenderResources.findItemInStyle(style, attrName, frameworkAttr);
} else {
resValue = mRenderResources.findItemInTheme(attrName, frameworkAttr);
}
if (resValue != null) {
// Add it to defaultPropMap before resolving
String preResolve = resValue.getValue();
// resolve it to make sure there are no references left.
resValue = mRenderResources.resolveResValue(resValue);
ta.bridgeSetValue(i, attrName, frameworkAttr, resValue);
defaultPropMap.put(frameworkAttr ? SdkConstants.ANDROID_PREFIX + attrName : attrName, new Property(preResolve, resValue.getValue()));
}
}
}
ta.sealArray();
return Pair.of(ta, defaultPropMap);
}
use of android.content.res.BridgeTypedArray in project android_frameworks_base by AOSPA.
the class BridgeContext method obtainStyledAttributes.
@Override
public final BridgeTypedArray obtainStyledAttributes(int resId, int[] attrs) throws Resources.NotFoundException {
StyleResourceValue style = null;
// get the StyleResourceValue based on the resId;
if (resId != 0) {
style = getStyleByDynamicId(resId);
if (style == null) {
// In some cases, style may not be a dynamic id, so we do a full search.
ResourceReference ref = resolveId(resId);
if (ref != null) {
style = mRenderResources.getStyle(ref.getName(), ref.isFramework());
}
}
if (style == null) {
throw new Resources.NotFoundException();
}
}
if (mTypedArrayCache == null) {
mTypedArrayCache = new TypedArrayCache();
}
List<StyleResourceValue> currentThemes = mRenderResources.getAllThemes();
Pair<BridgeTypedArray, PropertiesMap> typeArrayAndPropertiesPair = mTypedArrayCache.get(attrs, currentThemes, resId);
if (typeArrayAndPropertiesPair == null) {
typeArrayAndPropertiesPair = createStyleBasedTypedArray(style, attrs);
mTypedArrayCache.put(attrs, currentThemes, resId, typeArrayAndPropertiesPair);
}
// Add value to defaultPropsMap if needed
if (typeArrayAndPropertiesPair.getSecond() != null) {
BridgeXmlBlockParser parser = getCurrentParser();
Object key = parser != null ? parser.getViewCookie() : null;
if (key != null) {
PropertiesMap defaultPropMap = mDefaultPropMaps.get(key);
if (defaultPropMap == null) {
defaultPropMap = typeArrayAndPropertiesPair.getSecond();
mDefaultPropMaps.put(key, defaultPropMap);
} else {
defaultPropMap.putAll(typeArrayAndPropertiesPair.getSecond());
}
}
}
return typeArrayAndPropertiesPair.getFirst();
}
use of android.content.res.BridgeTypedArray in project android_frameworks_base by crdroidandroid.
the class BridgeContext method createStyleBasedTypedArray.
// ------------- private new methods
/**
* Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
* values found in the given style. If no style is specified, the default theme, along with the
* styles applied to it are used.
*
* @see #obtainStyledAttributes(int, int[])
*/
private Pair<BridgeTypedArray, PropertiesMap> createStyleBasedTypedArray(@Nullable StyleResourceValue style, int[] attrs) throws Resources.NotFoundException {
List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length, false);
PropertiesMap defaultPropMap = new PropertiesMap();
// for each attribute, get its name so that we can search it in the style
for (int i = 0; i < attrs.length; i++) {
Pair<String, Boolean> attribute = attributes.get(i);
if (attribute != null) {
// look for the value in the given style
ResourceValue resValue;
String attrName = attribute.getFirst();
boolean frameworkAttr = attribute.getSecond();
if (style != null) {
resValue = mRenderResources.findItemInStyle(style, attrName, frameworkAttr);
} else {
resValue = mRenderResources.findItemInTheme(attrName, frameworkAttr);
}
if (resValue != null) {
// Add it to defaultPropMap before resolving
String preResolve = resValue.getValue();
// resolve it to make sure there are no references left.
resValue = mRenderResources.resolveResValue(resValue);
ta.bridgeSetValue(i, attrName, frameworkAttr, resValue);
defaultPropMap.put(frameworkAttr ? SdkConstants.ANDROID_PREFIX + attrName : attrName, new Property(preResolve, resValue.getValue()));
}
}
}
ta.sealArray();
return Pair.of(ta, defaultPropMap);
}
Aggregations