use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class MockupTest method testCreateMockup_createWithoutAttribute.
public void testCreateMockup_createWithoutAttribute() {
final NlModel model = createModel0Mockup();
final NlComponent component = model.getComponents().get(0);
assertNotNull(Mockup.create(component, true));
assertNull(Mockup.create(component, false));
}
use of com.android.tools.idea.uibuilder.model.NlModel 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;
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class MockupTest method testCreateMockupModelFromCorrectXYString.
public void testCreateMockupModelFromCorrectXYString() {
final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 1 2");
NlComponent component = model.getComponents().get(0);
//mockProject, "", "1 2");
final Mockup mockup = Mockup.create(component);
assertNotNull(mockup);
assertEquals(new Rectangle(1, 2, -1, -1), mockup.getBounds());
assertEquals(new Rectangle(0, 0, -1, -1), mockup.getCropping());
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class MockupTest method testGetBounds_Normal_Position.
public void testGetBounds_Normal_Position() {
final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 10 10 120 50");
DesignSurface mockSurface = mock(DesignSurface.class);
when(mockSurface.getScale()).thenReturn(1.0);
Configuration configuration = mock(Configuration.class);
when(configuration.getDensity()).thenReturn(Density.DPI_280);
ScreenView screenView = mock(ScreenView.class);
when(screenView.getX()).thenReturn(0);
when(screenView.getY()).thenReturn(0);
when(screenView.getSize()).thenReturn(new Dimension(1000, 2000));
when(screenView.getSize(anyObject())).thenReturn(new Dimension(1000, 2000));
when(screenView.getScale()).thenReturn(2.);
when(screenView.getConfiguration()).thenReturn(configuration);
final Mockup mockup = Mockup.create(model.getComponents().get(0));
assertNotNull(mockup);
assertEquals(new Rectangle(10, 10, 120, 50), mockup.getBounds());
final Rectangle swingBounds = mockup.getScreenBounds(screenView);
assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.x, 2.);
assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.y, 2.);
assertEquals(Coordinates.getSwingDimensionDip(screenView, 110), swingBounds.width, 2.);
assertEquals(Coordinates.getSwingDimensionDip(screenView, 40), swingBounds.height, 2.);
}
use of com.android.tools.idea.uibuilder.model.NlModel 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;
}
Aggregations