Search in sources :

Example 56 with NlModel

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

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

the class MockupTest method testGetBounds_nullPosition.

public void testGetBounds_nullPosition() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, null, null);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    DesignSurface mockSurface = mock(DesignSurface.class);
    when(mockSurface.getScale()).thenReturn(1.0);
    final ScreenView screenView = new ScreenView(mockSurface, ScreenView.ScreenViewType.BLUEPRINT, model);
    final Rectangle destinationRectangle = mockup.getScreenBounds(screenView);
    assertEquals(new Rectangle(0, 0, component.w, component.h), destinationRectangle);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 58 with NlModel

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

the class MockupTest method testGetCropping_FullImage.

public void testGetCropping_FullImage() {
    final NlModel model = createModel1Mockup(getTestDataPath() + "/" + MOCKUP_PSD, "");
    NlComponent component = model.getComponents().get(0);
    //mockProject, "", "1 2 3 4");
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    final BufferedImage image = mockup.getImage();
    assertNotNull(image);
    assertEquals(new Rectangle(0, 0, image.getWidth(), image.getHeight()), mockup.getCropping());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel) BufferedImage(java.awt.image.BufferedImage)

Example 59 with NlModel

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

the class MockupTest method testFilePathRelative.

public void testFilePathRelative() {
    if (SystemInfo.isWindows) {
        // Do not run tests on Windows (see http://b.android.com/222904)
        return;
    }
    final NlModel model = createModel1Mockup(MOCKUP_PSD, DEFAULT_TEST_POSITION, null);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    assertEquals(model.getProject().getBasePath() + "/" + MOCKUP_PSD, mockup.getFilePath());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 60 with NlModel

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

the class MockupTest method testCreateMockupModelFromCorrectPositionString.

public void testCreateMockupModelFromCorrectPositionString() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "1 2 3 4");
    NlComponent component = model.getComponents().get(0);
    //mockProject, "", "1 2 3 4");
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    assertEquals(new Rectangle(1, 2, 3, 4), mockup.getCropping());
    assertEquals(new Rectangle(0, 0, -1, -1), mockup.getBounds());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) 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