• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.systemui.shade.ui.composable
18 
19 import androidx.compose.ui.unit.IntOffset
20 import com.android.systemui.qs.ui.adapter.QSSceneAdapter
21 
22 /**
23  * Provider for the extra offset for the Media section in the shade to accommodate for the squishing
24  * qs or qqs tiles.
25  */
26 interface ShadeMediaOffsetProvider {
27 
28     /** Returns current offset to be applied to the Media Carousel */
29     val offset: IntOffset
30 
31     /**
32      * [ShadeMediaOffsetProvider] implementation for Quick Settings.
33      *
34      * [updateLayout] should represent an access to some state to trigger Compose to relayout to
35      * track [QSSceneAdapter] internal state changes during the transition.
36      */
37     class Qs(private val updateLayout: () -> Unit, private val qsSceneAdapter: QSSceneAdapter) :
38         ShadeMediaOffsetProvider {
39 
40         override val offset: IntOffset
41             get() =
42                 calculateQsOffset(
43                     updateLayout,
44                     qsSceneAdapter.qsHeight,
45                     qsSceneAdapter.squishedQsHeight
46                 )
47     }
48 
49     /**
50      * [ShadeMediaOffsetProvider] implementation for Quick Quick Settings.
51      *
52      * [updateLayout] should represent an access to some state to trigger Compose to relayout to
53      * track [QSSceneAdapter] internal state changes during the transition.
54      */
55     class Qqs(private val updateLayout: () -> Unit, private val qsSceneAdapter: QSSceneAdapter) :
56         ShadeMediaOffsetProvider {
57 
58         override val offset: IntOffset
59             get() =
60                 calculateQsOffset(
61                     updateLayout,
62                     qsSceneAdapter.qqsHeight,
63                     qsSceneAdapter.squishedQqsHeight
64                 )
65     }
66 
67     companion object {
68 
calculateQsOffsetnull69         protected fun calculateQsOffset(
70             updateLayout: () -> Unit,
71             qsHeight: Int,
72             qsSquishedHeight: Int
73         ): IntOffset {
74             updateLayout()
75             val distanceFromBottomToActualBottom = qsHeight - qsSquishedHeight
76             return IntOffset(0, -distanceFromBottomToActualBottom)
77         }
78     }
79 }
80