use of com.android.tools.idea.uibuilder.model.AndroidCoordinate in project android by JetBrains.
the class AbsoluteLayoutHandler method createDragHandler.
@Override
@Nullable
public DragHandler createDragHandler(@NotNull ViewEditor editor, @NotNull NlComponent layout, @NotNull List<NlComponent> components, @NotNull DragType type) {
return new DragHandler(editor, this, layout, components, type) {
@Override
public void paint(@NotNull NlGraphics graphics) {
int deltaX = lastX - startX;
int deltaY = lastY - startY;
for (NlComponent component : components) {
int x = component.x + deltaX;
int y = component.y + deltaY;
int w = component.w;
int h = component.h;
graphics.useStyle(NlDrawingStyle.DROP_PREVIEW);
graphics.drawRect(x, y, w, h);
}
}
@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
// TODO: Remove all existing layout parameters; if you're dragging from one layout type to another, you don't
// want stale layout parameters (e.g. layout_alignLeft from a previous RelativeLayout in a new GridLayout, and so on.)
int deltaX = x - startX;
int deltaY = y - startY;
for (NlComponent component : components) {
component.setAttribute(ANDROID_URI, ATTR_LAYOUT_X, editor.pxToDpWithUnits(component.x - layout.x + deltaX));
component.setAttribute(ANDROID_URI, ATTR_LAYOUT_Y, editor.pxToDpWithUnits(component.y - layout.y + deltaY));
}
insertComponents(-1, insertType);
}
};
}
use of com.android.tools.idea.uibuilder.model.AndroidCoordinate in project android by JetBrains.
the class RelativeLayoutHandler method createDragHandler.
@Override
@Nullable
public DragHandler createDragHandler(@NotNull ViewEditor editor, @NotNull NlComponent layout, @NotNull List<NlComponent> components, @NotNull DragType type) {
final RelativeDragHandler moveHandler = new RelativeDragHandler(editor, layout, components);
return new DragHandler(editor, this, layout, components, type) {
@Nullable
@Override
public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers) {
super.update(x, y, modifiers);
NlComponent primary = components.get(0);
int deltaX = lastX - startX;
int deltaY = lastY - startY;
moveHandler.updateMove(primary, deltaX, deltaY, modifiers);
return null;
}
@Override
public void paint(@NotNull NlGraphics graphics) {
GuidelinePainter.paint(graphics, moveHandler);
}
@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
moveHandler.removeCycles();
NlComponent previous = null;
for (NlComponent component : components) {
if (previous == null) {
moveHandler.applyConstraints(component);
} else {
// Arrange the nodes next to each other, depending on which
// edge we are attaching to. For example, if attaching to the
// top edge, arrange the subsequent nodes in a column below it.
//
// TODO: Try to do something smarter here where we detect
// constraints between the dragged edges, and we preserve these.
// We have to do this carefully though because if the
// constraints go through some other nodes not part of the
// selection, this doesn't work right, and you might be
// dragging several connected components, which we'd then
// need to stitch together such that they are all visible.
moveHandler.attachPrevious(previous, component);
}
previous = component;
}
insertAddedComponents(insertType);
}
private void insertAddedComponents(@NotNull InsertType insertType) {
List<NlComponent> added = components.stream().filter(component -> component.getParent() != layout).collect(Collectors.toList());
editor.getModel().addComponents(added, layout, null, insertType);
}
};
}
use of com.android.tools.idea.uibuilder.model.AndroidCoordinate in project android by JetBrains.
the class GridInfo method getSize.
@AndroidCoordinate
private Dimension getSize() {
Dimension size = new Dimension();
if (layout.children != null) {
Insets padding = layout.getPadding();
for (NlComponent child : layout.children) {
size.width = Math.max(child.x - layout.x - padding.left + child.w, size.width);
size.height = Math.max(child.y - layout.y - padding.top + child.h, size.height);
}
}
return size;
}
use of com.android.tools.idea.uibuilder.model.AndroidCoordinate in project android by JetBrains.
the class RelativeLayoutHandler method createResizeHandler.
@Override
@Nullable
public ResizeHandler createResizeHandler(@NotNull ViewEditor editor, @NotNull NlComponent component, @Nullable SegmentType horizontalEdgeType, @Nullable SegmentType verticalEdgeType) {
NlComponent parent = component.getParent();
if (parent == null) {
return null;
}
final RelativeResizeHandler resizeHandler = new RelativeResizeHandler(editor, parent, component, horizontalEdgeType, verticalEdgeType);
return new ResizeHandler(editor, this, component, horizontalEdgeType, verticalEdgeType) {
@Nullable
@Override
public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull @AndroidCoordinate Rectangle newBounds) {
super.update(x, y, modifiers, newBounds);
resizeHandler.updateResize(component, newBounds, modifiers);
return null;
}
@Override
public void commit(@AndroidCoordinate int px, @AndroidCoordinate int py, int modifiers, @NotNull @AndroidCoordinate Rectangle newBounds) {
resizeHandler.removeCycles();
resizeHandler.applyConstraints(component);
}
@Override
public void paint(@NotNull NlGraphics graphics) {
GuidelinePainter.paint(graphics, resizeHandler);
}
};
}
use of com.android.tools.idea.uibuilder.model.AndroidCoordinate in project android by JetBrains.
the class GridInfo method getAxisLocations.
@AndroidCoordinate
private int[] getAxisLocations(String name1, String name2) throws NoSuchFieldException, IllegalAccessException {
assert layout.viewInfo != null;
Object view = layout.viewInfo.getViewObject();
Field axisField = getDeclaredField(view.getClass(), name1, name2);
axisField.setAccessible(true);
Object axis = axisField.get(view);
Field locationsField = axis.getClass().getDeclaredField("locations");
locationsField.setAccessible(true);
return (int[]) locationsField.get(axis);
}
Aggregations