Search in sources :

Example 6 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class NlModelTest method testRemoveLastChild.

public void testRemoveLastChild() throws Exception {
    ModelBuilder modelBuilder = createDefaultModelBuilder(false);
    NlModel model = modelBuilder.build();
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
    // Remove last child
    ComponentDescriptor parent = modelBuilder.findByPath(LINEAR_LAYOUT);
    assertThat(parent).isNotNull();
    parent.removeChild(modelBuilder.findByPath(LINEAR_LAYOUT, BUTTON));
    modelBuilder.updateModel(model, false);
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}", myTreeDumper.toTree(model.getComponents()));
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)

Example 7 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class RelativeLayoutHandlerTest method createModel.

@NotNull
private NlModel createModel() {
    ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(BUTTON).withBounds(100, 100, 100, 100).id("@id/button").width("100dp").height("100dp").withAttribute("android:layout_alignParentTop", "true").withAttribute("android:layout_alignParentLeft", "true").withAttribute("android:layout_alignParentStart", "true").withAttribute("android:layout_marginTop", "100dp").withAttribute("android:layout_marginLeft", "100dp").withAttribute("android:layout_marginStart", "100dp"), component(CHECK_BOX).withBounds(300, 300, 20, 20).viewObject(mockViewWithBaseline(17)).id("@id/checkbox").width("20dp").height("20dp").withAttribute("android:layout_below", "@id/button").withAttribute("android:layout_toRightOf", "@id/button").withAttribute("android:layout_marginLeft", "100dp").withAttribute("android:layout_marginTop", "100dp"), component(TEXT_VIEW).withBounds(400, 400, 100, 100).viewObject(mockViewWithBaseline(70)).id("@id/textView").width("100dp").height("100dp").withAttribute("android:layout_below", "@id/checkbox").withAttribute("android:layout_toRightOf", "@id/checkbox").withAttribute("android:layout_marginLeft", "80dp").withAttribute("android:layout_marginTop", "80dp")));
    NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<RelativeLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<Button>, bounds=[100,100:100x100}\n" + "    NlComponent{tag=<CheckBox>, bounds=[300,300:20x20}\n" + "    NlComponent{tag=<TextView>, bounds=[400,400:100x100}", NlTreeDumper.dumpTree(model.getComponents()));
    format(model.getFile());
    assertEquals("<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"match_parent\"\n" + "    android:layout_height=\"match_parent\">\n" + "\n" + "    <Button\n" + "        android:id=\"@id/button\"\n" + "        android:layout_width=\"100dp\"\n" + "        android:layout_height=\"100dp\"\n" + "        android:layout_alignParentTop=\"true\"\n" + "        android:layout_alignParentLeft=\"true\"\n" + "        android:layout_alignParentStart=\"true\"\n" + "        android:layout_marginTop=\"100dp\"\n" + "        android:layout_marginLeft=\"100dp\"\n" + "        android:layout_marginStart=\"100dp\" />\n" + "\n" + "    <CheckBox\n" + "        android:id=\"@id/checkbox\"\n" + "        android:layout_width=\"20dp\"\n" + "        android:layout_height=\"20dp\"\n" + "        android:layout_below=\"@id/button\"\n" + "        android:layout_toRightOf=\"@id/button\"\n" + "        android:layout_marginLeft=\"100dp\"\n" + "        android:layout_marginTop=\"100dp\" />\n" + "\n" + "    <TextView\n" + "        android:id=\"@id/textView\"\n" + "        android:layout_width=\"100dp\"\n" + "        android:layout_height=\"100dp\"\n" + "        android:layout_below=\"@id/checkbox\"\n" + "        android:layout_toRightOf=\"@id/checkbox\"\n" + "        android:layout_marginLeft=\"80dp\"\n" + "        android:layout_marginTop=\"80dp\" />\n" + "\n" + "</RelativeLayout>\n", model.getFile().getText());
    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 8 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder 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 9 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class MockupTestCase method createModel0Mockup.

protected NlModel createModel0Mockup() {
    ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight());
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 10 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class AbsoluteLayoutHandlerTest method testDragToLayout.

public void testDragToLayout() throws Exception {
    // Drag from one layout to another
    ModelBuilder builder = model("absolute2.xml", component(LINEAR_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().withAttribute(ANDROID_URI, ATTR_ORIENTATION, VALUE_VERTICAL).children(component(TEXT_VIEW).withBounds(0, 0, 1000, 150).id("@id/myText").width("100dp").height("100dp").withAttribute("android:layout_x", "100dp").withAttribute("android:layout_y", "100dp"), component(ABSOLUTE_LAYOUT).withBounds(0, 150, 1000, 850).id("myAbsLayout").matchParentWidth().matchParentHeight()));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<TextView>, bounds=[0,0:1000x150}\n" + "    NlComponent{tag=<AbsoluteLayout>, bounds=[0,150:1000x850}", NlTreeDumper.dumpTree(model.getComponents()));
    surface().screen(createModel()).get("@id/myText").drag().drag(50, // into AbsoluteLayout child
    300).release().primary().parent().expectXml("<AbsoluteLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"match_parent\"\n" + "    android:layout_height=\"match_parent\">\n" + "\n" + "    <TextView\n" + "        android:id=\"@id/myText\"\n" + "        android:layout_width=\"100dp\"\n" + "        android:layout_height=\"100dp\"\n" + "        android:layout_x=\"150dp\"\n" + "        android:layout_y=\"400dp\" />\n" + "\n" + "</AbsoluteLayout>");
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Aggregations

ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)29 NlModel (com.android.tools.idea.uibuilder.model.NlModel)19 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)12 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)6 NotNull (org.jetbrains.annotations.NotNull)6 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 ABSOLUTE_LAYOUT (com.android.SdkConstants.ABSOLUTE_LAYOUT)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 Configuration (com.android.tools.idea.configurations.Configuration)1 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 TagSnapshot (com.android.tools.idea.rendering.TagSnapshot)1 LayoutTestCase (com.android.tools.idea.uibuilder.LayoutTestCase)1 IdeEventQueue (com.intellij.ide.IdeEventQueue)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1