Search in sources :

Example 6 with AttributeFormat

use of org.jetbrains.android.dom.attrs.AttributeFormat 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 7 with AttributeFormat

use of org.jetbrains.android.dom.attrs.AttributeFormat 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 8 with AttributeFormat

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

the class AndroidDomUtil method getConverter.

@Nullable
public static ResolvingConverter getConverter(@NotNull AttributeDefinition attr) {
    Set<AttributeFormat> formats = attr.getFormats();
    CompositeConverter.Builder compositeBuilder = new CompositeConverter.Builder();
    String[] values = attr.getValues();
    boolean containsUnsupportedFormats = false;
    if ("fontFamily".equals(attr.getName())) {
        compositeBuilder.addConverter(new StaticEnumConverter(AVAILABLE_FAMILIES).setContainsAllValues(false));
    }
    for (AttributeFormat format : formats) {
        ResolvingConverter<String> converter = getStringConverter(format, values);
        if (converter != null) {
            compositeBuilder.addConverter(converter);
        } else {
            containsUnsupportedFormats = true;
        }
    }
    ResourceReferenceConverter resConverter = getResourceReferenceConverter(attr);
    if (formats.contains(AttributeFormat.Flag)) {
        return new FlagConverter(compositeBuilder.build(), values);
    }
    if (resConverter == null && formats.contains(AttributeFormat.Enum)) {
        resConverter = new ResourceReferenceConverter(EnumSet.of(ResourceType.INTEGER), attr);
        resConverter.setQuiet(true);
    }
    ResolvingConverter<String> stringConverter = compositeBuilder.build();
    if (resConverter != null) {
        resConverter.setAdditionalConverter(stringConverter, containsUnsupportedFormats);
        return resConverter;
    }
    return stringConverter;
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with AttributeFormat

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

the class AndroidXmlDocumentationProvider method generateDocForXmlAttribute.

private static String generateDocForXmlAttribute(@NotNull AttributeDefinition definition, @Nullable String parentStyleable) {
    final StringBuilder builder = new StringBuilder("<html><body>");
    final Set<AttributeFormat> formats = definition.getFormats();
    if (formats.size() > 0) {
        builder.append("Formats: ");
        final List<String> formatLabels = new ArrayList<>(formats.size());
        for (AttributeFormat format : formats) {
            formatLabels.add(format.name().toLowerCase(Locale.US));
        }
        Collections.sort(formatLabels);
        for (int i = 0, n = formatLabels.size(); i < n; i++) {
            builder.append(formatLabels.get(i));
            if (i < n - 1) {
                builder.append(", ");
            }
        }
    }
    final String[] values = definition.getValues();
    if (values.length > 0) {
        if (builder.length() > 0) {
            builder.append("<br>");
        }
        builder.append("Values: ");
        final String[] sortedValues = new String[values.length];
        System.arraycopy(values, 0, sortedValues, 0, values.length);
        Arrays.sort(sortedValues);
        for (int i = 0; i < sortedValues.length; i++) {
            builder.append(sortedValues[i]);
            if (i < sortedValues.length - 1) {
                builder.append(", ");
            }
        }
    }
    final String docValue = definition.getDocValue(parentStyleable);
    if (docValue != null && docValue.length() > 0) {
        if (builder.length() > 0) {
            builder.append("<br><br>");
        }
        builder.append(docValue);
    }
    builder.append("</body></html>");
    return builder.toString();
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat)

Example 10 with AttributeFormat

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

the class BrowsePanel method getResourceTypes.

@NotNull
public static EnumSet<ResourceType> getResourceTypes(@NotNull String propertyName, @Nullable AttributeDefinition definition) {
    Set<AttributeFormat> formats = definition != null ? definition.getFormats() : EnumSet.allOf(AttributeFormat.class);
    // for some special known properties, we can narrow down the possible types (rather than the all encompassing reference type)
    ResourceType type = AndroidDomUtil.SPECIAL_RESOURCE_TYPES.get(propertyName);
    return type == null ? AttributeFormat.convertTypes(formats) : EnumSet.of(type);
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) ResourceType(com.android.resources.ResourceType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AttributeFormat (org.jetbrains.android.dom.attrs.AttributeFormat)11 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)6 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 ResourceType (com.android.resources.ResourceType)3 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)2 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1 SdkConstants (com.android.SdkConstants)1 ATTR_LAYOUT_RESOURCE_PREFIX (com.android.SdkConstants.ATTR_LAYOUT_RESOURCE_PREFIX)1 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 ID (com.android.resources.ResourceType.ID)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 Configuration (com.android.tools.idea.configurations.Configuration)1 ResolutionUtils (com.android.tools.idea.editors.theme.ResolutionUtils)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 ResourceHelper (com.android.tools.idea.res.ResourceHelper)1 HtmlBuilder (com.android.utils.HtmlBuilder)1