Search in sources :

Example 21 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class NlPropertyOrderingTest method testSorting.

public void testSorting() {
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + "  <TextView android:text=\"Hello\" />" + "</RelativeLayout>";
    NlComponent component = getFirstComponent(source);
    Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(component));
    List<NlPropertyItem> propertyList = new ArrayList<>(properties.values());
    List<NlPropertyItem> sortedList = new NlPropertiesSorter().sort(propertyList, ImmutableList.of(component));
    List<PTableItem> items = new NlPropertiesGrouper().group(sortedList, ImmutableList.of(component));
    assertEquals("id attribute is not the first item", "id", items.get(0).getName());
    assertEquals("Layout_width attribute is not the second item", "layout_width", items.get(1).getName());
    assertEquals("Layout_height attribute is not the third item", "layout_height", items.get(2).getName());
    assertEquals("Layout attributes group is not the fourth item", "Layout_Margin", items.get(3).getName());
    assertEquals("Padding attributes group is not the fifth item", "Padding", items.get(4).getName());
    assertTrue("TextView group not within the top 10 items", findItemIndex(items, "TextView") < 10);
    assertTrue("Modified attribute text not in the top 10 items", findItemIndex(items, "text") < 10);
}
Also used : Language(org.intellij.lang.annotations.Language) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ArrayList(java.util.ArrayList) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Example 22 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class PropertyTestCase method createFrom.

@NotNull
protected NlPropertyItem createFrom(@NotNull NlComponent component, @NotNull String attributeName) {
    List<NlComponent> components = ImmutableList.of(component);
    XmlAttributeDescriptor descriptor = getDescriptor(component, attributeName);
    assertThat(descriptor).isNotNull();
    AttributeDefinition definition = getDefinition(component, descriptor);
    String namespace = getNamespace(component, descriptor);
    return NlPropertyItem.create(components, descriptor, namespace, definition);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class PaletteTestCase method assertHorizontalProgressBarItem.

public void assertHorizontalProgressBarItem(@NotNull Palette.BaseItem item) {
    checkItem(item, "ProgressBar", "ProgressBar (Horizontal)", AndroidIcons.Views.ProgressBarHorizontal, HORIZONTAL_PROGRESS_XML, HORIZONTAL_PROGRESS_PREVIEW_XML, HORIZONTAL_PROGRESS_XML, IN_PLATFORM, 2.0);
    NlComponent component = createMockComponent("ProgressBar");
    when(component.getAttribute(null, TAG_STYLE)).thenReturn(ANDROID_STYLE_RESOURCE_PREFIX + "Widget.ProgressBar.Horizontal");
    checkComponent(component, "ProgressBar (Horizontal)", AndroidIcons.Views.ProgressBar);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 24 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class PaletteTestCase method assertDiscreteSeekBar.

public void assertDiscreteSeekBar(@NotNull Palette.BaseItem item) {
    checkItem(item, "SeekBar", "SeekBar (Discrete)", AndroidIcons.Views.SeekBar, DISCRETE_SEEKBAR_XML, DISCRETE_SEEKBAR_PREVIEW_XML, DISCRETE_SEEKBAR_XML, IN_PLATFORM, 1.0);
    NlComponent component = createMockComponent("SeekBar");
    when(component.getAttribute(null, TAG_STYLE)).thenReturn(ANDROID_STYLE_RESOURCE_PREFIX + "Widget.Material.SeekBar.Discrete");
    checkComponent(component, "SeekBar", AndroidIcons.Views.SeekBar);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 25 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class PaletteTestCase method assertVerticalLinearLayoutItem.

public void assertVerticalLinearLayoutItem(@NotNull Palette.BaseItem item) {
    checkItem(item, LINEAR_LAYOUT, "LinearLayout (vertical)", AndroidIcons.Views.VerticalLinearLayout, VERTICAL_LINEAR_LAYOUT_XML, NO_PREVIEW, NO_PREVIEW, IN_PLATFORM, NO_SCALE);
    NlComponent component = createMockComponent(LINEAR_LAYOUT);
    when(component.getAttribute(ANDROID_URI, ATTR_ORIENTATION)).thenReturn(VALUE_VERTICAL);
    checkComponent(component, "LinearLayout (vertical)", AndroidIcons.Views.VerticalLinearLayout);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6