Search in sources :

Example 1 with ResourceManager

use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.

the class AttributeProcessingUtil method processMenuItemAttributes.

private static void processMenuItemAttributes(@NotNull AndroidFacet facet, @NotNull DomElement element, @NotNull Collection<XmlName> skippedAttributes, @NotNull AttributeProcessor callback) {
    ResourceManager manager = facet.getSystemResourceManager();
    if (manager == null) {
        return;
    }
    AttributeDefinitions styleables = manager.getAttributeDefinitions();
    if (styleables == null) {
        return;
    }
    StyleableDefinition styleable = styleables.getStyleableByName("MenuItem");
    if (styleable == null) {
        getLog().warn("No StyleableDefinition for MenuItem");
        return;
    }
    for (AttributeDefinition attribute : styleable.getAttributes()) {
        String name = attribute.getName();
        // .lint.checks.AppCompatResourceDetector.
        if (name.equals(ATTR_SHOW_AS_ACTION)) {
            AndroidModuleModel model = AndroidModuleModel.get(facet);
            if (model != null && GradleUtil.dependsOn(model, APPCOMPAT_LIB_ARTIFACT)) {
                if (skippedAttributes.add(new XmlName(name, AUTO_URI))) {
                    registerAttribute(attribute, "MenuItem", AUTO_URI, element, callback);
                }
                continue;
            }
        }
        if (skippedAttributes.add(new XmlName(name, ANDROID_URI))) {
            registerAttribute(attribute, "MenuItem", ANDROID_URI, element, callback);
        }
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) XmlName(com.intellij.util.xml.XmlName) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) SystemResourceManager(org.jetbrains.android.resourceManagers.SystemResourceManager)

Example 2 with ResourceManager

use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.

the class AndroidDomUtil method getAttributeDefinition.

@Nullable
public static AttributeDefinition getAttributeDefinition(@NotNull AndroidFacet facet, @NotNull XmlAttribute attribute) {
    String localName = attribute.getLocalName();
    String namespace = attribute.getNamespace();
    boolean isFramework = namespace.equals(ANDROID_URI);
    if (!isFramework && TOOLS_URI.equals(namespace)) {
        // Treat tools namespace attributes as aliases for Android namespaces: see https://developer.android.com/studio/write/tool-attributes.html#design-time_view_attributes
        isFramework = true;
        // However, there are some attributes with other meanings: https://developer.android.com/studio/write/tool-attributes.html
        // Filter some of these out such that they are not treated as the (unrelated but identically named) platform attributes
        AttributeDefinition toolsAttr = TOOLS_ATTRIBUTE_DEFINITIONS.getAttrDefByName(localName);
        if (toolsAttr != null) {
            return toolsAttr;
        }
    }
    ResourceManager manager = facet.getResourceManager(isFramework ? SYSTEM_RESOURCE_PACKAGE : null);
    if (manager != null) {
        AttributeDefinitions attrDefs = manager.getAttributeDefinitions();
        if (attrDefs != null) {
            return attrDefs.getAttrDefByName(localName);
        }
    }
    return null;
}
Also used : AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ResourceManager

use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.

the class AttributeProcessingUtil method registerAttributes.

private static void registerAttributes(AndroidFacet facet, DomElement element, @NotNull String styleableName, @Nullable String resPackage, AttributeProcessor callback, Set<XmlName> skipNames) {
    ResourceManager manager = facet.getResourceManager(resPackage);
    if (manager == null) {
        return;
    }
    AttributeDefinitions attrDefs = manager.getAttributeDefinitions();
    if (attrDefs == null) {
        return;
    }
    String namespace = getNamespaceKeyByResourcePackage(facet, resPackage);
    StyleableDefinition styleable = attrDefs.getStyleableByName(styleableName);
    if (styleable != null) {
        registerStyleableAttributes(element, styleable, namespace, callback, skipNames);
    }
// It's a good idea to add a warning when styleable not found, to make sure that code doesn't
// try to use attributes that don't exist. However, current AndroidDomExtender code relies on
// a lot of "heuristics" that fail quite a lot (like adding a bunch of suffixes to short class names)
// TODO: add a warning when rest of the code of AndroidDomExtender is cleaned up
}
Also used : ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) SystemResourceManager(org.jetbrains.android.resourceManagers.SystemResourceManager)

Example 4 with ResourceManager

use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.

the class ResourceReferenceConverter method addResourceReferenceValues.

private static void addResourceReferenceValues(AndroidFacet facet, char prefix, ResourceType type, @Nullable String resPackage, Collection<ResourceValue> result, boolean explicitResourceType) {
    final ResourceManager manager = facet.getResourceManager(resPackage);
    String typeName = type.getName();
    if (manager != null) {
        for (String name : manager.getResourceNames(type, true)) {
            result.add(referenceTo(prefix, typeName, resPackage, name, explicitResourceType));
        }
    }
}
Also used : ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager)

Example 5 with ResourceManager

use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.

the class AndroidFindStyleApplicationsAction method resolveStyleRef.

private static PsiElement resolveStyleRef(StyleRefData styleRef, AndroidFacet facet) {
    final ResourceManager resourceManager = facet.getResourceManager(styleRef.getStylePackage());
    if (resourceManager == null) {
        return null;
    }
    final List<ValueResourceInfoImpl> infos = resourceManager.findValueResourceInfos(ResourceType.STYLE.getName(), styleRef.getStyleName(), true, false);
    return infos.size() == 1 ? infos.get(0).computeXmlElement() : null;
}
Also used : ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) ValueResourceInfoImpl(org.jetbrains.android.resourceManagers.ValueResourceInfoImpl)

Aggregations

ResourceManager (org.jetbrains.android.resourceManagers.ResourceManager)14 AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)5 LocalResourceManager (org.jetbrains.android.resourceManagers.LocalResourceManager)4 XmlTag (com.intellij.psi.xml.XmlTag)3 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 SystemResourceManager (org.jetbrains.android.resourceManagers.SystemResourceManager)3 ResourceType (com.android.resources.ResourceType)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 Attr (org.jetbrains.android.dom.resources.Attr)2 DeclareStyleable (org.jetbrains.android.dom.resources.DeclareStyleable)2 AndroidResourceUtil (org.jetbrains.android.util.AndroidResourceUtil)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)1 ResourceItem (com.android.ide.common.res2.ResourceItem)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1