use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class GradleInstantRunContext method getManifestResourcesHash.
@VisibleForTesting
static HashCode getManifestResourcesHash(@NotNull AndroidFacet facet) {
Document manifest = MergedManifest.get(facet).getDocument();
if (manifest == null || manifest.getDocumentElement() == null) {
return HashCode.fromInt(0);
}
final Hasher hasher = Hashing.goodFastHash(32).newHasher();
SortedSet<ResourceUrl> appResourceReferences = getAppResourceReferences(manifest.getDocumentElement());
AppResourceRepository appResources = AppResourceRepository.getAppResources(facet, true);
// read action needed when reading the values for app resources
ApplicationManager.getApplication().runReadAction(() -> {
hashResources(appResourceReferences, appResources, hasher);
});
return hasher.hash();
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class ResourceHelper method createStateListState.
/**
* Try to parse a state in the "item" tag. Only handles those items that have
* either "android:color" or "android:drawable" attributes in "item" tag.
*
* @return {@link StateListState} representing the state in tag, null if parse is unsuccessful
*/
@Nullable
private static StateListState createStateListState(XmlTag tag, boolean isFramework) {
String stateValue = null;
String alphaValue = null;
Map<String, Boolean> stateAttributes = new HashMap<>();
XmlAttribute[] attributes = tag.getAttributes();
for (XmlAttribute attr : attributes) {
String name = attr.getLocalName();
String value = attr.getValue();
if (value == null) {
continue;
}
if (ATTR_COLOR.equals(name) || ATTR_DRAWABLE.equals(name)) {
ResourceUrl url = ResourceUrl.parse(value, isFramework);
stateValue = url != null ? url.toString() : value;
} else if ("alpha".equals(name)) {
ResourceUrl url = ResourceUrl.parse(value, isFramework);
alphaValue = url != null ? url.toString() : value;
} else if (name.startsWith(STATE_NAME_PREFIX)) {
stateAttributes.put(name, Boolean.valueOf(value));
}
}
if (stateValue == null) {
return null;
}
return new StateListState(stateValue, stateAttributes, alphaValue);
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class DataBindingUtil method getViewClassNameFromLayoutReferenceTag.
private static String getViewClassNameFromLayoutReferenceTag(XmlTag tag, AndroidFacet facet) {
String layout = tag.getAttributeValue(SdkConstants.ATTR_LAYOUT);
if (layout == null) {
return null;
}
LocalResourceRepository moduleResources = facet.getModuleResources(false);
if (moduleResources == null) {
return null;
}
ResourceUrl resourceUrl = ResourceUrl.parse(layout);
if (resourceUrl == null || resourceUrl.type != ResourceType.LAYOUT) {
return null;
}
DataBindingInfo info = moduleResources.getDataBindingInfoForLayout(resourceUrl.name);
if (info == null) {
return null;
}
return info.getQualifiedName();
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class ResolutionUtils method getOriginalApiLevel.
/**
* Returns the Api level at which was defined the attribute or value with the name passed as argument.
* Returns -1 if the name argument is null or not the name of a framework attribute or resource,
* or if it is the name of a framework attribute or resource defined in API 1, or if no Lint client found.
*/
public static int getOriginalApiLevel(@Nullable String name, @NotNull Project project) {
if (name == null) {
return -1;
}
ApiLookup apiLookup = LintIdeClient.getApiLookup(project);
if (apiLookup == null) {
// There is no Lint API database for this project
LOG.warn("Could not find Lint client for project " + project.getName());
return -1;
}
ResourceUrl resUrl = ResourceUrl.parse(name);
if (resUrl == null) {
// It is an attribute
if (!name.startsWith(ANDROID_NS_NAME_PREFIX)) {
// not an android attribute
return -1;
}
return apiLookup.getFieldVersion("android/R$attr", name.substring(ANDROID_NS_NAME_PREFIX_LEN));
} else {
if (!resUrl.framework) {
// not an android value
return -1;
}
return apiLookup.getFieldVersion("android/R$" + resUrl.type, AndroidResourceUtil.getFieldNameByResourceName(resUrl.name));
}
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class GutterIconCache method replaceResourceReferences.
private static void replaceResourceReferences(@NonNull Node node, @NonNull ResourceResolver resolver) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
NamedNodeMap attributes = element.getAttributes();
attributes: for (int i = 0, n = attributes.getLength(); i < n; i++) {
Node attribute = attributes.item(i);
String value = attribute.getNodeValue();
if (!(value.startsWith(PREFIX_RESOURCE_REF) || value.startsWith(PREFIX_THEME_REF))) {
continue;
}
for (int j = 0; j < 10; j++) {
ResourceUrl resolvedUrl = ResourceUrl.parse(value);
if (resolvedUrl == null) {
continue attributes;
}
ResourceValue resourceValue;
if (resolvedUrl.theme) {
resourceValue = resolver.findItemInTheme(resolvedUrl.name, resolvedUrl.framework);
} else {
resourceValue = resolver.findResValue(resolvedUrl.toString(), resolvedUrl.framework);
}
if (resourceValue == null) {
continue attributes;
}
value = resourceValue.getValue();
if (value == null) {
continue attributes;
}
if (!(value.startsWith(PREFIX_RESOURCE_REF) || value.startsWith(PREFIX_THEME_REF))) {
// Found leaf value
attribute.setNodeValue(value);
break;
}
}
}
}
node = node.getFirstChild();
while (node != null) {
replaceResourceReferences(node, resolver);
node = node.getNextSibling();
}
}
Aggregations