Search in sources :

Example 21 with NlModel

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

the class PreferenceScreenDragHandlerLayoutTest method testCommit.

public void testCommit() {
    NlModel model = buildModel();
    NlComponent screen = model.getComponents().get(0);
    List<NlComponent> actualCategoryChildren = screen.getChildren().get(1).getChildren();
    NlComponent preference = new NlComponent(model, NlModel.createTag(myModule.getProject(), "<CheckBoxPreference />"));
    List<NlComponent> expectedCategoryChildren = Arrays.asList(actualCategoryChildren.get(0), preference, actualCategoryChildren.get(1), actualCategoryChildren.get(2));
    DragHandler handler = new PreferenceScreenDragHandler(mockEditor(model), new ViewGroupHandler(), screen, Collections.singletonList(preference), DragType.MOVE);
    handler.update(360, 502, 0);
    handler.commit(360, 502, 0, InsertType.CREATE);
    assertEquals(expectedCategoryChildren, actualCategoryChildren);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 22 with NlModel

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

Example 23 with NlModel

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

the class MockupTest method testGetAllMockup.

public void testGetAllMockup() {
    final NlModel model = createModel2Mockup(MOCKUP_PSD, DEFAULT_TEST_POSITION);
    final List<Mockup> all = Mockup.createAll(model);
    assertNotNull(all);
    assertSize(2, all);
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 24 with NlModel

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

the class DesignSurfaceTest method testRenderWhileBuilding.

public void testRenderWhileBuilding() {
    ModelBuilder modelBuilder = model("absolute.xml", component(ABSOLUTE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component("custom.view.not.present.yet").withBounds(100, 100, 100, 100).matchParentWidth().matchParentHeight()));
    NlModel model = modelBuilder.build();
    // Simulate that we are in the middle of a build
    BuildSettings.getInstance(getProject()).setBuildMode(BuildMode.SOURCE_GEN);
    // Avoid rendering any other components (nav bar and similar) so we do not have dependencies on the Material theme
    model.getConfiguration().setTheme("android:Theme.NoTitleBar.Fullscreen");
    mySurface.setModel(model);
    assertNull(model.getRenderResult());
    mySurface.requestRender();
    assertEquals(1, mySurface.getErrorModel().getIssues().size());
    assertEquals("The project is still building", mySurface.getErrorModel().getIssues().get(0).getSummary());
    // Now finish the build, and try to build again. The "project is still building" should be gone.
    BuildSettings.getInstance(getProject()).setBuildMode(null);
    model = modelBuilder.build();
    model.getConfiguration().setTheme("android:Theme.NoTitleBar.Fullscreen");
    mySurface.setModel(model);
    mySurface.requestRender();
    // Because there is a missing view, some other extra errors will be generated about missing styles. This is caused by
    // MockView (which is based on TextView) that depends on some Material styles.
    // We only care about the missing class error.
    assertTrue(mySurface.getErrorModel().getIssues().stream().anyMatch(issue -> issue.getSummary().startsWith("Missing classes")));
    assertFalse(mySurface.getErrorModel().getIssues().stream().anyMatch(issue -> issue.getSummary().startsWith("The project is still building")));
}
Also used : IdeEventQueue(com.intellij.ide.IdeEventQueue) ABSOLUTE_LAYOUT(com.android.SdkConstants.ABSOLUTE_LAYOUT) ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) BuildMode(com.android.tools.idea.gradle.util.BuildMode) Disposer(com.intellij.openapi.util.Disposer) NlModel(com.android.tools.idea.uibuilder.model.NlModel) BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) LayoutTestCase(com.android.tools.idea.uibuilder.LayoutTestCase) ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 25 with NlModel

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

the class InteractionManagerTest method testDragAndDrop.

public void testDragAndDrop() throws Exception {
    // Drops a fragment (xmlFragment below) into the design surface (via drag & drop events) and verifies that
    // the resulting document ends up modified as expected.
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"0dp\"\n" + "    android:layout_height=\"0dp\"\n" + "    android:orientation=\"vertical\">\n" + "\n" + "</LinearLayout>\n";
    XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
    DesignSurface surface = createSurface();
    NlModel model = createModel(surface, myFacet, xmlFile);
    ScreenView screenView = createScreen(surface, model, new SelectionModel());
    DesignSurface designSurface = screenView.getSurface();
    InteractionManager manager = createManager(designSurface);
    @Language("XML") String xmlFragment = "" + "<TextView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "     android:layout_width=\"wrap_content\"\n" + "     android:layout_height=\"wrap_content\"\n" + "     android:text=\"Hello World\"\n" + "/>";
    Transferable transferable = createTransferable(DataFlavor.stringFlavor, xmlFragment);
    dragDrop(manager, 0, 0, 100, 100, transferable);
    Disposer.dispose(model);
    @Language("XML") String expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"0dp\"\n" + "    android:layout_height=\"0dp\"\n" + "    android:orientation=\"vertical\">\n" + "\n" + "    <TextView\n" + "        android:id=\"@+id/textView\"\n" + "        android:layout_width=\"match_parent\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:text=\"Hello World\" />\n" + "</LinearLayout>\n";
    assertEquals(expected, xmlFile.getText());
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) Transferable(java.awt.datatransfer.Transferable) NlModel(com.android.tools.idea.uibuilder.model.NlModel) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel)

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