Loading libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterbox/lifecycle/TaskInfoLetterboxLifecycleEventFactory.kt +11 −7 Original line number Diff line number Diff line Loading @@ -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, Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/letterbox/lifecycle/TaskInfoLetterboxLifecycleEventFactoryTest.kt +6 −9 Original line number Diff line number Diff line Loading @@ -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)) } } } Loading @@ -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) Loading @@ -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)) } } } Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterbox/lifecycle/TaskInfoLetterboxLifecycleEventFactory.kt +11 −7 Original line number Diff line number Diff line Loading @@ -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, Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/letterbox/lifecycle/TaskInfoLetterboxLifecycleEventFactoryTest.kt +6 −9 Original line number Diff line number Diff line Loading @@ -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)) } } } Loading @@ -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) Loading @@ -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)) } } } Loading