Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cfd1158 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Handing pin item drag when workspce is not loaded" into ub-launcher3-master

parents 8a0dc38a 2bcb3fb1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ public class DragController implements DragDriver.EventListener, TouchController
        if (!mIsInPreDrag) {
            callOnDragStart();
        } else if (mOptions.preDragCondition != null) {
            mOptions.preDragCondition.onPreDragStart();
            mOptions.preDragCondition.onPreDragStart(mDragObject);
        }

        mLastTouch[0] = mMotionDownX;
@@ -236,7 +236,7 @@ public class DragController implements DragDriver.EventListener, TouchController
            listener.onDragStart(mDragObject, mOptions);
        }
        if (mOptions.preDragCondition != null) {
            mOptions.preDragCondition.onPreDragEnd(true /* dragStarted*/);
            mOptions.preDragCondition.onPreDragEnd(mDragObject, true /* dragStarted*/);
        }
        mIsInPreDrag = false;
    }
@@ -335,7 +335,7 @@ public class DragController implements DragDriver.EventListener, TouchController

    private void callOnDragEnd() {
        if (mIsInPreDrag && mOptions.preDragCondition != null) {
            mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/);
            mOptions.preDragCondition.onPreDragEnd(mDragObject, false /* dragStarted*/);
        }
        mIsInPreDrag = false;
        mOptions = null;
+4 −2
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.graphics.Point;
import android.support.annotation.CallSuper;
import android.view.View;

import com.android.launcher3.DropTarget;

/**
 * Set of options to control the drag and drop behavior.
 */
@@ -52,7 +54,7 @@ public class DragOptions {
         * The pre-drag has started, but onDragStart() is
         * deferred until shouldStartDrag() returns true.
         */
        void onPreDragStart();
        void onPreDragStart(DropTarget.DragObject dragObject);

        /**
         * The pre-drag has ended. This gets called at the same time as onDragStart()
@@ -60,6 +62,6 @@ public class DragOptions {
         * @param dragStarted Whether the pre-drag ended because the actual drag started.
         *                    This will be true if the condition was met, otherwise false.
         */
        void onPreDragEnd(boolean dragStarted);
        void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted);
    }
}
+28 −6
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.compat.PinItemRequestCompat;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.graphics.LauncherIcons;
@@ -57,7 +58,8 @@ import java.util.UUID;
 * {@link DragSource} for handling drop from from a different window. This object is initialized
 * in the source window and is passed on to the Launcher activity as an Intent extra.
 */
public class PinItemDragListener implements Parcelable, View.OnDragListener, DragSource {
public class PinItemDragListener
        implements Parcelable, View.OnDragListener, DragSource, DragOptions.PreDragCondition {

    private static final String TAG = "PinItemDragListener";

@@ -136,11 +138,6 @@ public class PinItemDragListener implements Parcelable, View.OnDragListener, Dra
            return false;
        }

        if (mLauncher.isWorkspaceLocked()) {
            // TODO: implement wait
            return false;
        }

        final PendingAddItemInfo item;
        final Bitmap preview;
        final View view = new View(mLauncher);
@@ -203,6 +200,7 @@ public class PinItemDragListener implements Parcelable, View.OnDragListener, Dra
        Point downPos = new Point((int) event.getX(), (int) event.getY());
        DragOptions options = new DragOptions();
        options.systemDndStartPoint = downPos;
        options.preDragCondition = this;

        int x = downPos.x + dragShift.x;
        int y = downPos.y + dragShift.y;
@@ -212,6 +210,30 @@ public class PinItemDragListener implements Parcelable, View.OnDragListener, Dra
        return true;
    }

    @Override
    public boolean shouldStartDrag(double distanceDragged) {
        // Stay in pre-drag mode, if workspace is locked.
        return !mLauncher.isWorkspaceLocked();
    }

    @Override
    public void onPreDragStart(DropTarget.DragObject dragObject) {
        // The predrag starts when the workspace is not yet loaded. In some cases we set
        // the dragLayer alpha to 0 to have a nice fade-in animation. But that will prevent the
        // dragView from being visible. Instead just skip the fade-in animation here.
        mLauncher.getDragLayer().setAlpha(1);

        dragObject.dragView.setColor(
                mLauncher.getResources().getColor(R.color.delete_target_hover_tint));
    }

    @Override
    public void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted) {
        if (dragStarted) {
            dragObject.dragView.setColor(0);
        }
    }

    @Override
    public boolean supportsAppInfoDropTarget() {
        return false;
+2 −2
Original line number Diff line number Diff line
@@ -498,12 +498,12 @@ public class PopupContainerWithArrow extends AbstractFloatingView
            }

            @Override
            public void onPreDragStart() {
            public void onPreDragStart(DropTarget.DragObject dragObject) {
                mOriginalIcon.setVisibility(INVISIBLE);
            }

            @Override
            public void onPreDragEnd(boolean dragStarted) {
            public void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted) {
                if (!dragStarted) {
                    mOriginalIcon.setVisibility(VISIBLE);
                    mLauncher.getUserEventDispatcher().logDeepShortcutsOpen(mOriginalIcon);