Search in sources :

Example 11 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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 12 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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 13 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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)

Example 14 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty in project android by JetBrains.

the class NlEnumEditorFixture method createListener.

protected static NlEditingListener createListener() {
    NlEditingListener listener = mock(NlEditingListener.class);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NlComponentEditor editor = (NlComponentEditor) args[0];
        Object value = args[1];
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        editor.getProperty().setValue(value);
        return null;
    }).when(listener).stopEditing(any(NlComponentEditor.class), any());
    return listener;
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty)

Example 15 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty in project android by JetBrains.

the class IdInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    IdInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(3);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(4);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        String propertyName = property.getName();
        if (propertyName.equals(ATTR_ID)) {
            propertyName = "ID";
        }
        verify(panel).addComponent(eq(propertyName), eq(null), eq(editor.getComponent()));
    }
    verify(panel, never()).addPanel(inspector.getConstraintPanel());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) IdInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)

Aggregations

NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)25 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)17 Matchers.anyString (org.mockito.Matchers.anyString)12 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)7 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)6 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 TextInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent)3 IdInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)2 HashMap (java.util.HashMap)2 SdkConstants (com.android.SdkConstants)1 ChooseResourceDialog (com.android.tools.idea.ui.resourcechooser.ChooseResourceDialog)1 SwitchHandler (com.android.tools.idea.uibuilder.handlers.SwitchHandler)1 PreferenceUtils (com.android.tools.idea.uibuilder.model.PreferenceUtils)1 PropertyTestCase (com.android.tools.idea.uibuilder.property.PropertyTestCase)1 com.android.tools.idea.uibuilder.property.editors (com.android.tools.idea.uibuilder.property.editors)1 NlBaseComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlBaseComponentEditor)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1