Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 536be689 authored by Galia Peycheva's avatar Galia Peycheva Committed by Automerger Merge Worker
Browse files

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

parents 84d46c31 42718971
Loading
Loading
Loading
Loading
+11 −7
Original line number Original line Diff line number Diff line
@@ -133,7 +133,8 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
        val pipAnchorBoundsWithAllDecors =
        val pipAnchorBoundsWithAllDecors =
                getNormalPipAnchorBounds(pipSizeWithAllDecors, transformedMovementBounds)
                getNormalPipAnchorBounds(pipSizeWithAllDecors, transformedMovementBounds)


        val pipAnchorBoundsWithPermanentDecors = removeTemporaryDecors(pipAnchorBoundsWithAllDecors)
        val pipAnchorBoundsWithPermanentDecors =
                removeTemporaryDecorsTransformed(pipAnchorBoundsWithAllDecors)
        val result = calculatePipPositionTransformed(
        val result = calculatePipPositionTransformed(
            pipAnchorBoundsWithPermanentDecors,
            pipAnchorBoundsWithPermanentDecors,
            transformedRestrictedAreas,
            transformedRestrictedAreas,
@@ -471,12 +472,10 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {
    }
    }


    fun setPipPermanentDecorInsets(insets: Insets) {
    fun setPipPermanentDecorInsets(insets: Insets) {
        if (pipPermanentDecorInsets == insets) return
        pipPermanentDecorInsets = insets
        pipPermanentDecorInsets = insets
    }
    }


    fun setPipTemporaryDecorInsets(insets: Insets) {
    fun setPipTemporaryDecorInsets(insets: Insets) {
        if (pipTemporaryDecorInsets == insets) return
        pipTemporaryDecorInsets = insets
        pipTemporaryDecorInsets = insets
    }
    }


@@ -781,6 +780,7 @@ class TvPipKeepClearAlgorithm(private val clock: () -> Long) {


    /**
    /**
     * Removes the space that was reserved for permanent decorations around the pip
     * 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 {
    private fun removePermanentDecors(bounds: Rect): Rect {
        val pipDecorReverseInsets = Insets.subtract(Insets.NONE, pipPermanentDecorInsets)
        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
     * 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 {
    private fun removeTemporaryDecorsTransformed(bounds: Rect): Rect {
        val pipDecorReverseInsets = Insets.subtract(Insets.NONE, pipTemporaryDecorInsets)
        if (pipTemporaryDecorInsets == Insets.NONE) return bounds
        bounds.inset(pipDecorReverseInsets)

        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) }
    private fun Rect.offsetCopy(dx: Int, dy: Int) = Rect(this).apply { offset(dx, dy) }
+59 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.wm.shell.pip.tv
package com.android.wm.shell.pip.tv


import android.graphics.Insets
import android.graphics.Rect
import android.graphics.Rect
import android.testing.AndroidTestingRunner
import android.testing.AndroidTestingRunner
import android.util.Size
import android.util.Size
@@ -432,6 +433,64 @@ class TvPipKeepClearAlgorithmTest {
        assertEquals(currentTime + algorithm.stashDuration, placement.unstashTime)
        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 {
    private fun makeSideBar(width: Int, @Gravity.GravityFlags side: Int): Rect {
        val sidebar = Rect(0, 0, width, SCREEN_SIZE.height)
        val sidebar = Rect(0, 0, width, SCREEN_SIZE.height)
        if (side == Gravity.RIGHT) {
        if (side == Gravity.RIGHT) {