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.util.MathUtils
20 import javax.inject.Inject
21 
22 /** Interpolator responsible for the split shade. */
23 internal class SplitShadeInterpolator @Inject internal constructor() :
24     LargeScreenShadeInterpolator {
25 
getBehindScrimAlphanull26     override fun getBehindScrimAlpha(fraction: Float): Float {
27         // Start delay: 0%
28         // Duration: 40%
29         // End: 40%
30         return mapFraction(start = 0f, end = 0.4f, fraction)
31     }
32 
getNotificationScrimAlphanull33     override fun getNotificationScrimAlpha(fraction: Float): Float {
34         // Start delay: 39%
35         // Duration: 27%
36         // End: 66%
37         return mapFraction(start = 0.39f, end = 0.66f, fraction)
38     }
39 
getNotificationContentAlphanull40     override fun getNotificationContentAlpha(fraction: Float): Float {
41         return getNotificationScrimAlpha(fraction)
42     }
43 
getNotificationFooterAlphanull44     override fun getNotificationFooterAlpha(fraction: Float): Float {
45         // Start delay: 57.6%
46         // Duration: 32.1%
47         // End: 89.7%
48         return mapFraction(start = 0.576f, end = 0.897f, fraction)
49     }
50 
getQsAlphanull51     override fun getQsAlpha(fraction: Float): Float {
52         return getNotificationScrimAlpha(fraction)
53     }
54 
mapFractionnull55     private fun mapFraction(start: Float, end: Float, fraction: Float) =
56         MathUtils.constrainedMap(
57             /* rangeMin= */ 0f,
58             /* rangeMax= */ 1f,
59             /* valueMin= */ start,
60             /* valueMax= */ end,
61             /* value= */ fraction
62         )
63 }
64