Merge "Fix a couple of drag and drop issues from transient taskbar" into tm-qpr-dev

This commit is contained in:
Tony Wickham
2023-02-22 03:38:38 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 17 deletions

View File

@@ -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()
}

View File

@@ -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);
}
}

View File

@@ -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);