Search in sources :

Example 6 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class CoordinatesTest method testAndroidToSwing.

public void testAndroidToSwing() {
    ScreenView screenView = createScreenView(0.5, 100, 110);
    assertEquals(100, Coordinates.getSwingX(screenView, 0));
    assertEquals(110, Coordinates.getSwingY(screenView, 0));
    assertEquals(100 + 500, Coordinates.getSwingX(screenView, 1000));
    assertEquals(110 + 500, Coordinates.getSwingY(screenView, 1000));
    assertEquals(500, Coordinates.getSwingDimension(screenView, 1000));
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView)

Example 7 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class CoordinatesTest method createScreenView.

private static ScreenView createScreenView(double scale, @SwingCoordinate int x, @SwingCoordinate int y) {
    ScreenView screenView = mock(ScreenView.class);
    when(screenView.getScale()).thenReturn(scale);
    when(screenView.getX()).thenReturn(x);
    when(screenView.getY()).thenReturn(y);
    return screenView;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView)

Example 8 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class NlComponentFixture method getMidPoint.

/** Returns the center point in panel coordinates */
@NotNull
private Point getMidPoint() {
    ScreenView screenView = mySurface.getCurrentScreenView();
    int midX = Coordinates.getSwingX(screenView, myComponent.x + myComponent.w / 2);
    int midY = Coordinates.getSwingY(screenView, myComponent.y + myComponent.h / 2);
    return new Point(midX, midY);
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class NlEditorFixture method startResizeInteraction.

/**
   * Moves the mouse to the resize corner of the screen view, and presses the left mouse button.
   * That starts the canvas resize interaction.
   *
   * @see #resizeToAndroidSize(int, int)
   * @see #endResizeInteraction()
   */
public NlEditorFixture startResizeInteraction() {
    DesignSurface surface = myDesignSurfaceFixture.target();
    ScreenView screenView = surface.getCurrentScreenView();
    Dimension size = screenView.getSize();
    robot().pressMouse(surface, new Point(screenView.getX() + size.width + 24, screenView.getY() + size.height + 24));
    return this;
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView)

Example 10 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class DesignSurfaceFixture method findView.

/**
   * Searches for the nth occurrence of a given view in the layout. The ordering of widgets of the same
   * type is by visual order, first vertically, then horizontally (and finally by XML source offset, if they exactly overlap
   * as for example would happen in a {@code <merge>}
   *
   * @param tag the view tag to search for, e.g. "Button" or "TextView"
   * @param occurrence the index of the occurrence of the tag, e.g. 0 for the first TextView in the layout
   */
@NotNull
public NlComponentFixture findView(@NotNull final String tag, int occurrence) {
    waitForRenderToFinish();
    ScreenView screenView = target().getCurrentScreenView();
    assertNotNull(screenView);
    final NlModel model = screenView.getModel();
    final java.util.List<NlComponent> components = Lists.newArrayList();
    model.getComponents().forEach(component -> addComponents(tag, component, components));
    // Sort by visual order
    components.sort((component1, component2) -> {
        int delta = component1.y - component2.y;
        if (delta != -1) {
            return delta;
        }
        delta = component1.x - component2.x;
        if (delta != -1) {
            return delta;
        }
        // Unlikely
        return component1.getTag().getTextOffset() - component2.getTag().getTextOffset();
    });
    assertTrue("Only " + components.size() + " found, not enough for occurrence #" + occurrence, components.size() > occurrence);
    NlComponent component = components.get(occurrence);
    return createComponentFixture(component);
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)42 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)16 NlModel (com.android.tools.idea.uibuilder.model.NlModel)6 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)6 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)6 Nullable (org.jetbrains.annotations.Nullable)5 NotNull (org.jetbrains.annotations.NotNull)4 Configuration (com.android.tools.idea.configurations.Configuration)3 LintAnnotationsModel (com.android.tools.idea.uibuilder.lint.LintAnnotationsModel)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 BufferedImage (java.awt.image.BufferedImage)2 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 GradleDependencyManager (com.android.tools.idea.gradle.dependencies.GradleDependencyManager)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 InsertType (com.android.tools.idea.uibuilder.api.InsertType)1 ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)1 ViewHandler (com.android.tools.idea.uibuilder.api.ViewHandler)1 ViewEditorImpl (com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)1 LintNotificationPanel (com.android.tools.idea.uibuilder.lint.LintNotificationPanel)1