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

Commit 16cfed3d authored by Tony Wickham's avatar Tony Wickham
Browse files

Fix a couple of drag and drop issues from transient taskbar

- Don't stash until drag ends, but immediately stash at that point
  (regardless of success or failure, though failure will animate to the
  original icon before stashing)
- Send transient taskbar's bounds to WM Shell via intent extra such that
  they ignore drag events in that region

Test: manual in persistent and transient taskbar
Bug: 269814838
Fixes: 268526633
Fixes: 259645384
Change-Id: I5ded3998046f259ed6e79cb4ed765ad7b0c72e45
parent 73a2334f
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
import com.android.launcher3.R
import com.android.launcher3.Utilities.mapRange
import com.android.launcher3.Utilities.mapToRange
@@ -30,7 +31,8 @@ import com.android.launcher3.util.DisplayController
/** Helps draw the taskbar background, made up of a rectangle plus two inverted rounded corners. */
class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {

    val paint: Paint = Paint()
    val paint = Paint()
    val lastDrawnTransientRect = RectF()
    var backgroundHeight = context.deviceProfile.taskbarSize.toFloat()
    var translationYForSwipe = 0f

@@ -131,7 +133,11 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
            val radius = newBackgroundHeight / 2f
            val bottomMarginProgress = bottomMargin * ((1f - progress) / 2f)

            canvas.translate(0f, canvas.height - bottomMargin + bottomMarginProgress)
            // Aligns the bottom with the bottom of the stashed handle.
            val bottom =
                canvas.height - bottomMargin +
                    bottomMarginProgress +
                    (-mapRange(1f - progress, 0f, stashedHandleHeight / 2f) + translationYForSwipe)

            // Draw shadow.
            val shadowAlpha =
@@ -143,19 +149,14 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
                setColorAlphaBound(Color.BLACK, Math.round(shadowAlpha))
            )

            // Aligns the bottom with the bottom of the stashed handle.
            val bottom =
                (-mapRange(1f - progress, 0f, stashedHandleHeight / 2f) + translationYForSwipe)

            canvas.drawRoundRect(
            lastDrawnTransientRect.set(
                transientBackgroundBounds.left + halfWidthDelta,
                bottom - newBackgroundHeight,
                transientBackgroundBounds.right - halfWidthDelta,
                bottom,
                radius,
                radius,
                paint
                bottom
            )

            canvas.drawRoundRect(lastDrawnTransientRect, radius, radius, paint)
        }
        canvas.restore()
    }
+15 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.util.Pair;
@@ -69,11 +70,13 @@ import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.quickstep.util.LogUtils;
import com.android.quickstep.util.MultiValueUpdateListener;
import com.android.systemui.shared.recents.model.Task;
import com.android.wm.shell.draganddrop.DragAndDropConstants;

import java.io.PrintWriter;
import java.util.Arrays;
@@ -310,9 +313,6 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
        if (mDisallowGlobalDrag) {
            AbstractFloatingView.closeAllOpenViewsExcept(mActivity, TYPE_TASKBAR_ALL_APPS);
        } else {
            // stash the transient taskbar
            mControllers.taskbarStashController.updateAndAnimateTransientTaskbar(true);

            AbstractFloatingView.closeAllOpenViews(mActivity);
        }

@@ -395,6 +395,15 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
            com.android.launcher3.logging.InstanceId launcherInstanceId = instanceIds.second;

            intent.putExtra(ClipDescription.EXTRA_LOGGING_INSTANCE_ID, internalInstanceId);
            if (DisplayController.isTransientTaskbar(mActivity)) {
                // Tell WM Shell to ignore drag events in the provided transient taskbar region.
                TaskbarDragLayer dragLayer = mControllers.taskbarActivityContext.getDragLayer();
                int[] locationOnScreen = dragLayer.getLocationOnScreen();
                RectF disallowExternalDropRegion = new RectF(dragLayer.getLastDrawnTransientRect());
                disallowExternalDropRegion.offset(locationOnScreen[0], locationOnScreen[1]);
                intent.putExtra(DragAndDropConstants.EXTRA_DISALLOW_HIT_REGION,
                        disallowExternalDropRegion);
            }

            ClipData clipData = new ClipData(clipDescription, new ClipData.Item(intent));
            if (btv.startDragAndDrop(clipData, shadowBuilder, null /* localState */,
@@ -421,9 +430,6 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
                    if (dragEvent.getResult()) {
                        maybeOnDragEnd();
                    } else {
                        // un-stash the transient taskbar in case drag and drop was canceled
                        mControllers.taskbarStashController.updateAndAnimateTransientTaskbar(false);

                        // This will take care of calling maybeOnDragEnd() after the animation
                        animateGlobalDragViewToOriginalPosition(btv, dragEvent);
                    }
@@ -451,6 +457,9 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
            mControllers.taskbarAutohideSuspendController.updateFlag(
                    TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING, false);
            mActivity.onDragEnd();
            // Note, this must be done last to ensure no AutohideSuspendFlags are active, as that
            // will prevent us from stashing until the timeout.
            mControllers.taskbarStashController.updateAndAnimateTransientTaskbar(true);
        }
    }

+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.view.KeyEvent.KEYCODE_BACK;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -183,6 +184,11 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
        invalidate();
    }

    /** Returns the bounds in DragLayer coordinates of where the transient background was drawn. */
    protected RectF getLastDrawnTransientRect() {
        return mBackgroundRenderer.getLastDrawnTransientRect();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        TestLogging.recordMotionEvent(TestProtocol.SEQUENCE_MAIN, "Touch event", ev);