From 7a772305c3e2bf25234604293ae7473e0634b19f Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 26 Jan 2022 13:52:56 -0800 Subject: [PATCH] Fix hit targets, hopefully once and for all When already in split screen we use the stage bounds from split screen controller, however, these bounds really represent the draw region and would be inset by taskbar etc. For the hit targets we really want the whole side of the screen from the middle of the divider, rather than the draw region. This CL updates it so that the hit region is based of the display region divided wherever the divider is. Test: manual - have apps in split, drag a new one into split and observe that the animation is smooth Bug: 207011867 Change-Id: I7142755febd7fe2f6c2db4cee2e08fa2f43c3b7f --- .../shell/draganddrop/DragAndDropPolicy.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java index eda09e3ce0b0d..5ebdceba135bd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java @@ -150,43 +150,45 @@ public class DragAndDropPolicy { if (inLandscape) { final Rect leftHitRegion = new Rect(); - final Rect leftDrawRegion = topOrLeftBounds; final Rect rightHitRegion = new Rect(); - final Rect rightDrawRegion = bottomOrRightBounds; // If we have existing split regions use those bounds, otherwise split it 50/50 if (inSplitScreen) { - // Add the divider bounds to each side since that counts for the hit region. - leftHitRegion.set(topOrLeftBounds); - leftHitRegion.right += dividerWidth / 2; - rightHitRegion.set(bottomOrRightBounds); - rightHitRegion.left -= dividerWidth / 2; + // The bounds of the existing split will have a divider bar, the hit region + // should include that space. Find the center of the divider bar: + float centerX = topOrLeftBounds.right + (dividerWidth / 2); + // Now set the hit regions using that center. + leftHitRegion.set(displayRegion); + leftHitRegion.right = (int) centerX; + rightHitRegion.set(displayRegion); + rightHitRegion.left = (int) centerX; } else { displayRegion.splitVertically(leftHitRegion, rightHitRegion); } - mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, leftDrawRegion)); - mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, rightDrawRegion)); + mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, topOrLeftBounds)); + mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, bottomOrRightBounds)); } else { final Rect topHitRegion = new Rect(); - final Rect topDrawRegion = topOrLeftBounds; final Rect bottomHitRegion = new Rect(); - final Rect bottomDrawRegion = bottomOrRightBounds; // If we have existing split regions use those bounds, otherwise split it 50/50 if (inSplitScreen) { - // Add the divider bounds to each side since that counts for the hit region. - topHitRegion.set(topOrLeftBounds); - topHitRegion.bottom += dividerWidth / 2; - bottomHitRegion.set(bottomOrRightBounds); - bottomHitRegion.top -= dividerWidth / 2; + // The bounds of the existing split will have a divider bar, the hit region + // should include that space. Find the center of the divider bar: + float centerX = topOrLeftBounds.bottom + (dividerWidth / 2); + // Now set the hit regions using that center. + topHitRegion.set(displayRegion); + topHitRegion.bottom = (int) centerX; + bottomHitRegion.set(displayRegion); + bottomHitRegion.top = (int) centerX; } else { displayRegion.splitHorizontally(topHitRegion, bottomHitRegion); } - mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topDrawRegion)); - mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomDrawRegion)); + mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topOrLeftBounds)); + mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomOrRightBounds)); } } else { // Split-screen not allowed, so only show the fullscreen target