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.ui.viewmodel 18 19 import android.graphics.Rect 20 import android.util.Size 21 import com.android.quickstep.recents.domain.model.DesktopTaskBoundsData 22 import com.android.quickstep.recents.domain.usecase.OrganizeDesktopTasksUseCase 23 24 /** ViewModel used for [com.android.quickstep.views.DesktopTaskView]. */ 25 class DesktopTaskViewModel(private val organizeDesktopTasksUseCase: OrganizeDesktopTasksUseCase) { 26 /** Positions for desktop tasks as calculated by [organizeDesktopTasksUseCase] */ 27 var organizedDesktopTaskPositions = emptyList<DesktopTaskBoundsData>() 28 private set 29 30 /** 31 * Computes new task positions using [organizeDesktopTasksUseCase]. The result is stored in 32 * [organizedDesktopTaskPositions]. This is used for the exploded desktop view where the usecase 33 * will scale and translate tasks so that they don't overlap. 34 * 35 * @param desktopSize the size available for organizing the tasks. 36 * @param defaultPositions the tasks and their bounds as they appear on a desktop. 37 */ organizeDesktopTasksnull38 fun organizeDesktopTasks(desktopSize: Size, defaultPositions: List<DesktopTaskBoundsData>) { 39 organizedDesktopTaskPositions = 40 organizeDesktopTasksUseCase.run( 41 desktopBounds = Rect(0, 0, desktopSize.width, desktopSize.height), 42 taskBounds = defaultPositions, 43 ) 44 } 45 } 46