use of com.google.devtools.build.android.resources.IntArrayFieldInitializer in project bazel by bazelbuild.
the class AndroidResourceClassWriter method getStyleableInitializers.
private List<FieldInitializer> getStyleableInitializers(Map<String, Integer> attrAssignments, Collection<String> styleableFields) throws AttrLookupException {
ImmutableList.Builder<FieldInitializer> initList = ImmutableList.builder();
for (String field : styleableFields) {
Set<String> attrs = styleableAttrs.get(field).keySet();
ImmutableMap.Builder<String, Integer> arrayInitValues = ImmutableMap.builder();
for (String attr : attrs) {
Integer attrId = attrAssignments.get(attr);
if (attrId == null) {
// It should be a framework resource, otherwise we don't know about the resource.
if (!attr.startsWith(NORMALIZED_ANDROID_PREFIX)) {
throw new AttrLookupException("App attribute not found: " + attr);
}
String attrWithoutPrefix = attr.substring(NORMALIZED_ANDROID_PREFIX.length());
attrId = androidIdProvider.getAttrId(attrWithoutPrefix);
}
arrayInitValues.put(attr, attrId);
}
// The styleable array should be sorted by ID value.
// Make sure that if we have android: framework attributes, their IDs are listed first.
ImmutableMap<String, Integer> arrayInitMap = arrayInitValues.orderEntriesByValue(Ordering.<Integer>natural()).build();
initList.add(new IntArrayFieldInitializer(field, arrayInitMap.values()));
int index = 0;
for (String attr : arrayInitMap.keySet()) {
initList.add(new IntFieldInitializer(field + "_" + attr, index));
++index;
}
}
return initList.build();
}
Aggregations