Search in sources :

Example 66 with NlModel

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

the class DesignSurfaceTest method testEmptyRenderSuccess.

public void testEmptyRenderSuccess() {
    NlModel model = model("absolute.xml", component(ABSOLUTE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight()).build();
    // 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();
    assertTrue(model.getRenderResult().getRenderResult().isSuccess());
    assertTrue(mySurface.getErrorModel().getIssues().isEmpty());
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 67 with NlModel

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

the class DesignSurfaceTest method ScreenPositioning.

// https://code.google.com/p/android/issues/detail?id=227931
public void ScreenPositioning() {
    mySurface.addNotify();
    mySurface.setBounds(0, 0, 400, 4000);
    mySurface.validate();
    // Process the resize events
    IdeEventQueue.getInstance().flushQueue();
    NlModel model = model("absolute.xml", component(ABSOLUTE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight()).build();
    // 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.setScreenMode(DesignSurface.ScreenMode.SCREEN_ONLY, false);
    mySurface.requestRender();
    assertTrue(model.getRenderResult().getRenderResult().isSuccess());
    assertNotNull(mySurface.getCurrentScreenView());
    assertNull(mySurface.getBlueprintView());
    mySurface.setScreenMode(DesignSurface.ScreenMode.BOTH, false);
    mySurface.requestRender();
    assertTrue(model.getRenderResult().getRenderResult().isSuccess());
    ScreenView screenView = mySurface.getCurrentScreenView();
    ScreenView blueprintView = mySurface.getBlueprintView();
    assertNotNull(screenView);
    assertNotNull(blueprintView);
    assertTrue(screenView.getY() < blueprintView.getY());
    mySurface.setBounds(0, 0, 4000, 400);
    mySurface.validate();
    IdeEventQueue.getInstance().flushQueue();
    // Horizontal stack
    assertTrue(screenView.getY() == blueprintView.getY());
    mySurface.removeNotify();
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 68 with NlModel

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

the class DeleteAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView == null) {
        return;
    }
    SelectionModel selectionModel = screenView.getSelectionModel();
    NlModel model = screenView.getModel();
    model.delete(selectionModel.getSelection());
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 69 with NlModel

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

the class GenerateLayoutTestSkeletonAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
    NlModel model = getModel(event.getProject());
    if (model == null) {
        return;
    }
    int option = Messages.showDialog(model.getProject(), "Generate LayoutTest skeleton with the current layout components.", "Generate LayoutTest Skeleton", new String[] { "Copy to Clipboard", "Cancel" }, 0, AndroidIcons.AndroidTestRoot);
    if (option == 0) {
        CopyPasteManager.getInstance().setContents(new StringSelection(generateModelFixture(model)));
    }
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel) StringSelection(java.awt.datatransfer.StringSelection)

Example 70 with NlModel

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

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