Search in sources :

Example 21 with ModelBuilder

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

the class AbsoluteLayoutHandlerTest method createModel.

@NotNull
private NlModel createModel() {
    ModelBuilder builder = model("absolute.xml", component(ABSOLUTE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(TEXT_VIEW).withBounds(100, 100, 100, 100).id("@id/myText").width("100dp").height("100dp").withAttribute("android:layout_x", "100dp").withAttribute("android:layout_y", "100dp")));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<AbsoluteLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100}", NlTreeDumper.dumpTree(model.getComponents()));
    format(model.getFile());
    assertEquals("<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=\"100dp\"\n" + "        android:layout_y=\"100dp\" />\n" + "\n" + "</AbsoluteLayout>\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 22 with ModelBuilder

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

the class AbsoluteLayoutHandlerTest method testDragToLayout2.

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

Example 23 with ModelBuilder

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

the class MockupTestCase method createModel1Mockup.

protected NlModel createModel1Mockup(@NotNull String mockupFile, @Nullable String mockupPosition, @Nullable String opacity) {
    final ComponentDescriptor root = component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().withAttribute(TOOLS_URI, ATTR_MOCKUP, mockupFile);
    if (mockupPosition != null) {
        root.withAttribute(TOOLS_URI, ATTR_MOCKUP_CROP, mockupPosition);
    }
    if (opacity != null) {
        root.withAttribute(TOOLS_URI, ATTR_MOCKUP_OPACITY, opacity);
    }
    ModelBuilder builder = model("relative.xml", root);
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 24 with ModelBuilder

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

the class NlComponentTreeTest method createModel.

@NotNull
private NlModel createModel() {
    ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(LINEAR_LAYOUT).withBounds(0, 0, 200, 200).wrapContentWidth().wrapContentHeight().children(component(BUTTON).withBounds(0, 0, 100, 100).id("@+id/myButton").width("100dp").height("100dp")), component(TEXT_VIEW).withBounds(0, 200, 100, 100).id("@+id/myText").width("100dp").height("100dp"), component(ABSOLUTE_LAYOUT).withBounds(0, 300, 400, 500).width("400dp").height("500dp")));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<RelativeLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<LinearLayout>, bounds=[0,0:200x200}\n" + "        NlComponent{tag=<Button>, bounds=[0,0:100x100}\n" + "    NlComponent{tag=<TextView>, bounds=[0,200:100x100}\n" + "    NlComponent{tag=<AbsoluteLayout>, bounds=[0,300:400x500}", NlTreeDumper.dumpTree(model.getComponents()));
    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 25 with ModelBuilder

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

the class MockupTestCase method createModel2Mockup.

@NotNull
protected NlModel createModel2Mockup(String mockupFile, @NotNull String mockupPosition) {
    ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().withAttribute(TOOLS_URI, ATTR_MOCKUP, mockupFile).withAttribute(TOOLS_URI, ATTR_MOCKUP_CROP, mockupPosition).children(component(LINEAR_LAYOUT).withBounds(0, 0, 200, 200).wrapContentWidth().wrapContentHeight().withAttribute(TOOLS_URI, ATTR_MOCKUP, mockupFile).withAttribute(TOOLS_URI, ATTR_MOCKUP_CROP, mockupPosition).children(component(BUTTON).withBounds(0, 0, 100, 100).id("@+id/myButton").width("100dp").height("100dp")), component(TEXT_VIEW).withBounds(0, 200, 100, 100).id("@+id/myText").width("100dp").height("100dp"), component(ABSOLUTE_LAYOUT).withBounds(0, 300, 400, 500).width("400dp").height("500dp")));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals(3, model.getComponents().get(0).getChildCount());
    assertEquals("NlComponent{tag=<RelativeLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<LinearLayout>, bounds=[0,0:200x200}\n" + "        NlComponent{tag=<Button>, bounds=[0,0:100x100}\n" + "    NlComponent{tag=<TextView>, bounds=[0,200:100x100}\n" + "    NlComponent{tag=<AbsoluteLayout>, bounds=[0,300:400x500}", NlTreeDumper.dumpTree(model.getComponents()));
    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)

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