Search in sources :

Example 1 with DragDndTarget

use of com.android.tools.idea.uibuilder.scene.target.DragDndTarget in project android by JetBrains.

the class SceneDragHandler method commit.

@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    if (myComponent != null) {
        NlComponent nlComponent = components.get(0);
        NlComponent root = nlComponent.getRoot();
        root.ensureNamespace(SdkConstants.SHERPA_PREFIX, SdkConstants.AUTO_URI);
        SceneComponent component = scene.getSceneComponent(myComponent);
        if (component != null) {
            ArrayList<Target> targets = component.getTargets();
            int dx = x - myComponent.w / 2;
            int dy = y - myComponent.h / 2;
            for (int i = 0; i < targets.size(); i++) {
                if (targets.get(i) instanceof DragDndTarget) {
                    DragDndTarget target = (DragDndTarget) targets.get(i);
                    target.mouseRelease(scene.pxToDp(dx), scene.pxToDp(dy), nlComponent);
                    break;
                }
            }
        }
    }
    insertComponents(-1, insertType);
    scene.setDnDComponent(null);
    scene.checkRequestLayoutStatus();
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget)

Example 2 with DragDndTarget

use of com.android.tools.idea.uibuilder.scene.target.DragDndTarget in project android by JetBrains.

the class SceneDragHandler method update.

@Nullable
@Override
public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers) {
    String result = super.update(x, y, modifiers);
    if (myComponent == null) {
        return "undefined";
    }
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    SceneComponent component = scene.getSceneComponent(myComponent);
    int dx = x - myComponent.w / 2;
    int dy = y - myComponent.h / 2;
    myComponent.x = dx;
    myComponent.y = dy;
    if (component != null) {
        ArrayList<Target> targets = component.getTargets();
        for (int i = 0; i < targets.size(); i++) {
            if (targets.get(i) instanceof DragDndTarget) {
                DragDndTarget target = (DragDndTarget) targets.get(i);
                target.mouseDrag(scene.pxToDp(dx), scene.pxToDp(dy), target);
                break;
            }
        }
    }
    scene.checkRequestLayoutStatus();
    return result;
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DragDndTarget

use of com.android.tools.idea.uibuilder.scene.target.DragDndTarget in project android by JetBrains.

the class SceneDragHandler method start.

@Override
public void start(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers) {
    super.start(x, y, modifiers);
    if (myComponent == null) {
        return;
    }
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    scene.needsRebuildList();
    SceneComponent component = scene.getSceneComponent(myComponent);
    ArrayList<Target> targets = component.getTargets();
    int dx = x - myComponent.w / 2;
    int dy = y - myComponent.h / 2;
    for (int i = 0; i < targets.size(); i++) {
        if (targets.get(i) instanceof DragDndTarget) {
            DragDndTarget target = (DragDndTarget) targets.get(i);
            target.mouseDown(scene.pxToDp(dx), scene.pxToDp(dy));
            break;
        }
    }
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget)

Aggregations

DragDndTarget (com.android.tools.idea.uibuilder.scene.target.DragDndTarget)3 DragTarget (com.android.tools.idea.uibuilder.scene.target.DragTarget)3 Target (com.android.tools.idea.uibuilder.scene.target.Target)3 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 Nullable (org.jetbrains.annotations.Nullable)1