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

Commit c4c1add2 authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[60/n] Improve letterbox surfaces bounds calculation" into main

parents 35330480 4111bb2c
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -28,16 +28,20 @@ class TaskInfoLetterboxLifecycleEventFactory : LetterboxLifecycleEventFactory {

    override fun createLifecycleEvent(change: Change): LetterboxLifecycleEvent? {
        change.taskInfo?.let { ti ->
            val taskBounds = Rect(
                change.endRelOffset.x,
                change.endRelOffset.y,
                change.endAbsBounds.width(),
                change.endAbsBounds.height()
            )
            val isLetterboxed = ti.appCompatTaskInfo?.isTopActivityLetterboxed ?: false
            val taskBoundsAbs = change.endAbsBounds
            // The bounds are absolute to the screen but we need them relative to the Task.
            val taskBounds = Rect(taskBoundsAbs).apply {
                offset(-taskBoundsAbs.left, -taskBoundsAbs.top)
            }
            // Letterbox bounds are null when the activity is not letterboxed.
            val letterboxBounds =
            val letterboxBoundsAbs =
                if (isLetterboxed) ti.appCompatTaskInfo?.topActivityLetterboxBounds else null
            val letterboxBounds = letterboxBoundsAbs?.let { absBounds ->
                Rect(absBounds).apply {
                    offset(-taskBoundsAbs.left, -taskBoundsAbs.top)
                }
            }
            return LetterboxLifecycleEvent(
                type = change.asLetterboxLifecycleEventType(),
                displayId = ti.displayId,
+6 −9
Original line number Diff line number Diff line
@@ -56,19 +56,18 @@ class TaskInfoLetterboxLifecycleEventFactoryTest {
    }

    @Test
    fun `With TaskInfo taskBounds are calculated from endAbsBounds and endRelOffset`() {
    fun `With TaskInfo taskBounds are calculated from endAbsBounds`() {
        runTestScenario { r ->
            testLetterboxLifecycleEventFactory(r.getLetterboxLifecycleEventFactory()) {
                inputChange {
                    endAbsBounds = Rect(0, 0, 500, 1000)
                    endRelOffset = Point(100, 200)
                    endAbsBounds = Rect(100, 200, 2000, 1000)
                }
                validateCanHandle { canHandle ->
                    assert(canHandle == true)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assert(event?.taskBounds == Rect(100, 200, 500, 1000))
                    assert(event?.taskBounds == Rect(0, 0, 1900, 1800))
                }
            }
        }
@@ -83,7 +82,6 @@ class TaskInfoLetterboxLifecycleEventFactoryTest {
                        ti.appCompatTaskInfo.isTopActivityLetterboxed = false
                    }
                    endAbsBounds = Rect(0, 0, 500, 1000)
                    endRelOffset = Point(100, 200)
                }
                validateCanHandle { canHandle ->
                    assert(canHandle == true)
@@ -103,17 +101,16 @@ class TaskInfoLetterboxLifecycleEventFactoryTest {
                inputChange {
                    runningTaskInfo { ti ->
                        ti.appCompatTaskInfo.isTopActivityLetterboxed = true
                        ti.appCompatTaskInfo.topActivityLetterboxBounds = Rect(1, 2, 3, 4)
                        ti.appCompatTaskInfo.topActivityLetterboxBounds = Rect(300, 200, 2300, 1200)
                    }
                    endAbsBounds = Rect(0, 0, 500, 1000)
                    endRelOffset = Point(100, 200)
                    endAbsBounds = Rect(100, 50, 2500, 1500)
                }
                validateCanHandle { canHandle ->
                    assert(canHandle == true)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assert(event?.letterboxBounds == Rect(1, 2, 3, 4))
                    assert(event?.letterboxBounds == Rect(200, 150, 2400, 1150))
                }
            }
        }