Search in sources :

Example 21 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class AndroidXmlDocumentationProvider method findAttributeDefinition.

@Nullable
private static Pair<AttributeDefinition, String> findAttributeDefinition(@NotNull PsiElement originalElement, @NotNull AndroidFacet facet, @NotNull final String namespace, @NotNull final String localName) {
    if (!originalElement.isValid()) {
        return null;
    }
    final XmlTag parentTag = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class);
    if (parentTag == null) {
        return null;
    }
    final DomElement parentDomElement = DomManager.getDomManager(parentTag.getProject()).getDomElement(parentTag);
    if (!(parentDomElement instanceof AndroidDomElement)) {
        return null;
    }
    final Ref<Pair<AttributeDefinition, String>> result = Ref.create();
    try {
        AttributeProcessingUtil.processAttributes((AndroidDomElement) parentDomElement, facet, false, (xn, attrDef, parentStyleableName) -> {
            if (xn.getLocalName().equals(localName) && namespace.equals(xn.getNamespaceKey())) {
                result.set(Pair.of(attrDef, parentStyleableName));
                throw new MyStopException();
            }
            return null;
        });
    } catch (MyStopException e) {
    // ignore
    }
    final Pair<AttributeDefinition, String> pair = result.get();
    if (pair != null) {
        return pair;
    }
    final AttributeDefinition attrDef = findAttributeDefinitionGlobally(facet, namespace, localName);
    return attrDef != null ? Pair.of(attrDef, (String) null) : null;
}
Also used : AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) XmlTag(com.intellij.psi.xml.XmlTag) Pair(com.android.utils.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class ColorRendererEditor method getAllowedResourceTypes.

@NotNull
@Override
protected EnumSet<ResourceType> getAllowedResourceTypes() {
    AttributeDefinition attrDefinition = ResolutionUtils.getAttributeDefinition(myContext.getConfiguration(), myItem.getSelectedValue());
    String attributeName = myItem.getName().toLowerCase(Locale.ENGLISH);
    if (attributeName.contains("color") || !ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Reference)) {
        return COLORS_ONLY;
    } else if (attributeName.contains("drawable") || !ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Color)) {
        return DRAWABLES_ONLY;
    } else {
        return COLORS_AND_DRAWABLES;
    }
}
Also used : AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class EnumRendererEditor method getEditorComponent.

@Override
public Component getEditorComponent(JTable table, EditedStyleItem value, boolean isSelected, int row, int column) {
    AttributeDefinition attrDefinition = ResolutionUtils.getAttributeDefinition(value.getSourceStyle().getConfiguration(), value.getSelectedValue());
    if (attrDefinition != null) {
        if (attrDefinition.getFormats().size() > 1) {
            // makes the box editable for items that can take values outside of the choices
            myComboBox.setEditable(true);
        } else {
            myComboBox.setEditable(false);
        }
        myComboBox.setModel(new DefaultComboBoxModel(attrDefinition.getValues()));
    }
    myComboBox.setSelectedItem(value.getValue());
    return myComboBox;
}
Also used : AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition)

Example 24 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class AndroidCompletionContributor method isFrameworkAttributeDeprecated.

private static boolean isFrameworkAttributeDeprecated(AndroidFacet facet, XmlAttribute attribute, String attributeName) {
    final ResourceManager manager = facet.getResourceManager(AndroidUtils.SYSTEM_RESOURCE_PACKAGE, attribute.getParent());
    if (manager == null) {
        return false;
    }
    final AttributeDefinitions attributes = manager.getAttributeDefinitions();
    if (attributes == null) {
        return false;
    }
    final AttributeDefinition attributeDefinition = attributes.getAttrDefByName(attributeName);
    return attributeDefinition != null && attributeDefinition.isAttributeDeprecated();
}
Also used : AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager)

Example 25 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class AndroidJavaDocRenderer method renderAttributeDoc.

@NotNull
private static String renderAttributeDoc(@NotNull Module module, @Nullable Configuration configuration, @NotNull String name) {
    AttributeDefinition def = ResolutionUtils.getAttributeDefinition(module, configuration, name);
    String doc = (def == null) ? null : def.getDocValue(null);
    HtmlBuilder builder = new HtmlBuilder();
    builder.openHtmlBody();
    builder.beginBold();
    builder.add(name);
    builder.endBold();
    int api = ResolutionUtils.getOriginalApiLevel(name, module.getProject());
    if (api >= 0) {
        builder.add(" (Added in API level ");
        builder.add(String.valueOf(api));
        builder.add(")");
    }
    builder.addHtml("<br/>");
    if (!StringUtil.isEmpty(doc)) {
        builder.addHtml(doc);
        builder.addHtml("<br/>");
    }
    builder.addHtml("<hr/>");
    builder.closeHtmlBody();
    return builder.getHtml();
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)35 NotNull (org.jetbrains.annotations.NotNull)10 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)8 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)7 Nullable (org.jetbrains.annotations.Nullable)7 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)6 AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)6 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 AttributeFormat (org.jetbrains.android.dom.attrs.AttributeFormat)5 ResourceType (com.android.resources.ResourceType)4 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)3 XmlTag (com.intellij.psi.xml.XmlTag)3 ResourceManager (org.jetbrains.android.resourceManagers.ResourceManager)3 HtmlBuilder (com.android.utils.HtmlBuilder)2 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1