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

Commit 1797af41 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Cleaning up drag state management.

When the drag is started, the UI automatically goes into spring loaded mode. On a successful
drop, it is the responsibility of the {@link DropTarget} to exit out of the spring loaded
mode. If the drop was cancelled for some reason, the UI will automatically exit out of this mode.

Bug: 34692289
Change-Id: Ic611739a43bb8d9279b587aaee3039326c143e8b
parent cbdfc598
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ public abstract class ButtonDropTarget extends TextView
            public void run() {
                completeDrop(d);
                mDropTargetBar.onDragEnd();
                mLauncher.exitSpringLoadedDragModeDelayed(true, 0, null);
                mLauncher.exitSpringLoadedDragMode(true, 0);
            }
        };
        dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f,
+1 −1
Original line number Diff line number Diff line
@@ -30,5 +30,5 @@ public interface DragSource extends LogContainerProvider {
     * A callback made back to the source after an item from this source has been dropped on a
     * DropTarget.
     */
    void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, boolean success);
    void onDropCompleted(View target, DragObject d, boolean success);
}
+8 −4
Original line number Diff line number Diff line
@@ -59,9 +59,6 @@ public interface DropTarget {
        /** The object is part of an accessible drag operation */
        public boolean accessibleDrag;

        /** Post drag animation runnable */
        public Runnable postAnimationRunnable = null;

        /** Indicates that the drag operation was cancelled */
        public boolean cancelled = false;

@@ -105,7 +102,14 @@ public interface DropTarget {
    boolean isDropEnabled();

    /**
     * Handle an object being dropped on the DropTarget
     * Handle an object being dropped on the DropTarget.
     *
     * This will be called only if this target previously returned true for {@link #acceptDrop}. It
     * is the responsibility of this target to exit out of the spring loaded mode (either
     * immediately or after any pending animations).
     *
     * If the drop was cancelled for some reason, onDrop will never get called, the UI will
     * automatically exit out of this mode.
     */
    void onDrop(DragObject dragObject, DragOptions options);

+33 −25
Original line number Diff line number Diff line
@@ -582,8 +582,8 @@ public class Launcher extends BaseActivity
        Runnable exitSpringLoaded = new Runnable() {
            @Override
            public void run() {
                exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
                        EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
                exitSpringLoadedDragMode((resultCode != RESULT_CANCELED),
                        EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT);
            }
        };

@@ -635,7 +635,7 @@ public class Launcher extends BaseActivity
                final Runnable onComplete = new Runnable() {
                    @Override
                    public void run() {
                        exitSpringLoadedDragModeDelayed(false, 0, null);
                        exitSpringLoadedDragMode(false, 0);
                    }
                };

@@ -763,8 +763,8 @@ public class Launcher extends BaseActivity
                @Override
                public void run() {
                    completeAddAppWidget(appWidgetId, requestArgs, layout, null);
                    exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
                            EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
                    exitSpringLoadedDragMode((resultCode != RESULT_CANCELED),
                            EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT);
                }
            };
        } else if (resultCode == RESULT_CANCELED) {
@@ -1231,7 +1231,7 @@ public class Launcher extends BaseActivity

                // If appropriate, either create a folder or add to an existing folder
                if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
                        true, null, null)) {
                        true, null)) {
                    return;
                }
                DragObject dragObject = new DragObject();
@@ -1714,8 +1714,8 @@ public class Launcher extends BaseActivity
                @Override
                public void run() {
                    // Exit spring loaded mode if necessary after adding the widget
                    exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
                            null);
                    exitSpringLoadedDragMode(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT
                    );
                }
            };
            completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
@@ -2598,16 +2598,36 @@ public class Launcher extends BaseActivity
            return;
        }

        // Lock the orientation:
        if (mRotationEnabled) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
        }

        // Prevent any Un/InstallShortcutReceivers from updating the db while we are
        // in spring loaded mode
        InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP);

        mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
                Workspace.State.SPRING_LOADED, true /* animated */,
                null /* onCompleteRunnable */);
        setState(State.WORKSPACE_SPRING_LOADED);
    }

    public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
    public void exitSpringLoadedDragMode(final boolean successfulDrop, int delay) {
        exitSpringLoadedDragMode(successfulDrop, delay, null);
    }

    public void exitSpringLoadedDragMode(final boolean successfulDrop, int delay,
            final Runnable onCompleteRunnable) {
        if (!isStateSpringLoaded()) return;

        // Unlock rotation lock
        unlockScreenOrientation(false);

        // Re-enable any Un/InstallShortcutReceiver and now process any queued items
        InstallShortcutReceiver.disableAndFlushInstallQueue(
                InstallShortcutReceiver.FLAG_DRAG_AND_DROP, this);

        if (mExitSpringLoadedModeRunnable != null) {
            mHandler.removeCallbacks(mExitSpringLoadedModeRunnable);
        }
@@ -2621,8 +2641,10 @@ public class Launcher extends BaseActivity
                    // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
                    // clean up our state transition functions
                    showWorkspace(true, onCompleteRunnable);
                } else {
                    exitSpringLoadedDragMode();
                } else if (mState == State.APPS_SPRING_LOADED) {
                    showAppsView(true /* animated */);
                } else if (mState == State.WORKSPACE_SPRING_LOADED) {
                    showWorkspace(true);
                }
                mExitSpringLoadedModeRunnable = null;
            }
@@ -2635,14 +2657,6 @@ public class Launcher extends BaseActivity
                || mState == State.WIDGETS_SPRING_LOADED;
    }

    public void exitSpringLoadedDragMode() {
        if (mState == State.APPS_SPRING_LOADED) {
            showAppsView(true /* animated */);
        } else if (mState == State.WORKSPACE_SPRING_LOADED) {
            showWorkspace(true);
        }
    }

    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        final boolean result = super.dispatchPopulateAccessibilityEvent(event);
@@ -3398,12 +3412,6 @@ public class Launcher extends BaseActivity
        mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
    }

    public void lockScreenOrientation() {
        if (mRotationEnabled) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
        }
    }

    public void unlockScreenOrientation(boolean immediate) {
        if (mRotationEnabled) {
            if (immediate) {
+4 −6
Original line number Diff line number Diff line
@@ -97,9 +97,7 @@ public class UninstallDropTarget extends ButtonDropTarget {
    @Override
    public void onDrop(DragObject d, DragOptions options) {
        // Defer onComplete
        if (options.deferCompleteForUninstall) {
        d.dragSource = new DeferredOnComplete(d.dragSource, getContext());
        }
        super.onDrop(d, options);
    }

@@ -171,7 +169,7 @@ public class UninstallDropTarget extends ButtonDropTarget {
        }

        @Override
        public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete,
        public void onDropCompleted(View target, DragObject d,
                boolean success) {
            mDragObject = d;
        }
@@ -189,7 +187,7 @@ public class UninstallDropTarget extends ButtonDropTarget {
                    .getApplicationInfo(mPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES,
                            mDragObject.dragInfo.user) == null) {
                mDragObject.dragSource = mOriginal;
                mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, false, true);
                mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, true);
            } else {
                sendFailure();
            }
@@ -198,7 +196,7 @@ public class UninstallDropTarget extends ButtonDropTarget {
        public void sendFailure() {
            mDragObject.dragSource = mOriginal;
            mDragObject.cancelled = true;
            mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, false, false);
            mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, false);
        }
    }
}
Loading