Merge "Fix strange pip size in horizontal expanded mode" into tm-dev am: 427189714d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17607768

Change-Id: I979c87012da1969226f31655fbebd86f9ee3759e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Galia Peycheva
2022-04-12 08:53:18 +00:00
committed by Automerger Merge Worker
2 changed files with 70 additions and 7 deletions

View File

@@ -133,7 +133,8 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
val pipAnchorBoundsWithAllDecors =
getNormalPipAnchorBounds(pipSizeWithAllDecors, transformedMovementBounds)
val pipAnchorBoundsWithPermanentDecors = removeTemporaryDecors(pipAnchorBoundsWithAllDecors)
val pipAnchorBoundsWithPermanentDecors =
removeTemporaryDecorsTransformed(pipAnchorBoundsWithAllDecors)
val result = calculatePipPositionTransformed(
pipAnchorBoundsWithPermanentDecors,
transformedRestrictedAreas,
@@ -471,12 +472,10 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
}
fun setPipPermanentDecorInsets(insets: Insets) {
if (pipPermanentDecorInsets == insets) return
pipPermanentDecorInsets = insets
}
fun setPipTemporaryDecorInsets(insets: Insets) {
if (pipTemporaryDecorInsets == insets) return
pipTemporaryDecorInsets = insets
}
@@ -781,6 +780,7 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
/**
* Removes the space that was reserved for permanent decorations around the pip
* @param bounds the bounds (in screen space) to remove the insets from
*/
private fun removePermanentDecors(bounds: Rect): Rect {
val pipDecorReverseInsets = Insets.subtract(Insets.NONE, pipPermanentDecorInsets)
@@ -790,11 +790,15 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
/**
* Removes the space that was reserved for temporary decorations around the pip
* @param bounds the bounds (in base case) to remove the insets from
*/
private fun removeTemporaryDecors(bounds: Rect): Rect {
val pipDecorReverseInsets = Insets.subtract(Insets.NONE, pipTemporaryDecorInsets)
bounds.inset(pipDecorReverseInsets)
return bounds
private fun removeTemporaryDecorsTransformed(bounds: Rect): Rect {
if (pipTemporaryDecorInsets == Insets.NONE) return bounds
var reverseInsets = Insets.subtract(Insets.NONE, pipTemporaryDecorInsets)
var boundsInScreenSpace = fromTransformedSpace(bounds)
boundsInScreenSpace.inset(reverseInsets)
return toTransformedSpace(boundsInScreenSpace)
}
private fun Rect.offsetCopy(dx: Int, dy: Int) = Rect(this).apply { offset(dx, dy) }

View File

@@ -16,6 +16,7 @@
package com.android.wm.shell.pip.tv
import android.graphics.Insets
import android.graphics.Rect
import android.testing.AndroidTestingRunner
import android.util.Size
@@ -432,6 +433,64 @@ class TvPipKeepClearAlgorithmTest {
assertEquals(currentTime + algorithm.stashDuration, placement.unstashTime)
}
@Test
fun test_PipInsets() {
val permInsets = Insets.of(-1, -2, -3, -4)
algorithm.setPipPermanentDecorInsets(permInsets)
testInsetsForAllPositions(permInsets)
val tempInsets = Insets.of(-4, -3, -2, -1)
algorithm.setPipPermanentDecorInsets(Insets.NONE)
algorithm.setPipTemporaryDecorInsets(tempInsets)
testInsetsForAllPositions(tempInsets)
algorithm.setPipPermanentDecorInsets(permInsets)
algorithm.setPipTemporaryDecorInsets(tempInsets)
testInsetsForAllPositions(Insets.add(permInsets, tempInsets))
}
private fun testInsetsForAllPositions(insets: Insets) {
gravity = Gravity.BOTTOM or Gravity.RIGHT
testAnchorPositionWithInsets(insets)
gravity = Gravity.BOTTOM or Gravity.LEFT
testAnchorPositionWithInsets(insets)
gravity = Gravity.TOP or Gravity.LEFT
testAnchorPositionWithInsets(insets)
gravity = Gravity.TOP or Gravity.RIGHT
testAnchorPositionWithInsets(insets)
pipSize = EXPANDED_WIDE_PIP_SIZE
gravity = Gravity.BOTTOM
testAnchorPositionWithInsets(insets)
gravity = Gravity.TOP
testAnchorPositionWithInsets(insets)
pipSize = Size(pipSize.height, pipSize.width)
gravity = Gravity.LEFT
testAnchorPositionWithInsets(insets)
gravity = Gravity.RIGHT
testAnchorPositionWithInsets(insets)
}
private fun testAnchorPositionWithInsets(insets: Insets) {
var pipRect = Rect(0, 0, pipSize.width, pipSize.height)
pipRect.inset(insets)
var expectedBounds = Rect()
Gravity.apply(gravity, pipRect.width(), pipRect.height(), movementBounds, expectedBounds)
val reverseInsets = Insets.subtract(Insets.NONE, insets)
expectedBounds.inset(reverseInsets)
var placement = getActualPlacement()
assertEquals(expectedBounds, placement.bounds)
}
private fun makeSideBar(width: Int, @Gravity.GravityFlags side: Int): Rect {
val sidebar = Rect(0, 0, width, SCREEN_SIZE.height)
if (side == Gravity.RIGHT) {