1 /*
2  * Copyright (C) 2024 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
18 
19 import android.content.Context
20 import com.android.launcher3.R
21 import com.android.launcher3.Utilities
22 import com.android.launcher3.util.DisplayController
23 import com.android.launcher3.util.SafeCloseable
24 import com.android.launcher3.views.ActivityContext
25 import com.android.quickstep.util.TaskCornerRadius
26 import com.android.systemui.shared.system.QuickStepContract
27 
28 /**
29  * Class for computing corner radius by interpolating between overview and fullscreen corner radius
30  * with fullscreenProgress set in [setProgress].
31  */
32 open class FullscreenDrawParams
33 @JvmOverloads
34 constructor(
35     context: Context,
36     private val taskCornerRadiusProvider: (Context) -> Float = ::computeTaskCornerRadius,
37     private val windowCornerRadiusProvider: (Context) -> Float = ::computeWindowCornerRadius,
38 ) : SafeCloseable {
39     private var taskCornerRadius = 0f
40     private var windowCornerRadius = 0f
41     var currentCornerRadius = 0f
42 
43     init {
44         updateCornerRadius(context)
45     }
46 
47     /** Recomputes the start and end corner radius for the given Context. */
updateCornerRadiusnull48     fun updateCornerRadius(context: Context) {
49         taskCornerRadius = taskCornerRadiusProvider(context)
50         windowCornerRadius = windowCornerRadiusProvider(context)
51     }
52 
53     /** Sets the progress in range [0, 1] */
setProgressnull54     fun setProgress(fullscreenProgress: Float, parentScale: Float, taskViewScale: Float) {
55         currentCornerRadius =
56             Utilities.mapRange(fullscreenProgress, taskCornerRadius, windowCornerRadius) /
57                 parentScale /
58                 taskViewScale
59     }
60 
closenull61     override fun close() {}
62 
63     companion object {
computeTaskCornerRadiusnull64         private fun computeTaskCornerRadius(context: Context): Float = TaskCornerRadius.get(context)
65 
66         private fun computeWindowCornerRadius(context: Context): Float {
67             val activityContext: ActivityContext? = ActivityContext.lookupContextNoThrow(context)
68             return if (
69                 activityContext?.deviceProfile?.isTaskbarPresent == true &&
70                     DisplayController.isTransientTaskbar(context)
71             ) {
72                 context.resources
73                     .getDimensionPixelSize(R.dimen.persistent_taskbar_corner_radius)
74                     .toFloat()
75             } else {
76                 // The corner radius is fixed to match when Taskbar is persistent mode
77                 QuickStepContract.getWindowCornerRadius(context)
78             }
79         }
80     }
81 }
82