Merge "Consider all TV PiP stashing directions" into tm-dev

This commit is contained in:
Robert Horvath
2022-04-07 13:42:21 +00:00
committed by Android (Google) Code Review

View File

@@ -363,48 +363,54 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
private fun getNearbyStashedPosition(bounds: Rect, keepClearAreas: Set<Rect>): Rect { private fun getNearbyStashedPosition(bounds: Rect, keepClearAreas: Set<Rect>): Rect {
val screenBounds = transformedScreenBounds val screenBounds = transformedScreenBounds
val stashCandidates = Array(2) { Rect(bounds) } val stashCandidates = mutableListOf<Rect>()
val areasOverlappingPipX = keepClearAreas.filter { it.intersectsX(bounds) } val areasOverlappingPipX = keepClearAreas.filter { it.intersectsX(bounds) }
val areasOverlappingPipY = keepClearAreas.filter { it.intersectsY(bounds) } val areasOverlappingPipY = keepClearAreas.filter { it.intersectsY(bounds) }
if (screenBounds.bottom - bounds.bottom <= bounds.top - screenBounds.top) { if (screenBounds.bottom - bounds.bottom <= bounds.top - screenBounds.top) {
// bottom is closer than top, stash downwards
val fullStashTop = screenBounds.bottom - stashOffset val fullStashTop = screenBounds.bottom - stashOffset
val maxBottom = areasOverlappingPipX.maxByOrNull { it.bottom }!!.bottom val maxBottom = areasOverlappingPipX.maxByOrNull { it.bottom }!!.bottom
val partialStashTop = maxBottom + pipAreaPadding val partialStashTop = maxBottom + pipAreaPadding
val downPosition = stashCandidates[0] val downPosition = Rect(bounds)
downPosition.offsetTo(bounds.left, min(fullStashTop, partialStashTop)) downPosition.offsetTo(bounds.left, min(fullStashTop, partialStashTop))
} else { stashCandidates += downPosition
// top is closer than bottom, stash upwards }
val fullStashY = screenBounds.top - bounds.height() + stashOffset if (screenBounds.bottom - bounds.bottom >= bounds.top - screenBounds.top) {
val fullStashBottom = screenBounds.top - bounds.height() + stashOffset
val minTop = areasOverlappingPipX.minByOrNull { it.top }!!.top val minTop = areasOverlappingPipX.minByOrNull { it.top }!!.top
val partialStashY = minTop - bounds.height() - pipAreaPadding val partialStashBottom = minTop - bounds.height() - pipAreaPadding
val upPosition = stashCandidates[0] val upPosition = Rect(bounds)
upPosition.offsetTo(bounds.left, max(fullStashY, partialStashY)) upPosition.offsetTo(bounds.left, max(fullStashBottom, partialStashBottom))
stashCandidates += upPosition
} }
if (screenBounds.right - bounds.right <= bounds.left - screenBounds.left) { if (screenBounds.right - bounds.right <= bounds.left - screenBounds.left) {
// right is closer than left, stash rightwards val fullStashRight = screenBounds.right - stashOffset
val fullStashLeft = screenBounds.right - stashOffset
val maxRight = areasOverlappingPipY.maxByOrNull { it.right }!!.right val maxRight = areasOverlappingPipY.maxByOrNull { it.right }!!.right
val partialStashLeft = maxRight + pipAreaPadding val partialStashRight = maxRight + pipAreaPadding
val rightPosition = stashCandidates[1] val rightPosition = Rect(bounds)
rightPosition.offsetTo(min(fullStashLeft, partialStashLeft), bounds.top) rightPosition.offsetTo(min(fullStashRight, partialStashRight), bounds.top)
} else { stashCandidates += rightPosition
// left is closer than right, stash leftwards }
if (screenBounds.right - bounds.right >= bounds.left - screenBounds.left) {
val fullStashLeft = screenBounds.left - bounds.width() + stashOffset val fullStashLeft = screenBounds.left - bounds.width() + stashOffset
val minLeft = areasOverlappingPipY.minByOrNull { it.left }!!.left val minLeft = areasOverlappingPipY.minByOrNull { it.left }!!.left
val partialStashLeft = minLeft - bounds.width() - pipAreaPadding val partialStashLeft = minLeft - bounds.width() - pipAreaPadding
val rightPosition = stashCandidates[1] val leftPosition = Rect(bounds)
rightPosition.offsetTo(max(fullStashLeft, partialStashLeft), bounds.top) leftPosition.offsetTo(max(fullStashLeft, partialStashLeft), bounds.top)
stashCandidates += leftPosition
}
if (stashCandidates.isEmpty()) {
return bounds
} }
return stashCandidates.minByOrNull { return stashCandidates.minByOrNull {