use of com.android.tools.idea.uibuilder.api.ViewEditor 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);
}
use of com.android.tools.idea.uibuilder.api.ViewEditor in project android by JetBrains.
the class ScrollInteraction method createScrollInteraction.
/**
* Creates a new {@link ScrollInteraction} if any of the components in the component hierarchy can handle scrolling.
* @return the {@link ScrollInteraction} or null if none of the components handle the scrolling
*/
@Nullable
public static ScrollInteraction createScrollInteraction(@NonNull ScreenView screenView, @NonNull NlComponent component) {
NlComponent currentComponent = component;
ScrollHandler scrollHandler = null;
ViewEditor editor = new ViewEditorImpl(screenView);
// Find the component that is the lowest in the hierarchy and can take the scrolling events
while (currentComponent != null) {
ViewGroupHandler viewGroupHandler = currentComponent.getViewGroupHandler();
scrollHandler = viewGroupHandler != null ? viewGroupHandler.createScrollHandler(editor, currentComponent) : null;
if (scrollHandler != null) {
break;
}
currentComponent = currentComponent.getParent();
}
if (scrollHandler == null) {
return null;
}
return new ScrollInteraction(screenView, scrollHandler);
}
use of com.android.tools.idea.uibuilder.api.ViewEditor in project android by JetBrains.
the class ResizeInteraction method begin.
@Override
public void begin(@SwingCoordinate int x, @SwingCoordinate int y, @InputEventMask int startMask) {
super.begin(x, y, startMask);
NlComponent parent = myComponent.getParent();
if (parent != null) {
ViewGroupHandler viewGroupHandler = ViewHandlerManager.get(myScreenView.getModel().getFacet()).findLayoutHandler(parent, false);
if (viewGroupHandler != null) {
ViewEditor editor = new ViewEditorImpl(myScreenView);
myResizeHandler = viewGroupHandler.createResizeHandler(editor, myComponent, myHorizontalEdge, myVerticalEdge);
if (myResizeHandler != null) {
int androidX = Coordinates.getAndroidX(myScreenView, myStartX);
int androidY = Coordinates.getAndroidY(myScreenView, myStartY);
myResizeHandler.start(androidX, androidY, startMask);
}
}
}
}
use of com.android.tools.idea.uibuilder.api.ViewEditor in project android by JetBrains.
the class NlActionManager method addViewActions.
public void addViewActions(@NotNull DefaultActionGroup group, @Nullable NlComponent component, @Nullable NlComponent parent, @NotNull List<NlComponent> newSelection, boolean toolbar) {
ScreenView screenView = mySurface.getCurrentScreenView();
if (screenView == null || (parent == null && component == null)) {
return;
}
ViewEditor editor = new ViewEditorImpl(screenView);
// TODO: Perform caching
if (component != null) {
ViewHandler handler = ViewHandlerManager.get(mySurface.getProject()).getHandler(component);
addViewActionsForHandler(group, component, newSelection, editor, handler, toolbar);
}
if (parent != null) {
ViewHandler handler = ViewHandlerManager.get(mySurface.getProject()).getHandler(parent);
List<NlComponent> selectedChildren = Lists.newArrayListWithCapacity(newSelection.size());
for (NlComponent selected : newSelection) {
if (selected.getParent() == parent) {
selectedChildren.add(selected);
}
}
addViewActionsForHandler(group, parent, selectedChildren, editor, handler, toolbar);
}
}
use of com.android.tools.idea.uibuilder.api.ViewEditor in project android by JetBrains.
the class PreferenceScreenDragHandlerTest method newPreferenceScreenDragHandler.
@NotNull
private static PreferenceGroupDragHandler newPreferenceScreenDragHandler(@NotNull NlComponent group) {
ViewEditor editor = PreferenceScreenTestFactory.mockEditor();
List<NlComponent> preferences = Collections.singletonList(Mockito.mock(NlComponent.class));
return new PreferenceScreenDragHandler(editor, new ViewGroupHandler(), group, preferences, DragType.MOVE);
}
Aggregations