Search in sources :

Example 6 with ComponentDescriptor

use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.

the class GridDragHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    GridLayout viewObject = new GridLayout();
    viewObject.setVerticalAxis(new Axis(new int[] { 0, 1024 }));
    viewObject.setHorizontalAxis(new Axis(new int[] { 0, 248, 248, 248, 248, 248, 248, 248, 248, 520, 768 }));
    viewObject.setRowCount(1);
    viewObject.setColumnCount(10);
    // @formatter:off
    ComponentDescriptor button1 = component(SdkConstants.BUTTON).withBounds(0, 160, 248, 96).withAttribute("android:layout_row", "0").withAttribute("android:layout_column", "0").layoutParamsObject(new LayoutParams(new Spec(new Interval(0, 1)), new Spec(new Interval(0, 1))));
    ComponentDescriptor button2 = component(SdkConstants.BUTTON).withBounds(520, 160, 248, 96).withAttribute("android:layout_row", "0").withAttribute("android:layout_column", "9").layoutParamsObject(new LayoutParams(new Spec(new Interval(0, 1)), new Spec(new Interval(9, 10))));
    ComponentDescriptor layout = component(SdkConstants.GRID_LAYOUT).withBounds(0, 160, 768, 1024).viewObject(viewObject).children(button1, button2);
    NlModel model = model("grid_layout.xml", layout).build();
    // @formatter:on
    ViewEditor editor = Mockito.mock(ViewEditor.class);
    Mockito.when(editor.getModel()).thenReturn(model);
    List<NlComponent> components = Collections.emptyList();
    handler = new GridDragHandler(editor, new ViewGroupHandler(), model.getComponents().get(0), components, DragType.CREATE);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) NlModel(com.android.tools.idea.uibuilder.model.NlModel) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

Example 7 with ComponentDescriptor

use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.

the class GroupDragHandlerLayoutTest method testCommitConsecutiveOrders.

public void testCommitConsecutiveOrders() {
    ComponentDescriptor menuDescriptor = component(TAG_MENU).withBounds(576, 58, 192, 96).children(item(2, 672), item(1, 576));
    NlComponent menuComponent = model("menu.xml", menuDescriptor).build().getComponents().get(0);
    NlComponent item = Mockito.mock(NlComponent.class);
    DragHandler handler = newGroupDragHandler(menuComponent, item);
    handler.update(700, 100, 0);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> handler.commit(700, 100, 0, InsertType.MOVE_INTO));
    Iterator<NlComponent> i = menuComponent.getChildren().iterator();
    assertEquals("3", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
    assertEquals("1", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
    Mockito.verify(item).setAndroidAttribute(ATTR_ORDER_IN_CATEGORY, "2");
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)

Example 8 with ComponentDescriptor

use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.

the class SceneCreationTest method testDeviceChange.

public void testDeviceChange() {
    ModelBuilder builder = createModel();
    NlModel model = builder.build();
    Configuration config = model.getConfiguration();
    config.setDevice(config.getConfigurationManager().getDeviceById("Nexus 6P"), false);
    Scene scene = Scene.createScene(model, myScreen.getScreen());
    scene.setAnimate(false);
    ComponentDescriptor parent = builder.findByPath(CONSTRAINT_LAYOUT);
    ComponentDescriptor textView = builder.findByPath(CONSTRAINT_LAYOUT, TEXT_VIEW);
    SceneComponent sceneTextView = scene.getRoot().getChildren().get(0);
    float dpiFactor = 560 / 160f;
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawX());
    assertEquals(pxToDp(200, dpiFactor), sceneTextView.getDrawY());
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawWidth());
    assertEquals(pxToDp(20, dpiFactor), sceneTextView.getDrawHeight());
    config.setDevice(config.getConfigurationManager().getDeviceById("Nexus S"), false);
    dpiFactor = 240 / 160f;
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawX());
    assertEquals(pxToDp(200, dpiFactor), sceneTextView.getDrawY());
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawWidth());
    assertEquals(pxToDp(20, dpiFactor), sceneTextView.getDrawHeight());
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) Configuration(com.android.tools.idea.configurations.Configuration) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 9 with ComponentDescriptor

use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor 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());
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 10 with ComponentDescriptor

use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.

the class NlModelTest method testChangeSingleProperty.

@SuppressWarnings("ConstantConditions")
public void testChangeSingleProperty() throws Exception {
    boolean preserveXmlTags = false;
    boolean includeIds = false;
    ModelBuilder modelBuilder = createDefaultModelBuilder(includeIds);
    NlModel model = modelBuilder.build();
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
    // Change a single attribute in an element without id's.
    ComponentDescriptor layout = modelBuilder.findByPath(LINEAR_LAYOUT);
    assertThat(layout).isNotNull();
    layout.withAttribute("style", "@style/Foo");
    modelBuilder.updateModel(model, preserveXmlTags);
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)

Aggregations

ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)16 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)12 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 Configuration (com.android.tools.idea.configurations.Configuration)1 ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)1 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)1