Search in sources :

Example 1 with ViewEditor

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);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) NlModel(com.android.tools.idea.uibuilder.model.NlModel) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

Example 2 with ViewEditor

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);
}
Also used : ScrollHandler(com.android.tools.idea.uibuilder.api.ScrollHandler) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) ViewEditorImpl(com.android.tools.idea.uibuilder.handlers.ViewEditorImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ViewEditor

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);
            }
        }
    }
}
Also used : ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) ViewEditorImpl(com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)

Example 4 with ViewEditor

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);
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) ViewEditorImpl(com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)

Example 5 with ViewEditor

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);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)7 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)5 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)5 ViewEditorImpl (com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)3 NotNull (org.jetbrains.annotations.NotNull)3 ListView (android.widget.ListView)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 ScrollHandler (com.android.tools.idea.uibuilder.api.ScrollHandler)1 ViewHandler (com.android.tools.idea.uibuilder.api.ViewHandler)1 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 Nullable (org.jetbrains.annotations.Nullable)1