Search in sources :

Example 11 with DesignSurface

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

the class NlEditorFixture method resizeToAndroidSize.

/**
   * Moves the mouse to resize the screen view to correspond to a device of size {@code (width, height)}, expressed in dp
   *
   * @see #startResizeInteraction()
   * @see #endResizeInteraction()
   */
public NlEditorFixture resizeToAndroidSize(@AndroidDpCoordinate int width, @AndroidDpCoordinate int height) {
    DesignSurface surface = myDesignSurfaceFixture.target();
    ScreenView screenView = surface.getCurrentScreenView();
    robot().moveMouse(surface, Coordinates.getSwingXDip(screenView, width), Coordinates.getSwingYDip(screenView, height));
    return this;
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView)

Example 12 with DesignSurface

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

the class ResizeFixture method releaseKey.

public ResizeFixture releaseKey(@MagicConstant(flagsFromClass = KeyEvent.class) int keyCode, char keyChar) {
    if (keyCode == KeyEvent.VK_SHIFT) {
        myModifiers |= InputEvent.SHIFT_MASK;
    }
    if (keyCode == KeyEvent.VK_META) {
        myModifiers |= InputEvent.META_MASK;
    }
    if (keyCode == KeyEvent.VK_CONTROL) {
        myModifiers |= InputEvent.CTRL_MASK;
    }
    if (keyCode == KeyEvent.VK_ALT) {
        myModifiers |= InputEvent.ALT_MASK;
    }
    DesignSurface surface = myScreen.getSurface();
    KeyEvent event = new KeyEventBuilder(keyCode, keyChar).withSource(surface).build();
    myInteraction.keyReleased(event);
    return this;
}
Also used : KeyEvent(java.awt.event.KeyEvent) DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface)

Example 13 with DesignSurface

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

the class MockupTest method testGetBounds_nullPosition.

public void testGetBounds_nullPosition() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, null, null);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    DesignSurface mockSurface = mock(DesignSurface.class);
    when(mockSurface.getScale()).thenReturn(1.0);
    final ScreenView screenView = new ScreenView(mockSurface, ScreenView.ScreenViewType.BLUEPRINT, model);
    final Rectangle destinationRectangle = mockup.getScreenBounds(screenView);
    assertEquals(new Rectangle(0, 0, component.w, component.h), destinationRectangle);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 14 with DesignSurface

use of com.android.tools.idea.uibuilder.surface.DesignSurface 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.);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Configuration(com.android.tools.idea.configurations.Configuration) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 15 with DesignSurface

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

the class GenerateLayoutTestSkeletonAction method getModel.

@Nullable
private static NlModel getModel(@Nullable Project project) {
    if (project == null) {
        return null;
    }
    DesignSurface surface = getSurface(project);
    if (surface == null) {
        return null;
    }
    ScreenView screenView = surface.getCurrentScreenView();
    if (screenView == null) {
        return null;
    }
    return screenView.getModel();
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)17 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)7 Configuration (com.android.tools.idea.configurations.Configuration)4 KeyEvent (java.awt.event.KeyEvent)4 NlModel (com.android.tools.idea.uibuilder.model.NlModel)3 UsageTracker (com.android.tools.analytics.UsageTracker)2 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2 AndroidStudioEvent (com.google.wireless.android.sdk.stats.AndroidStudioEvent)2 LinkedList (java.util.LinkedList)2 Result (com.android.ide.common.rendering.api.Result)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)1 RenderLogger (com.android.tools.idea.rendering.RenderLogger)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 LayoutEditorRenderResult (com.google.wireless.android.sdk.stats.LayoutEditorRenderResult)1 LayoutEditorState (com.google.wireless.android.sdk.stats.LayoutEditorState)1 MockModule (com.intellij.mock.MockModule)1 CopyPasteManager (com.intellij.openapi.ide.CopyPasteManager)1 BufferedImage (java.awt.image.BufferedImage)1 Nullable (org.jetbrains.annotations.Nullable)1