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

Commit 58376925 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing page background not displayed when dragging from all apps

> Adding empty page synchronously, instead of waiting for a frame
> Changing launcher state from widgets screen in the same frame, similar to all apps
> Removing DragEnforcer, and moving that logic in side the workspace, disabled by a flag
> Using first page to get page bounds in drag layer, as last page may not have been measured

Change-Id: I172ba4e5ce44648ac55402d49994542c6e10f101
parent 5cc7af12
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

<!-- DragController -->
    <integer name="config_flingToDeleteMinVelocity">-1500</integer>
    <item type="id" name="drag_event_parity" />

<!-- AllApps & Launcher transitions -->
    <!-- The alpha of the AppsCustomize bg in spring loaded mode -->
+0 −4
Original line number Diff line number Diff line
@@ -168,7 +168,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
    private int[] mDirectionVector = new int[2];
    int[] mPreviousReorderDirection = new int[2];
    private static final int INVALID_DIRECTION = -100;
    private DropTarget.DragEnforcer mDragEnforcer;

    private final Rect mTempRect = new Rect();

@@ -188,7 +187,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {

    public CellLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mDragEnforcer = new DropTarget.DragEnforcer(context);

        // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
        // the user where a dragged item will land when dropped.
@@ -2637,7 +2635,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
     * or it may have begun on another layout.
     */
    void onDragEnter() {
        mDragEnforcer.onDragEnter();
        mDragging = true;
    }

@@ -2645,7 +2642,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
     * Called when drag has left this CellLayout or has been completed (successfully or not)
     */
    void onDragExit() {
        mDragEnforcer.onDragExit();
        // This can actually be called when we aren't in a drag, e.g. when adding a new
        // item to this layout via the customize drawer.
        // Guard against that case.
+1 −1
Original line number Diff line number Diff line
@@ -918,7 +918,7 @@ public class DragLayer extends InsettableFrameLayout {
    void showPageHints() {
        mShowPageHints = true;
        Workspace workspace = mLauncher.getWorkspace();
        getDescendantRectRelativeToSelf(workspace.getChildAt(workspace.getChildCount() - 1),
        getDescendantRectRelativeToSelf(workspace.getChildAt(workspace.numCustomPages()),
                mScrollChildPosition);
        invalidate();
    }
+0 −39
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@

package com.android.launcher3;

import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Log;

/**
 * Interface defining an object that can receive a drag.
@@ -93,43 +91,6 @@ public interface DropTarget {
        }
    }

    public static class DragEnforcer implements DragController.DragListener {
        int dragParity = 0;

        public DragEnforcer(Context context) {
            Launcher launcher = (Launcher) context;
            launcher.getDragController().addDragListener(this);
        }

        void onDragEnter() {
            dragParity++;
            if (dragParity != 1) {
                Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
            }
        }

        void onDragExit() {
            dragParity--;
            if (dragParity != 0) {
                Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
            }
        }

        @Override
        public void onDragStart(DragSource source, Object info, int dragAction) {
            if (dragParity != 0) {
                Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
            }
        }

        @Override
        public void onDragEnd() {
            if (dragParity != 0) {
                Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
            }
        }
    }

    /**
     * Used to temporarily disable certain drop targets
     *
+45 −16
Original line number Diff line number Diff line
@@ -64,8 +64,8 @@ import com.android.launcher3.Launcher.LauncherOverlay;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.UninstallDropTarget.UninstallSource;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource;
import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.Thunk;
@@ -89,6 +89,8 @@ public class Workspace extends PagedView
        Insettable, UninstallSource, AccessibilityDragSource {
    private static final String TAG = "Launcher.Workspace";

    private static boolean ENFORCE_DRAG_EVENT_ORDER = false;

    protected static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400;
    protected static final int FADE_EMPTY_SCREEN_DURATION = 150;

@@ -215,7 +217,6 @@ public class Workspace extends PagedView
    private FolderIcon mDragOverFolderIcon = null;
    private boolean mCreateUserFolderOnDrop = false;
    private boolean mAddToExistingFolderOnDrop = false;
    private DropTarget.DragEnforcer mDragEnforcer;
    private float mMaxDistanceForFolderCreation;

    private final Canvas mCanvas = new Canvas();
@@ -301,9 +302,6 @@ public class Workspace extends PagedView

        mOutlineHelper = HolographicOutlineHelper.obtain(context);

        mDragEnforcer = new DropTarget.DragEnforcer(context);
        // With workspace, data is available straight from the get-go

        mLauncher = (Launcher) context;
        mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
        final Resources res = getResources();
@@ -372,23 +370,24 @@ public class Workspace extends PagedView
        return r;
    }

    @Override
    public void onDragStart(final DragSource source, Object info, int dragAction) {
        if (ENFORCE_DRAG_EVENT_ORDER) {
            enfoceDragParity("onDragStart", 0, 0);
        }

        mIsDragOccuring = true;
        updateChildrenLayersEnabled(false);
        mLauncher.lockScreenOrientation();
        mLauncher.onInteractionBegin();
        // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
        InstallShortcutReceiver.enableInstallQueue();
        post(new Runnable() {
            @Override
            public void run() {
                if (mIsDragOccuring && mAddNewPageOnDrag) {

        if (mAddNewPageOnDrag) {
            mDeferRemoveExtraEmptyScreen = false;
            addExtraEmptyScreenOnDrag();
        }
    }
        });
    }

    public void setAddNewPageOnDrag(boolean addPage) {
        mAddNewPageOnDrag = addPage;
@@ -398,7 +397,12 @@ public class Workspace extends PagedView
        mDeferRemoveExtraEmptyScreen = true;
    }

    @Override
    public void onDragEnd() {
        if (ENFORCE_DRAG_EVENT_ORDER) {
            enfoceDragParity("onDragEnd", 0, 0);
        }

        if (!mDeferRemoveExtraEmptyScreen) {
            removeExtraEmptyScreen(true, mDragSourceInternal != null);
        }
@@ -2822,8 +2826,12 @@ public class Workspace extends PagedView
        location[1] = vY - y;
    }

    @Override
    public void onDragEnter(DragObject d) {
        mDragEnforcer.onDragEnter();
        if (ENFORCE_DRAG_EVENT_ORDER) {
            enfoceDragParity("onDragEnter", 1, 1);
        }

        mCreateUserFolderOnDrop = false;
        mAddToExistingFolderOnDrop = false;

@@ -2876,8 +2884,11 @@ public class Workspace extends PagedView
        return null;
    }

    @Override
    public void onDragExit(DragObject d) {
        mDragEnforcer.onDragExit();
        if (ENFORCE_DRAG_EVENT_ORDER) {
            enfoceDragParity("onDragExit", -1, 0);
        }

        // Here we store the final page that will be dropped to, if the workspace in fact
        // receives the drop
@@ -2909,6 +2920,24 @@ public class Workspace extends PagedView
        mLauncher.getDragLayer().hidePageHints();
    }

    private void enfoceDragParity(String event, int update, int expectedValue) {
        enfoceDragParity(this, event, update, expectedValue);
        for (int i = 0; i < getChildCount(); i++) {
            enfoceDragParity(getChildAt(i), event, update, expectedValue);
        }
    }

    private void enfoceDragParity(View v, String event, int update, int expectedValue) {
        Object tag = v.getTag(R.id.drag_event_parity);
        int value = tag == null ? 0 : (Integer) tag;
        value += update;
        v.setTag(R.id.drag_event_parity, value);

        if (value != expectedValue) {
            Log.e(TAG, event + ": Drag contract violated: " + value);
        }
    }

    void setCurrentDropLayout(CellLayout layout) {
        if (mDragTargetLayout != null) {
            mDragTargetLayout.revertTempState();
Loading