From f1c14902ca0376e088cfa78aabc5c89a5b18fcad Mon Sep 17 00:00:00 2001 From: Uwais Ashraf Date: Tue, 20 Aug 2024 10:08:05 +0000 Subject: [PATCH 1/2] Fix splash icon size to 52dp Fix: 360804090 Test: presubmits passing, manual Flag: com.android.launcher3.enable_refactor_task_thumbnail Change-Id: I1bc14be7d2d25a985d26709eb59b8aa4887d4764 --- quickstep/res/layout/task_thumbnail.xml | 29 ++++--- quickstep/res/values/dimens.xml | 2 + .../recents/data/RecentsDeviceProfile.kt | 2 - .../RecentsDeviceProfileRepositoryImpl.kt | 4 +- .../recents/di/RecentsDependencies.kt | 8 -- .../task/thumbnail/GetSplashSizeUseCase.kt | 46 ---------- .../task/thumbnail/TaskThumbnailUiState.kt | 8 +- .../task/thumbnail/TaskThumbnailView.kt | 30 +++---- .../task/thumbnail/TaskThumbnailViewData.kt | 2 - .../task/viewmodel/TaskThumbnailViewModel.kt | 12 +-- .../quickstep/task/viewmodel/TaskViewData.kt | 2 - .../quickstep/task/viewmodel/TaskViewModel.kt | 4 - .../com/android/quickstep/views/TaskView.kt | 3 - .../FakeRecentsDeviceProfileRepository.kt | 2 - .../RecentsDeviceProfileRepositoryImplTest.kt | 2 +- .../thumbnail/GetSplashSizeUseCaseTest.kt | 84 ------------------- .../thumbnail/TaskThumbnailViewModelTest.kt | 34 +------- res/values/dimens.xml | 1 + 18 files changed, 41 insertions(+), 234 deletions(-) delete mode 100644 quickstep/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCase.kt delete mode 100644 quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCaseTest.kt diff --git a/quickstep/res/layout/task_thumbnail.xml b/quickstep/res/layout/task_thumbnail.xml index 784a094669..6ca501234e 100644 --- a/quickstep/res/layout/task_thumbnail.xml +++ b/quickstep/res/layout/task_thumbnail.xml @@ -15,8 +15,9 @@ --> + android:layout_height="match_parent" > - - - + android:alpha="0" + android:importantForAccessibility="no" /> + + \ No newline at end of file diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 867ce1769d..e6911341dc 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -41,6 +41,8 @@ 48dp 44dp + + 52dp 4dp diff --git a/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfile.kt b/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfile.kt index feed2fdf41..d2cb595586 100644 --- a/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfile.kt +++ b/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfile.kt @@ -23,6 +23,4 @@ package com.android.quickstep.recents.data */ data class RecentsDeviceProfile( val isLargeScreen: Boolean, - val widthPx: Int, - val heightPx: Int, ) diff --git a/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImpl.kt b/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImpl.kt index ce39ff1b53..c64453d0cd 100644 --- a/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImpl.kt +++ b/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImpl.kt @@ -26,7 +26,5 @@ class RecentsDeviceProfileRepositoryImpl(private val container: RecentsViewConta RecentsDeviceProfileRepository { override fun getRecentsDeviceProfile() = - with(container.deviceProfile) { - RecentsDeviceProfile(isLargeScreen = isTablet, widthPx = widthPx, heightPx = heightPx) - } + with(container.deviceProfile) { RecentsDeviceProfile(isLargeScreen = isTablet) } } diff --git a/quickstep/src/com/android/quickstep/recents/di/RecentsDependencies.kt b/quickstep/src/com/android/quickstep/recents/di/RecentsDependencies.kt index d8156b1811..0b672d1b94 100644 --- a/quickstep/src/com/android/quickstep/recents/di/RecentsDependencies.kt +++ b/quickstep/src/com/android/quickstep/recents/di/RecentsDependencies.kt @@ -27,7 +27,6 @@ import com.android.quickstep.recents.usecase.GetThumbnailPositionUseCase import com.android.quickstep.recents.usecase.GetThumbnailUseCase import com.android.quickstep.recents.usecase.SysUiStatusNavFlagsUseCase import com.android.quickstep.recents.viewmodel.RecentsViewData -import com.android.quickstep.task.thumbnail.GetSplashSizeUseCase import com.android.quickstep.task.thumbnail.SplashAlphaUseCase import com.android.quickstep.task.thumbnail.TaskThumbnailViewData import com.android.quickstep.task.viewmodel.TaskContainerData @@ -176,7 +175,6 @@ class RecentsDependencies private constructor(private val appContext: Context) { getThumbnailPositionUseCase = inject(), tasksRepository = inject(), splashAlphaUseCase = inject(scopeId), - getSplashSizeUseCase = inject(scopeId), ) TaskOverlayViewModel::class.java -> { val task = extras["Task"] as Task @@ -204,12 +202,6 @@ class RecentsDependencies private constructor(private val appContext: Context) { tasksRepository = inject(), rotationStateRepository = inject(), ) - GetSplashSizeUseCase::class.java -> - GetSplashSizeUseCase( - taskThumbnailViewData = inject(scopeId), - taskViewData = inject(scopeId, extras), - deviceProfileRepository = inject(), - ) else -> { log("Factory for ${modelClass.simpleName} not defined!", Log.ERROR) error("Factory for ${modelClass.simpleName} not defined!") diff --git a/quickstep/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCase.kt b/quickstep/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCase.kt deleted file mode 100644 index 145957a618..0000000000 --- a/quickstep/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCase.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.task.thumbnail - -import android.graphics.Point -import android.graphics.drawable.Drawable -import com.android.quickstep.recents.data.RecentsDeviceProfileRepository -import com.android.quickstep.task.viewmodel.TaskViewData -import kotlin.math.min - -class GetSplashSizeUseCase( - private val taskThumbnailViewData: TaskThumbnailViewData, - private val taskViewData: TaskViewData, - private val deviceProfileRepository: RecentsDeviceProfileRepository, -) { - fun execute(splashImage: Drawable): Point { - val recentsDeviceProfile = deviceProfileRepository.getRecentsDeviceProfile() - val screenWidth = recentsDeviceProfile.widthPx - val screenHeight = recentsDeviceProfile.heightPx - val scaleAtFullscreen = - min( - screenWidth / taskThumbnailViewData.width.value, - screenHeight / taskThumbnailViewData.height.value, - ) - val scaleFactor: Float = 1f / taskViewData.nonGridScale.value / scaleAtFullscreen - return Point( - (splashImage.intrinsicWidth * scaleFactor / taskThumbnailViewData.scaleX.value).toInt(), - (splashImage.intrinsicHeight * scaleFactor / taskThumbnailViewData.scaleY.value) - .toInt(), - ) - } -} diff --git a/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailUiState.kt b/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailUiState.kt index a6be9f6ab9..36a86f2526 100644 --- a/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailUiState.kt +++ b/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailUiState.kt @@ -17,7 +17,6 @@ package com.android.quickstep.task.thumbnail import android.graphics.Bitmap -import android.graphics.Point import android.graphics.drawable.Drawable import android.view.Surface import androidx.annotation.ColorInt @@ -31,7 +30,7 @@ sealed class TaskThumbnailUiState { data class SnapshotSplash( val snapshot: Snapshot, - val splash: Splash, + val splash: Drawable?, ) : TaskThumbnailUiState() data class Snapshot( @@ -39,9 +38,4 @@ sealed class TaskThumbnailUiState { @Surface.Rotation val thumbnailRotation: Int, @ColorInt val backgroundColor: Int ) - - data class Splash( - val icon: Drawable?, - val size: Point, - ) } diff --git a/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailView.kt b/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailView.kt index 41aee52e4a..b3ae3d2ce7 100644 --- a/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailView.kt +++ b/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailView.kt @@ -24,11 +24,10 @@ import android.graphics.Rect import android.util.AttributeSet import android.view.View import android.view.ViewOutlineProvider -import android.widget.FrameLayout import android.widget.ImageView import androidx.annotation.ColorInt +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isVisible -import androidx.core.view.updateLayoutParams import com.android.launcher3.R import com.android.launcher3.Utilities import com.android.launcher3.util.ViewPool @@ -51,7 +50,7 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -class TaskThumbnailView : FrameLayout, ViewPool.Reusable { +class TaskThumbnailView : ConstraintLayout, ViewPool.Reusable { private val viewData: TaskThumbnailViewData by RecentsDependencies.inject(this) private val viewModel: TaskThumbnailViewModel by RecentsDependencies.inject(this) @@ -61,7 +60,7 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable { private val scrimView: View by lazy { findViewById(R.id.task_thumbnail_scrim) } private val liveTileView: LiveTileView by lazy { findViewById(R.id.task_thumbnail_live_tile) } private val thumbnailView: ImageView by lazy { findViewById(R.id.task_thumbnail) } - private val splashContainer: FrameLayout by lazy { findViewById(R.id.splash_container) } + private val splashBackground: View by lazy { findViewById(R.id.splash_background) } private val splashIcon: ImageView by lazy { findViewById(R.id.splash_icon) } private var uiState: TaskThumbnailUiState = Uninitialized @@ -107,7 +106,10 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable { .onEach { dimProgress -> scrimView.alpha = dimProgress } .launchIn(viewAttachedScope) viewModel.splashAlpha - .onEach { splashAlpha -> splashContainer.alpha = splashAlpha } + .onEach { splashAlpha -> + splashBackground.alpha = splashAlpha + splashIcon.alpha = splashAlpha + } .launchIn(viewAttachedScope) viewModel.cornerRadiusProgress.onEach { invalidateOutline() }.launchIn(viewAttachedScope) viewModel.inheritedScale @@ -152,15 +154,13 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable { override fun setScaleX(scaleX: Float) { super.setScaleX(scaleX) - viewData.scaleX.value = scaleX - // Splash icon should ignore scale + // Splash icon should ignore scale on TTV splashIcon.scaleX = 1 / scaleX } override fun setScaleY(scaleY: Float) { super.setScaleY(scaleY) - viewData.scaleY.value = scaleY - // Splash icon should ignore scale + // Splash icon should ignore scale on TTV splashIcon.scaleY = 1 / scaleY } @@ -175,7 +175,8 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable { private fun resetViews() { liveTileView.isVisible = false thumbnailView.isVisible = false - splashContainer.alpha = 0f + splashBackground.alpha = 0f + splashIcon.alpha = 0f scrimView.alpha = 0f setBackgroundColor(Color.BLACK) } @@ -191,13 +192,8 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable { private fun drawSnapshotSplash(snapshotSplash: SnapshotSplash) { drawSnapshot(snapshotSplash.snapshot) - splashContainer.isVisible = true - splashContainer.setBackgroundColor(snapshotSplash.snapshot.backgroundColor) - splashIcon.setImageDrawable(snapshotSplash.splash.icon) - splashIcon.updateLayoutParams { - width = snapshotSplash.splash.size.x - height = snapshotSplash.splash.size.y - } + splashBackground.setBackgroundColor(snapshotSplash.snapshot.backgroundColor) + splashIcon.setImageDrawable(snapshotSplash.splash) } private fun drawSnapshot(snapshot: Snapshot) { diff --git a/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewData.kt b/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewData.kt index 1f8c0bc0d5..35020294b0 100644 --- a/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewData.kt +++ b/quickstep/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewData.kt @@ -21,6 +21,4 @@ import kotlinx.coroutines.flow.MutableStateFlow class TaskThumbnailViewData { val width = MutableStateFlow(0) val height = MutableStateFlow(0) - val scaleX = MutableStateFlow(1f) - val scaleY = MutableStateFlow(1f) } diff --git a/quickstep/src/com/android/quickstep/task/viewmodel/TaskThumbnailViewModel.kt b/quickstep/src/com/android/quickstep/task/viewmodel/TaskThumbnailViewModel.kt index 4e29840dab..b1bb65e85e 100644 --- a/quickstep/src/com/android/quickstep/task/viewmodel/TaskThumbnailViewModel.kt +++ b/quickstep/src/com/android/quickstep/task/viewmodel/TaskThumbnailViewModel.kt @@ -19,20 +19,17 @@ package com.android.quickstep.task.viewmodel import android.annotation.ColorInt import android.app.ActivityTaskManager.INVALID_TASK_ID import android.graphics.Matrix -import android.graphics.Point import androidx.core.graphics.ColorUtils import com.android.quickstep.recents.data.RecentTasksRepository import com.android.quickstep.recents.usecase.GetThumbnailPositionUseCase import com.android.quickstep.recents.usecase.ThumbnailPositionState import com.android.quickstep.recents.viewmodel.RecentsViewData -import com.android.quickstep.task.thumbnail.GetSplashSizeUseCase import com.android.quickstep.task.thumbnail.SplashAlphaUseCase import com.android.quickstep.task.thumbnail.TaskThumbnailUiState import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.BackgroundOnly import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.LiveTile import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Snapshot import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.SnapshotSplash -import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Splash import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Uninitialized import com.android.systemui.shared.recents.model.Task import kotlin.math.max @@ -55,7 +52,6 @@ class TaskThumbnailViewModel( private val tasksRepository: RecentTasksRepository, private val getThumbnailPositionUseCase: GetThumbnailPositionUseCase, private val splashAlphaUseCase: SplashAlphaUseCase, - private val getSplashSizeUseCase: GetSplashSizeUseCase, ) { private val task = MutableStateFlow>(flowOf(null)) private val splashProgress = MutableStateFlow(flowOf(0f)) @@ -100,7 +96,7 @@ class TaskThumbnailViewModel( isBackgroundOnly(taskVal) -> BackgroundOnly(taskVal.colorBackground.removeAlpha()) isSnapshotSplashState(taskVal) -> - SnapshotSplash(createSnapshotState(taskVal), createSplashState(taskVal)) + SnapshotSplash(createSnapshotState(taskVal), taskVal.icon) else -> Uninitialized } } @@ -139,12 +135,6 @@ class TaskThumbnailViewModel( return Snapshot(bitmap, thumbnailData.rotation, task.colorBackground.removeAlpha()) } - private fun createSplashState(task: Task): Splash { - val taskIcon = task.icon - val size = if (taskIcon == null) Point() else getSplashSizeUseCase.execute(taskIcon) - return Splash(taskIcon, size) - } - @ColorInt private fun Int.removeAlpha(): Int = ColorUtils.setAlphaComponent(this, 0xff) private companion object { diff --git a/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewData.kt b/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewData.kt index 07dfc29585..7a9ecf2426 100644 --- a/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewData.kt +++ b/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewData.kt @@ -23,8 +23,6 @@ class TaskViewData(taskViewType: TaskViewType) { // This is typically a View concern but it is used to invalidate rendering in other Views val scale = MutableStateFlow(1f) - val nonGridScale = MutableStateFlow(1f) - // TODO(b/331753115): This property should not be in TaskViewData once TaskView is MVVM. /** Whether outline of TaskView is formed by outline thumbnail view(s). */ val isOutlineFormedByThumbnailView: Boolean = taskViewType != TaskViewType.DESKTOP diff --git a/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewModel.kt b/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewModel.kt index 30ee360e4f..ec75d59c34 100644 --- a/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewModel.kt +++ b/quickstep/src/com/android/quickstep/task/viewmodel/TaskViewModel.kt @@ -22,8 +22,4 @@ class TaskViewModel(private val taskViewData: TaskViewData) : ViewModel() { fun updateScale(scale: Float) { taskViewData.scale.value = scale } - - fun updateNonGridScale(nonGridScale: Float) { - taskViewData.nonGridScale.value = nonGridScale - } } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 176a538d48..7be73a32dd 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -290,9 +290,6 @@ constructor( set(value) { field = value applyScale() - if (enableRefactorTaskThumbnail()) { - taskViewModel.updateNonGridScale(value) - } } private var dismissScale = 1f diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeRecentsDeviceProfileRepository.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeRecentsDeviceProfileRepository.kt index cdfbd16c09..fc2f029419 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeRecentsDeviceProfileRepository.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeRecentsDeviceProfileRepository.kt @@ -20,8 +20,6 @@ class FakeRecentsDeviceProfileRepository : RecentsDeviceProfileRepository { private var recentsDeviceProfile = RecentsDeviceProfile( isLargeScreen = false, - widthPx = 1080, - heightPx = 1920, ) override fun getRecentsDeviceProfile() = recentsDeviceProfile diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImplTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImplTest.kt index e74fe4bf1d..abe414238d 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImplTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryImplTest.kt @@ -39,6 +39,6 @@ class RecentsDeviceProfileRepositoryImplTest : FakeInvariantDeviceProfileTest() whenever(recentsViewContainer.deviceProfile).thenReturn(tabletDeviceProfile) assertThat(systemUnderTest.getRecentsDeviceProfile()) - .isEqualTo(RecentsDeviceProfile(isLargeScreen = true, widthPx = 1600, heightPx = 2560)) + .isEqualTo(RecentsDeviceProfile(isLargeScreen = true)) } } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCaseTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCaseTest.kt deleted file mode 100644 index 13e8b09b8e..0000000000 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/GetSplashSizeUseCaseTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.task.thumbnail - -import android.graphics.Point -import android.graphics.drawable.Drawable -import com.android.quickstep.recents.data.FakeRecentsDeviceProfileRepository -import com.android.quickstep.task.viewmodel.TaskViewData -import com.android.quickstep.views.TaskViewType -import com.google.common.truth.Truth.assertThat -import org.junit.Test -import org.mockito.kotlin.mock -import org.mockito.kotlin.whenever - -class GetSplashSizeUseCaseTest { - private val taskThumbnailViewData = TaskThumbnailViewData() - private val taskViewData = TaskViewData(TaskViewType.SINGLE) - private val recentsDeviceProfileRepository = FakeRecentsDeviceProfileRepository() - private val systemUnderTest = - GetSplashSizeUseCase(taskThumbnailViewData, taskViewData, recentsDeviceProfileRepository) - - @Test - fun execute_whenNoScaleRequired_returnsIntrinsicSize() { - taskThumbnailViewData.width.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().widthPx - taskThumbnailViewData.height.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().heightPx - - assertThat(systemUnderTest.execute(createIcon(100, 100))).isEqualTo(Point(100, 100)) - } - - @Test - fun execute_whenThumbnailViewIsSmallerThanScreen_returnsScaledSize() { - taskThumbnailViewData.width.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().widthPx / 2 - taskThumbnailViewData.height.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().heightPx / 2 - - assertThat(systemUnderTest.execute(createIcon(100, 100))).isEqualTo(Point(50, 50)) - } - - @Test - fun execute_whenThumbnailViewIsSmallerThanScreen_withNonGridScale_returnsScaledSize() { - taskThumbnailViewData.width.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().widthPx / 2 - taskThumbnailViewData.height.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().heightPx / 2 - taskViewData.nonGridScale.value = 2f - - assertThat(systemUnderTest.execute(createIcon(100, 100))).isEqualTo(Point(25, 25)) - } - - @Test - fun execute_whenThumbnailViewIsSmallerThanScreen_withThumbnailViewScale_returnsScaledSize() { - taskThumbnailViewData.width.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().widthPx / 2 - taskThumbnailViewData.height.value = - recentsDeviceProfileRepository.getRecentsDeviceProfile().heightPx / 2 - taskThumbnailViewData.scaleX.value = 2f - taskThumbnailViewData.scaleY.value = 2f - - assertThat(systemUnderTest.execute(createIcon(100, 100))).isEqualTo(Point(25, 25)) - } - - private fun createIcon(width: Int, height: Int): Drawable = - mock().apply { - whenever(intrinsicWidth).thenReturn(width) - whenever(intrinsicHeight).thenReturn(height) - } -} diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewModelTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewModelTest.kt index fe7d37a500..fcf4e564db 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewModelTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/task/thumbnail/TaskThumbnailViewModelTest.kt @@ -21,7 +21,6 @@ import android.content.Intent import android.graphics.Bitmap import android.graphics.Color import android.graphics.Matrix -import android.graphics.Point import android.graphics.drawable.Drawable import android.view.Surface import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -35,7 +34,6 @@ import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.BackgroundOnly import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.LiveTile import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Snapshot import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.SnapshotSplash -import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Splash import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Uninitialized import com.android.quickstep.task.viewmodel.TaskContainerData import com.android.quickstep.task.viewmodel.TaskThumbnailViewModel @@ -46,10 +44,8 @@ import com.android.systemui.shared.recents.model.ThumbnailData import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest -import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -63,7 +59,6 @@ class TaskThumbnailViewModelTest { private val tasksRepository = FakeTasksRepository() private val mGetThumbnailPositionUseCase = mock() private val splashAlphaUseCase: SplashAlphaUseCase = mock() - private val getSplashSizeUseCase: GetSplashSizeUseCase = mock() private val systemUnderTest by lazy { TaskThumbnailViewModel( recentsViewData, @@ -72,17 +67,11 @@ class TaskThumbnailViewModelTest { tasksRepository, mGetThumbnailPositionUseCase, splashAlphaUseCase, - getSplashSizeUseCase, ) } private val tasks = (0..5).map(::createTaskWithId) - @Before - fun setUp() { - whenever(getSplashSizeUseCase.execute(any())).thenReturn(Point()) - } - @Test fun initialStateIsUninitialized() = runTest { assertThat(systemUnderTest.uiState.first()).isEqualTo(Uninitialized) @@ -120,7 +109,7 @@ class TaskThumbnailViewModelTest { bitmap = expectedThumbnailData.thumbnail!!, thumbnailRotation = Surface.ROTATION_0, ), - Splash(expectedIconData.icon, Point()) + expectedIconData.icon ) ) } @@ -215,7 +204,7 @@ class TaskThumbnailViewModelTest { bitmap = expectedThumbnailData.thumbnail!!, thumbnailRotation = Surface.ROTATION_270, ), - Splash(expectedIconData.icon, Point()) + expectedIconData.icon ) ) } @@ -241,28 +230,11 @@ class TaskThumbnailViewModelTest { bitmap = expectedThumbnailData.thumbnail!!, thumbnailRotation = Surface.ROTATION_0, ), - Splash(expectedIconData.icon, Point()) + expectedIconData.icon ) ) } - @Test - fun bindStoppedTask_thenStateContainsSplashSizeFromUseCase() = runTest { - val taskId = 2 - val expectedSplashSize = Point(100, 150) - whenever(getSplashSizeUseCase.execute(any())).thenReturn(expectedSplashSize) - val expectedThumbnailData = createThumbnailData(rotation = Surface.ROTATION_270) - tasksRepository.seedThumbnailData(mapOf(taskId to expectedThumbnailData)) - val expectedIconData = createIconData("Task 2") - tasksRepository.seedIconData(mapOf(taskId to expectedIconData)) - tasksRepository.seedTasks(tasks) - tasksRepository.setVisibleTasks(listOf(taskId)) - - systemUnderTest.bind(taskId) - val uiState = systemUnderTest.uiState.first() as SnapshotSplash - assertThat(uiState.splash.size).isEqualTo(expectedSplashSize) - } - @Test fun getSnapshotMatrix_MissingThumbnail() = runTest { val taskId = 2 diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 5e1d8a5ad3..5c5751aa3d 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -456,6 +456,7 @@ 0dp 0dp + 0dp 0dp 0dp 0dp From e0a0ebeece8bb3d7be67faba07700347b43e5d3c Mon Sep 17 00:00:00 2001 From: Uwais Ashraf Date: Wed, 21 Aug 2024 15:45:05 +0000 Subject: [PATCH 2/2] Prevent requestLayout() when updating drawables that don't change size Fix: 354224963 Test: presubmits passing, manual Flag: com.android.launcher3.enable_refactor_task_thumbnail Change-Id: I31d9a51ed621f411bcafbb5bf885ee2587df057f --- quickstep/res/layout/task_thumbnail.xml | 9 +-- .../task/thumbnail/TaskThumbnailView.kt | 16 +++--- .../quickstep/views/FixedSizeImageView.kt | 56 +++++++++++++++++++ 3 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 quickstep/src/com/android/quickstep/views/FixedSizeImageView.kt diff --git a/quickstep/res/layout/task_thumbnail.xml b/quickstep/res/layout/task_thumbnail.xml index 6ca501234e..d90d9169ab 100644 --- a/quickstep/res/layout/task_thumbnail.xml +++ b/quickstep/res/layout/task_thumbnail.xml @@ -19,19 +19,19 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - + android:visibility="invisible"/> + android:visibility="invisible"/> -