Search in sources :

Example 46 with NlComponent

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

the class PreferenceScreenTestFactory method newCheckBoxPreference.

@NotNull
static NlComponent newCheckBoxPreference(int x, int y, int width, int height) {
    NlComponent preference = HandlerTestFactory.newNlComponent(CHECK_BOX_PREFERENCE);
    preference.setBounds(x, y, width, height);
    return preference;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with NlComponent

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

the class GroupDragHandlerTest method updateUsingOverflowGroup.

@Test
public void updateUsingOverflowGroup() {
    NlComponent menu = newMenu(366, 162, 392, 288);
    menu.addChild(newOverflowItem(366, 162, 392, 96));
    menu.addChild(newOverflowItem(366, 258, 392, 96));
    menu.addChild(newOverflowItem(366, 354, 392, 96));
    GroupDragHandler handler = newGroupDragHandler(menu);
    int y = 90;
    y += 48;
    handler.update(0, y, 0);
    assertEquals(0, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(0, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(2, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(2, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(-1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(-1, handler.getInsertIndex());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Test(org.junit.Test)

Example 48 with NlComponent

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

the class ActionBarTest method addToItemsOrOverflowItemsItemViewTypeIsActionBarMenu.

@Test
public void addToItemsOrOverflowItemsItemViewTypeIsActionBarMenu() {
    NlComponent item = HandlerTestFactory.newNlComponent("item");
    item.viewInfo = MenuTestFactory.mockViewInfo(ViewType.ACTION_BAR_MENU);
    NlComponent menu = HandlerTestFactory.newNlComponent("menu");
    menu.addChild(item);
    ActionBar actionBar = new ActionBar(menu);
    assertEquals(Collections.singletonList(item), actionBar.getItems());
    assertEquals(Collections.emptyList(), actionBar.getOverflowItems());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Test(org.junit.Test)

Example 49 with NlComponent

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

the class GridDragHandlerTest method testCommit.

public void testCommit() {
    handler.start(630, 210, 0);
    handler.update(470, 210, 0);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        handler.commit(470, 210, 0, InsertType.MOVE_INTO);
    });
    NlComponent[][] children = handler.getInfo().getChildren();
    NlComponent child = children[handler.getStartRow()][handler.getStartColumn()];
    assertEquals("0", child.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_ROW));
    assertEquals("1", child.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_COLUMN));
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 50 with NlComponent

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

the class GridDragHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    GridLayout viewObject = new GridLayout();
    viewObject.setVerticalAxis(new Axis(new int[] { 0, 1024 }));
    viewObject.setHorizontalAxis(new Axis(new int[] { 0, 248, 248, 248, 248, 248, 248, 248, 248, 520, 768 }));
    viewObject.setRowCount(1);
    viewObject.setColumnCount(10);
    // @formatter:off
    ComponentDescriptor button1 = component(SdkConstants.BUTTON).withBounds(0, 160, 248, 96).withAttribute("android:layout_row", "0").withAttribute("android:layout_column", "0").layoutParamsObject(new LayoutParams(new Spec(new Interval(0, 1)), new Spec(new Interval(0, 1))));
    ComponentDescriptor button2 = component(SdkConstants.BUTTON).withBounds(520, 160, 248, 96).withAttribute("android:layout_row", "0").withAttribute("android:layout_column", "9").layoutParamsObject(new LayoutParams(new Spec(new Interval(0, 1)), new Spec(new Interval(9, 10))));
    ComponentDescriptor layout = component(SdkConstants.GRID_LAYOUT).withBounds(0, 160, 768, 1024).viewObject(viewObject).children(button1, button2);
    NlModel model = model("grid_layout.xml", layout).build();
    // @formatter:on
    ViewEditor editor = Mockito.mock(ViewEditor.class);
    Mockito.when(editor.getModel()).thenReturn(model);
    List<NlComponent> components = Collections.emptyList();
    handler = new GridDragHandler(editor, new ViewGroupHandler(), model.getComponents().get(0), components, DragType.CREATE);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) NlModel(com.android.tools.idea.uibuilder.model.NlModel) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

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