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);
}
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>");
}
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);
}
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")));
}
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());
}
Aggregations