From e0a81640e53063fb028db45d04d41d073ffd6bab Mon Sep 17 00:00:00 2001 From: Mateusz Cicheński Date: Thu, 18 May 2023 01:47:25 +0000 Subject: Make PiP move away to not occlude IME when it's too big Keep clear algorithm don't change position if there is no space, but in corner case scenario if the insets simply weren't big enough to even contain PiP height, it would lead to occluding IME. With this change we are now moving PiP when it doesn't fit in the insets to be positioned according to the gravity rules, even if user has interacted with it, which also brings PiP down when IME hides. Bug: 283172848 Test: http://recall/-/g8x7ZkgdfbqscttAA9wzl9/4Qxus5Q16e4SyHtJPgdtS Change-Id: Ia4c797ef484bc917cf1579ab2f0f72cfd4646169 --- .../wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java index ed8dc7ded654..fc674a8aa59b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipKeepClearAlgorithm.java @@ -65,9 +65,18 @@ public class PhonePipKeepClearAlgorithm implements PipKeepClearAlgorithmInterfac } Rect pipBounds = new Rect(startingBounds); - // move PiP towards corner if user hasn't moved it manually or the flag is on - if (mKeepClearAreaGravityEnabled - || (!pipBoundsState.hasUserMovedPip() && !pipBoundsState.hasUserResizedPip())) { + boolean shouldApplyGravity = false; + // if PiP is outside of screen insets, reposition using gravity + if (!insets.contains(pipBounds)) { + shouldApplyGravity = true; + } + // if user has not interacted with PiP, reposition using gravity + if (!pipBoundsState.hasUserMovedPip() && !pipBoundsState.hasUserResizedPip()) { + shouldApplyGravity = true; + } + + // apply gravity that will position PiP in bottom left or bottom right corner within insets + if (mKeepClearAreaGravityEnabled || shouldApplyGravity) { float snapFraction = pipBoundsAlgorithm.getSnapFraction(startingBounds); int verticalGravity = Gravity.BOTTOM; int horizontalGravity; -- cgit v1.2.3-59-g8ed1b