Search in sources :

Example 11 with NlModel

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

the class LinearLayoutHandlerTest method createModel.

@NotNull
private NlModel createModel() {
    ModelBuilder builder = model("linear.xml", component(LINEAR_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(TEXT_VIEW).withBounds(100, 100, 100, 100).id("@id/myText1").width("100dp").height("100dp"), component(BUTTON).withBounds(100, 200, 100, 100).id("@id/myText2").width("100dp").height("100dp").withAttribute("android:layout_weight", "1.0")));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100}", NlTreeDumper.dumpTree(model.getComponents()));
    format(model.getFile());
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with NlModel

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

Example 13 with NlModel

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

the class MockupTest method testSetAlphaString.

public void testSetAlphaString() {
    NlModel model = createModel1Mockup(MOCKUP_PSD, DEFAULT_TEST_POSITION);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    assertEquals(Mockup.DEFAULT_OPACITY, mockup.getAlpha());
    mockup.setAlpha("0.9");
    assertEquals(0.9f, mockup.getAlpha());
    mockup.setAlpha("2.9");
    assertEquals(Mockup.DEFAULT_OPACITY_IF_ERROR, mockup.getAlpha());
    mockup.setAlpha("-2.9");
    assertEquals(Mockup.DEFAULT_OPACITY_IF_ERROR, mockup.getAlpha());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 14 with NlModel

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

the class MockupTest method testCreateMockupLayerEmptyStringPosition.

public void testCreateMockupLayerEmptyStringPosition() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "");
    NlComponent component = model.getComponents().get(0).getRoot();
    final Mockup mockup = Mockup.create(component);
    assertNotNull("Model creation", mockup);
    assertEquals(new Rectangle(0, 0, -1, -1), mockup.getBounds());
    assertEquals(new Rectangle(0, 0, -1, -1), mockup.getCropping());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 15 with NlModel

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

the class MockupTest method testGetAllMockupNoMockup.

public void testGetAllMockupNoMockup() {
    final NlModel model = createModel0Mockup();
    final List<Mockup> all = Mockup.createAll(model);
    assertNotNull(all);
    assertSize(0, all);
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Aggregations

NlModel (com.android.tools.idea.uibuilder.model.NlModel)71 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)33 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)19 NotNull (org.jetbrains.annotations.NotNull)18 XmlFile (com.intellij.psi.xml.XmlFile)14 Project (com.intellij.openapi.project.Project)12 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)11 Result (com.intellij.openapi.application.Result)11 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)11 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)6 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)5 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)5 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)5 Configuration (com.android.tools.idea.configurations.Configuration)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)2 XmlTag (com.intellij.psi.xml.XmlTag)2 BufferedImage (java.awt.image.BufferedImage)2