1 /*
2  * Copyright (C) 2023 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.systemui.shade.transition
18 
19 import android.content.Context
20 import android.content.res.Configuration
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.statusbar.policy.ConfigurationController
23 import com.android.systemui.statusbar.policy.SplitShadeStateController
24 import javax.inject.Inject
25 
26 /** Interpolator responsible for the shade when on large screens. */
27 @SysUISingleton
28 internal class LargeScreenShadeInterpolatorImpl
29 @Inject
30 internal constructor(
31     configurationController: ConfigurationController,
32     private val context: Context,
33     private val splitShadeInterpolator: SplitShadeInterpolator,
34     private val portraitShadeInterpolator: LargeScreenPortraitShadeInterpolator,
35     private val splitShadeStateController: SplitShadeStateController
36 ) : LargeScreenShadeInterpolator {
37 
38     private var inSplitShade = false
39 
40     init {
41         configurationController.addCallback(
42             object : ConfigurationController.ConfigurationListener {
onConfigChangednull43                 override fun onConfigChanged(newConfig: Configuration?) {
44                     updateResources()
45                 }
46             }
47         )
48         updateResources()
49     }
50 
updateResourcesnull51     private fun updateResources() {
52         inSplitShade = splitShadeStateController.shouldUseSplitNotificationShade(context.resources)
53     }
54 
55     private val impl: LargeScreenShadeInterpolator
56         get() =
57             if (inSplitShade) {
58                 splitShadeInterpolator
59             } else {
60                 portraitShadeInterpolator
61             }
62 
getBehindScrimAlphanull63     override fun getBehindScrimAlpha(fraction: Float) = impl.getBehindScrimAlpha(fraction)
64 
65     override fun getNotificationScrimAlpha(fraction: Float) =
66         impl.getNotificationScrimAlpha(fraction)
67 
68     override fun getNotificationContentAlpha(fraction: Float) =
69         impl.getNotificationContentAlpha(fraction)
70 
71     override fun getNotificationFooterAlpha(fraction: Float) =
72         impl.getNotificationFooterAlpha(fraction)
73 
74     override fun getQsAlpha(fraction: Float) = impl.getQsAlpha(fraction)
75 }
76