Search in sources :

Example 16 with AttributeDefinition

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

the class EnumSupportFactory method supportsProperty.

public static boolean supportsProperty(@NotNull NlProperty property) {
    switch(property.getName()) {
        case ATTR_FONT_FAMILY:
        case ATTR_TYPEFACE:
        case ATTR_TEXT_SIZE:
        case ATTR_LINE_SPACING_EXTRA:
        case ATTR_TEXT_APPEARANCE:
        case ATTR_LAYOUT_HEIGHT:
        case ATTR_LAYOUT_WIDTH:
        case ATTR_DROPDOWN_HEIGHT:
        case ATTR_DROPDOWN_WIDTH:
        case ATTR_ON_CLICK:
            return true;
        case ATTR_ID:
            return false;
        case ATTR_STYLE:
            String tagName = property.getTagName();
            return tagName != null && StyleFilter.hasWidgetStyles(property.getModel().getProject(), property.getResolver(), tagName);
        default:
            if (property.getName().endsWith(TEXT_APPEARANCE_SUFFIX)) {
                return true;
            }
            if (AndroidDomUtil.SPECIAL_RESOURCE_TYPES.get(property.getName()) == ResourceType.ID) {
                return true;
            }
            AttributeDefinition definition = property.getDefinition();
            Set<AttributeFormat> formats = definition != null ? definition.getFormats() : Collections.emptySet();
            return formats.contains(AttributeFormat.Enum);
    }
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition)

Example 17 with AttributeDefinition

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

the class NlPropertyRenderers method get.

@NotNull
public static TableCellRenderer get(@NotNull NlProperty p) {
    AttributeDefinition definition = p.getDefinition();
    if (definition == null) {
        return getDefaultRenderer();
    }
    Set<AttributeFormat> formats = definition.getFormats();
    if (formats.size() == 1 && formats.contains(AttributeFormat.Boolean)) {
        NlBooleanRenderer renderer = getBooleanRenderer();
        if (renderer.canRender(p, formats)) {
            return renderer;
        }
    }
    if (formats.contains(AttributeFormat.Flag)) {
        NlFlagRenderer renderer = getFlagRenderer();
        if (renderer.canRender(p, formats)) {
            return renderer;
        }
    }
    return getDefaultRenderer();
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with AttributeDefinition

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

the class IdAnalyzerTest method testButton1And2.

public void testButton1And2() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button1 = findById(model, "button1");
    NlComponent button2 = findById(model, "button2");
    NlProperty accessibility = new NlPropertyItem(ImmutableList.of(button1, button2), ANDROID_URI, new AttributeDefinition(ATTR_ACCESSIBILITY_TRAVERSAL_BEFORE));
    IdAnalyzer analyzer = new IdAnalyzer(accessibility);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 19 with AttributeDefinition

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

the class IdAnalyzerTest method testRadioGroup.

public void testRadioGroup() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent group = findById(model, "group1");
    NlProperty property = new NlPropertyItem(ImmutableList.of(group), ANDROID_URI, new AttributeDefinition(ATTR_CHECKED_BUTTON));
    IdAnalyzer analyzer = new IdAnalyzer(property);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("radio_button1", "radio_button2", "radio_button3"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 20 with AttributeDefinition

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

the class QuantityTest method mockProperty.

private static NlProperty mockProperty(@NotNull String attribute, @NotNull AttributeFormat format) {
    NlProperty property = Mockito.mock(NlProperty.class);
    Mockito.when(property.getName()).thenReturn(attribute);
    Mockito.when(property.getDefinition()).thenReturn(new AttributeDefinition(attribute, null, Collections.singleton(format)));
    return property;
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition)

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