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