Search in sources :

Example 31 with AttributeDefinition

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

the class IdAnalyzerTest method testRelativeLayout.

public void testRelativeLayout() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button2 = findById(model, "button3");
    NlProperty property = new NlPropertyItem(ImmutableList.of(button2), ANDROID_URI, new AttributeDefinition(ATTR_LAYOUT_ALIGN_START));
    IdAnalyzer analyzer = new IdAnalyzer(property);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button4", "button5", "group1"), 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 32 with AttributeDefinition

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

the class IdAnalyzerTest method testButton1.

public void testButton1() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button1 = findById(model, "button1");
    NlProperty labelFor = new NlPropertyItem(ImmutableList.of(button1), ANDROID_URI, new AttributeDefinition(ATTR_LABEL_FOR));
    IdAnalyzer analyzer = new IdAnalyzer(labelFor);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button2", "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 33 with AttributeDefinition

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

the class BrowsePanel method showResourceChooser.

public static ChooseResourceDialog showResourceChooser(@NotNull NlProperty property) {
    Module module = property.getModel().getModule();
    AttributeDefinition definition = property.getDefinition();
    EnumSet<ResourceType> types = getResourceTypes(property.getName(), definition);
    //return new ChooseResourceDialog(module, types, property.getValue(), property.getTag());
    return ChooseResourceDialog.builder().setModule(module).setTypes(types).setCurrentValue(property.getValue()).setTag(property.getTag()).build();
}
Also used : AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceType(com.android.resources.ResourceType) Module(com.intellij.openapi.module.Module)

Example 34 with AttributeDefinition

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

the class AttributeDefinitionEnumSupport method getAllValues.

@Override
@NotNull
public List<ValueWithDisplayString> getAllValues() {
    AttributeDefinition definition = myProperty.getDefinition();
    String[] stringValues = definition != null ? definition.getValues() : ArrayUtil.EMPTY_STRING_ARRAY;
    List<ValueWithDisplayString> values = new ArrayList<>(stringValues.length);
    for (String stringValue : stringValues) {
        values.add(new ValueWithDisplayString(stringValue, stringValue));
    }
    return values;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with AttributeDefinition

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

the class NlReferenceEditor method configureSlider.

private boolean configureSlider() {
    if (myProperty == null) {
        return false;
    }
    AttributeDefinition definition = myProperty.getDefinition();
    if (definition == null || Collections.disjoint(definition.getFormats(), ImmutableList.of(AttributeFormat.Dimension, AttributeFormat.Float))) {
        return false;
    }
    int maximum;
    int value;
    switch(myProperty.getName()) {
        case SdkConstants.ATTR_ELEVATION:
        case SdkConstants.ATTR_CARD_ELEVATION:
            // Range: [0, 24] integer (dp)
            maximum = 24;
            value = getValueInDp(0);
            break;
        case SdkConstants.ATTR_MIN_HEIGHT:
            // Range: [0, 250] integer (dp)
            maximum = 250;
            value = getValueInDp(180);
            break;
        case SdkConstants.ATTR_MOCKUP_OPACITY:
        case SdkConstants.ATTR_COLLAPSE_PARALLAX_MULTIPLIER:
            // Range: [0.0, 1.0] float (no unit)
            maximum = 10;
            value = (int) (getValueAsFloat(1.0) * 10 + 0.5);
            break;
        default:
            return false;
    }
    mySlider.setMinimum(0);
    mySlider.setMaximum(maximum);
    mySlider.setValue(value);
    return true;
}
Also used : 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