Apply PreviewPositionHelper matrix to TTV and Overlay
- Added GetThumbnailMatrixUseCase to retrieve task using taskId and calcualte Matrix using provided canvas size and isRTL - TTVM and OverlayVM will uses GetThumbnailMatrixUseCaseTest with runBlocking to obtain the matrix from the loaded thumbnail - TTV and Overlay listen for size change, and call VM to get the latest Matrix and apply to the view Fix: 343101424 Test: GetThumbnailMatrixUseCaseTest Test: TaskThumbnailViewModelTest Test: TaskOverlayViewModelTest Flag: com.android.launcher3.enable_refactor_task_thumbnail Change-Id: If3f37824bed84d5cbaa54d7a4b12f5f1ef4e2c09
This commit is contained in:
1 parent
fd7499bb82
commit
893f4c6a45
16 files changed
+427
-57
No files matched your search
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.quickstep.recents.usecase
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Rect
|
||||
import android.view.Surface.ROTATION_90
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.quickstep.recents.data.FakeTasksRepository
|
||||
import com.android.quickstep.recents.data.RecentsDeviceProfileRepository
|
||||
import com.android.quickstep.recents.data.RecentsRotationStateRepository
|
||||
import com.android.quickstep.recents.usecase.ThumbnailPositionState.MatrixScaling
|
||||
import com.android.quickstep.recents.usecase.ThumbnailPositionState.MissingThumbnail
|
||||
import com.android.systemui.shared.recents.model.Task
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import com.android.systemui.shared.recents.utilities.PreviewPositionHelper
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.verify
|
||||
import org.mockito.kotlin.whenever
|
||||
|
||||
/** Test for [GetThumbnailPositionUseCase] */
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class GetThumbnailPositionUseCaseTest {
|
||||
private val task =
|
||||
Task(Task.TaskKey(TASK_ID, 0, Intent(), ComponentName("", ""), 0, 2000)).apply {
|
||||
colorBackground = Color.BLACK
|
||||
}
|
||||
private val thumbnailData =
|
||||
ThumbnailData(
|
||||
thumbnail =
|
||||
mock<Bitmap>().apply {
|
||||
whenever(width).thenReturn(THUMBNAIL_WIDTH)
|
||||
whenever(height).thenReturn(THUMBNAIL_HEIGHT)
|
||||
}
|
||||
)
|
||||
|
||||
private val deviceProfileRepository = mock<RecentsDeviceProfileRepository>()
|
||||
private val rotationStateRepository = mock<RecentsRotationStateRepository>()
|
||||
private val tasksRepository = FakeTasksRepository()
|
||||
private val previewPositionHelper = mock<PreviewPositionHelper>()
|
||||
|
||||
private val systemUnderTest =
|
||||
GetThumbnailPositionUseCase(
|
||||
deviceProfileRepository,
|
||||
rotationStateRepository,
|
||||
tasksRepository,
|
||||
previewPositionHelper
|
||||
)
|
||||
|
||||
@Test
|
||||
fun invisibleTask_returnsIdentityMatrix() = runTest {
|
||||
tasksRepository.seedTasks(listOf(task))
|
||||
|
||||
assertThat(systemUnderTest.run(TASK_ID, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl = true))
|
||||
.isInstanceOf(MissingThumbnail::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visibleTaskWithoutThumbnailData_returnsIdentityMatrix() = runTest {
|
||||
tasksRepository.seedTasks(listOf(task))
|
||||
tasksRepository.setVisibleTasks(listOf(TASK_ID))
|
||||
|
||||
assertThat(systemUnderTest.run(TASK_ID, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl = true))
|
||||
.isInstanceOf(MissingThumbnail::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visibleTaskWithThumbnailData_returnsTransformedMatrix() = runTest {
|
||||
tasksRepository.seedThumbnailData(mapOf(TASK_ID to thumbnailData))
|
||||
tasksRepository.seedTasks(listOf(task))
|
||||
tasksRepository.setVisibleTasks(listOf(TASK_ID))
|
||||
|
||||
val isLargeScreen = true
|
||||
val activityRotation = ROTATION_90
|
||||
val isRtl = true
|
||||
val isRotated = true
|
||||
|
||||
whenever(deviceProfileRepository.getRecentsDeviceProfile())
|
||||
.thenReturn(RecentsDeviceProfileRepository.RecentsDeviceProfile(isLargeScreen))
|
||||
whenever(rotationStateRepository.getRecentsRotationState())
|
||||
.thenReturn(RecentsRotationStateRepository.RecentsRotationState(activityRotation))
|
||||
|
||||
whenever(previewPositionHelper.matrix).thenReturn(MATRIX)
|
||||
whenever(previewPositionHelper.isOrientationChanged).thenReturn(isRotated)
|
||||
|
||||
assertThat(systemUnderTest.run(TASK_ID, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.isEqualTo(MatrixScaling(MATRIX, isRotated))
|
||||
|
||||
verify(previewPositionHelper)
|
||||
.updateThumbnailMatrix(
|
||||
Rect(0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT),
|
||||
thumbnailData,
|
||||
CANVAS_WIDTH,
|
||||
CANVAS_HEIGHT,
|
||||
isLargeScreen,
|
||||
activityRotation,
|
||||
isRtl
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TASK_ID = 2
|
||||
const val THUMBNAIL_WIDTH = 100
|
||||
const val THUMBNAIL_HEIGHT = 200
|
||||
const val CANVAS_WIDTH = 300
|
||||
const val CANVAS_HEIGHT = 600
|
||||
val MATRIX =
|
||||
Matrix().apply {
|
||||
setValues(floatArrayOf(2.3f, 4.5f, 2.6f, 7.4f, 3.4f, 2.3f, 2.5f, 6.0f, 3.4f))
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.quickstep.task.util
|
||||
package com.android.quickstep.recents.usecase
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
+46
-4
@@ -20,9 +20,12 @@ import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.graphics.Matrix
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.quickstep.recents.data.FakeTasksRepository
|
||||
import com.android.quickstep.recents.usecase.GetThumbnailPositionUseCase
|
||||
import com.android.quickstep.recents.usecase.ThumbnailPositionState.MatrixScaling
|
||||
import com.android.quickstep.recents.usecase.ThumbnailPositionState.MissingThumbnail
|
||||
import com.android.quickstep.recents.viewmodel.RecentsViewData
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.BackgroundOnly
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.LiveTile
|
||||
@@ -48,8 +51,15 @@ class TaskThumbnailViewModelTest {
|
||||
private val taskViewData by lazy { TaskViewData(taskViewType) }
|
||||
private val taskContainerData = TaskContainerData()
|
||||
private val tasksRepository = FakeTasksRepository()
|
||||
private val mGetThumbnailPositionUseCase = mock<GetThumbnailPositionUseCase>()
|
||||
private val systemUnderTest by lazy {
|
||||
TaskThumbnailViewModel(recentsViewData, taskViewData, taskContainerData, tasksRepository)
|
||||
TaskThumbnailViewModel(
|
||||
recentsViewData,
|
||||
taskViewData,
|
||||
taskContainerData,
|
||||
tasksRepository,
|
||||
mGetThumbnailPositionUseCase
|
||||
)
|
||||
}
|
||||
|
||||
private val tasks = (0..5).map(::createTaskWithId)
|
||||
@@ -149,7 +159,6 @@ class TaskThumbnailViewModelTest {
|
||||
Snapshot(
|
||||
backgroundColor = Color.rgb(2, 2, 2),
|
||||
bitmap = expectedThumbnailData.thumbnail!!,
|
||||
drawnRect = Rect(0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -170,11 +179,38 @@ class TaskThumbnailViewModelTest {
|
||||
Snapshot(
|
||||
backgroundColor = Color.rgb(2, 2, 2),
|
||||
bitmap = expectedThumbnailData.thumbnail!!,
|
||||
drawnRect = Rect(0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSnapshotMatrix_MissingThumbnail() = runTest {
|
||||
val taskId = 2
|
||||
val recentTask = TaskThumbnail(taskId = taskId, isRunning = false)
|
||||
val isRtl = true
|
||||
|
||||
whenever(mGetThumbnailPositionUseCase.run(taskId, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.thenReturn(MissingThumbnail)
|
||||
|
||||
systemUnderTest.bind(recentTask)
|
||||
assertThat(systemUnderTest.getThumbnailPositionState(CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.isEqualTo(Matrix.IDENTITY_MATRIX)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSnapshotMatrix_MatrixScaling() = runTest {
|
||||
val taskId = 2
|
||||
val recentTask = TaskThumbnail(taskId = taskId, isRunning = false)
|
||||
val isRtl = true
|
||||
|
||||
whenever(mGetThumbnailPositionUseCase.run(taskId, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.thenReturn(MatrixScaling(MATRIX, isRotated = false))
|
||||
|
||||
systemUnderTest.bind(recentTask)
|
||||
assertThat(systemUnderTest.getThumbnailPositionState(CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.isEqualTo(MATRIX)
|
||||
}
|
||||
|
||||
private fun createTaskWithId(taskId: Int) =
|
||||
Task(Task.TaskKey(taskId, 0, Intent(), ComponentName("", ""), 0, 2000)).apply {
|
||||
colorBackground = Color.argb(taskId, taskId, taskId, taskId)
|
||||
@@ -191,5 +227,11 @@ class TaskThumbnailViewModelTest {
|
||||
companion object {
|
||||
const val THUMBNAIL_WIDTH = 100
|
||||
const val THUMBNAIL_HEIGHT = 200
|
||||
const val CANVAS_WIDTH = 300
|
||||
const val CANVAS_HEIGHT = 600
|
||||
val MATRIX =
|
||||
Matrix().apply {
|
||||
setValues(floatArrayOf(2.3f, 4.5f, 2.6f, 7.4f, 3.4f, 2.3f, 2.5f, 6.0f, 3.4f))
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-5
@@ -23,9 +23,13 @@ import android.graphics.Color
|
||||
import android.graphics.Matrix
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.quickstep.recents.data.FakeTasksRepository
|
||||
import com.android.quickstep.recents.usecase.GetThumbnailPositionUseCase
|
||||
import com.android.quickstep.recents.usecase.ThumbnailPositionState.MatrixScaling
|
||||
import com.android.quickstep.recents.usecase.ThumbnailPositionState.MissingThumbnail
|
||||
import com.android.quickstep.recents.viewmodel.RecentsViewData
|
||||
import com.android.quickstep.task.thumbnail.TaskOverlayUiState.Disabled
|
||||
import com.android.quickstep.task.thumbnail.TaskOverlayUiState.Enabled
|
||||
import com.android.quickstep.task.viewmodel.TaskOverlayViewModel.ThumbnailPositionState
|
||||
import com.android.systemui.shared.recents.model.Task
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
@@ -53,7 +57,9 @@ class TaskOverlayViewModelTest {
|
||||
)
|
||||
private val recentsViewData = RecentsViewData()
|
||||
private val tasksRepository = FakeTasksRepository()
|
||||
private val systemUnderTest = TaskOverlayViewModel(task, recentsViewData, tasksRepository)
|
||||
private val mGetThumbnailPositionUseCase = mock<GetThumbnailPositionUseCase>()
|
||||
private val systemUnderTest =
|
||||
TaskOverlayViewModel(task, recentsViewData, tasksRepository, mGetThumbnailPositionUseCase)
|
||||
|
||||
@Test
|
||||
fun initialStateIsDisabled() = runTest {
|
||||
@@ -87,7 +93,6 @@ class TaskOverlayViewModelTest {
|
||||
Enabled(
|
||||
isRealSnapshot = false,
|
||||
thumbnail = null,
|
||||
thumbnailMatrix = Matrix.IDENTITY_MATRIX
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -107,7 +112,6 @@ class TaskOverlayViewModelTest {
|
||||
Enabled(
|
||||
isRealSnapshot = true,
|
||||
thumbnail = thumbnailData.thumbnail,
|
||||
thumbnailMatrix = Matrix.IDENTITY_MATRIX
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -127,7 +131,6 @@ class TaskOverlayViewModelTest {
|
||||
Enabled(
|
||||
isRealSnapshot = false,
|
||||
thumbnail = thumbnailData.thumbnail,
|
||||
thumbnailMatrix = Matrix.IDENTITY_MATRIX
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -147,14 +150,42 @@ class TaskOverlayViewModelTest {
|
||||
Enabled(
|
||||
isRealSnapshot = false,
|
||||
thumbnail = thumbnailData.thumbnail,
|
||||
thumbnailMatrix = Matrix.IDENTITY_MATRIX
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getThumbnailMatrix_MissingThumbnail() = runTest {
|
||||
val isRtl = true
|
||||
|
||||
whenever(mGetThumbnailPositionUseCase.run(TASK_ID, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.thenReturn(MissingThumbnail)
|
||||
|
||||
assertThat(systemUnderTest.getThumbnailPositionState(CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.isEqualTo(ThumbnailPositionState(Matrix.IDENTITY_MATRIX, isRotated = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getThumbnailMatrix_MatrixScaling() = runTest {
|
||||
val isRtl = true
|
||||
val isRotated = true
|
||||
|
||||
whenever(mGetThumbnailPositionUseCase.run(TASK_ID, CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.thenReturn(MatrixScaling(MATRIX, isRotated))
|
||||
|
||||
assertThat(systemUnderTest.getThumbnailPositionState(CANVAS_WIDTH, CANVAS_HEIGHT, isRtl))
|
||||
.isEqualTo(ThumbnailPositionState(MATRIX, isRotated))
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TASK_ID = 0
|
||||
const val THUMBNAIL_WIDTH = 100
|
||||
const val THUMBNAIL_HEIGHT = 200
|
||||
const val CANVAS_WIDTH = 300
|
||||
const val CANVAS_HEIGHT = 600
|
||||
val MATRIX =
|
||||
Matrix().apply {
|
||||
setValues(floatArrayOf(2.3f, 4.5f, 2.6f, 7.4f, 3.4f, 2.3f, 2.5f, 6.0f, 3.4f))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user