1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.quickstep.recents.domain.usecase 18 19 import android.graphics.Matrix 20 import android.graphics.Rect 21 import com.android.quickstep.recents.data.RecentsDeviceProfileRepository 22 import com.android.quickstep.recents.data.RecentsRotationStateRepository 23 import com.android.systemui.shared.recents.model.ThumbnailData 24 import com.android.systemui.shared.recents.utilities.PreviewPositionHelper 25 26 /** Use case for retrieving [Matrix] for positioning Thumbnail in a View */ 27 class GetThumbnailPositionUseCase( 28 private val deviceProfileRepository: RecentsDeviceProfileRepository, 29 private val rotationStateRepository: RecentsRotationStateRepository, 30 private val previewPositionHelperFactory: PreviewPositionHelper.PreviewPositionHelperFactory, 31 ) { invokenull32 operator fun invoke( 33 thumbnailData: ThumbnailData?, 34 width: Int, 35 height: Int, 36 isRtl: Boolean, 37 ): ThumbnailPosition { 38 val thumbnail = 39 thumbnailData?.thumbnail ?: return ThumbnailPosition(Matrix.IDENTITY_MATRIX, false) 40 41 val previewPositionHelper = previewPositionHelperFactory.create() 42 previewPositionHelper.updateThumbnailMatrix( 43 Rect(0, 0, thumbnail.width, thumbnail.height), 44 thumbnailData, 45 width, 46 height, 47 deviceProfileRepository.getRecentsDeviceProfile().isLargeScreen, 48 rotationStateRepository.getRecentsRotationState().activityRotation, 49 isRtl, 50 ) 51 return ThumbnailPosition( 52 matrix = previewPositionHelper.matrix, 53 isRotated = previewPositionHelper.isOrientationChanged, 54 ) 55 } 56 } 57 58 data class ThumbnailPosition(val matrix: Matrix, val isRotated: Boolean) 59