use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class SceneCreationTest method testSceneCreation.
public void testSceneCreation() {
ModelBuilder builder = createModel();
NlModel model = builder.build();
Scene scene = Scene.createScene(model, myScreen.getScreen());
scene.setDpiFactorOverride(1);
scene.setAnimate(false);
assertEquals(scene.getRoot().getChildren().size(), 1);
ComponentDescriptor parent = builder.findByPath(CONSTRAINT_LAYOUT);
ComponentDescriptor textView = builder.findByPath(CONSTRAINT_LAYOUT, TEXT_VIEW);
ComponentDescriptor editText = parent.addChild(component(EDIT_TEXT).withBounds(110, 220, 200, 30).width("200dp").height("30dp"), textView);
builder.updateModel(model, false);
scene.updateFrom(model);
assertEquals(2, scene.getRoot().getChildren().size());
List<SceneComponent> children = scene.getRoot().getChildren();
SceneComponent sceneTextView = children.get(0);
assertEquals(100, sceneTextView.getDrawX());
assertEquals(200, sceneTextView.getDrawY());
assertEquals(100, sceneTextView.getDrawWidth());
assertEquals(20, sceneTextView.getDrawHeight());
SceneComponent sceneEditText = children.get(1);
assertEquals(110, sceneEditText.getDrawX());
assertEquals(220, sceneEditText.getDrawY());
assertEquals(200, sceneEditText.getDrawWidth());
assertEquals(30, sceneEditText.getDrawHeight());
parent.removeChild(textView);
builder.updateModel(model, false);
scene.updateFrom(model);
assertEquals(1, scene.getRoot().getChildren().size());
sceneTextView = scene.getRoot().getChildren().get(0);
assertEquals(110, sceneTextView.getDrawX());
assertEquals(220, sceneTextView.getDrawY());
assertEquals(200, sceneTextView.getDrawWidth());
assertEquals(30, sceneTextView.getDrawHeight());
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class SceneCreationTest method testSceneReparenting.
public void testSceneReparenting() {
ModelBuilder builder = createModel();
NlModel model = builder.build();
Scene scene = Scene.createScene(model, myScreen.getScreen());
scene.setDpiFactorOverride(1);
scene.setAnimate(false);
assertEquals(scene.getRoot().getChildren().size(), 1);
ComponentDescriptor parent = builder.findByPath(CONSTRAINT_LAYOUT);
parent.addChild(component(CONSTRAINT_LAYOUT).id("@id/layout").withBounds(200, 300, 200, 200).width("200dp").height("200dp"), null);
builder.updateModel(model, false);
scene.updateFrom(model);
assertEquals(2, scene.getRoot().getChildren().size());
NlComponent textView = scene.getRoot().getChild(0).getNlComponent();
NlComponent container = scene.getRoot().getChild(1).getNlComponent();
scene.getRoot().getNlComponent().removeChild(textView);
container.addChild(textView);
scene.updateFrom(model);
assertEquals(1, scene.getRoot().getChildCount());
SceneComponent layout = scene.getSceneComponent("layout");
assertEquals(1, layout.getChildCount());
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class IdAnalyzerTest method testConstraintLayout.
public void testConstraintLayout() {
ModelBuilder modelBuilder = createConstraintLayout();
NlModel model = modelBuilder.build();
NlComponent button2 = findById(model, "button3");
NlProperty property = new NlPropertyItem(ImmutableList.of(button2), AUTO_URI, new AttributeDefinition(ATTR_LAYOUT_TOP_TO_TOP_OF));
IdAnalyzer analyzer = new IdAnalyzer(property);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button4", "button5"), ids);
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class IdAnalyzerTest method testRelativeLayout.
public void testRelativeLayout() {
ModelBuilder modelBuilder = createRelativeLayout();
NlModel model = modelBuilder.build();
NlComponent button2 = findById(model, "button3");
NlProperty property = new NlPropertyItem(ImmutableList.of(button2), ANDROID_URI, new AttributeDefinition(ATTR_LAYOUT_ALIGN_START));
IdAnalyzer analyzer = new IdAnalyzer(property);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button4", "button5", "group1"), ids);
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class IdAnalyzerTest method testButton1.
public void testButton1() {
ModelBuilder modelBuilder = createRelativeLayout();
NlModel model = modelBuilder.build();
NlComponent button1 = findById(model, "button1");
NlProperty labelFor = new NlPropertyItem(ImmutableList.of(button1), ANDROID_URI, new AttributeDefinition(ATTR_LABEL_FOR));
IdAnalyzer analyzer = new IdAnalyzer(labelFor);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button2", "button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
Aggregations