• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 package com.android.systemui.shade
17 
18 import androidx.constraintlayout.widget.ConstraintSet
19 
20 typealias ConstraintChange = ConstraintSet.() -> Unit
21 
plusnull22 operator fun ConstraintChange?.plus(other: ConstraintChange?): ConstraintChange? {
23     // Prevent wrapping
24     if (this == null) return other
25     if (other == null) return this
26     else return {
27         this@plus()
28         other()
29     }
30 }
31 
32 /**
33  * Contains all changes that need to be performed to the different [ConstraintSet] in
34  * [ShadeHeaderController].
35  */
36 data class ConstraintsChanges(
37     val qqsConstraintsChanges: ConstraintChange? = null,
38     val qsConstraintsChanges: ConstraintChange? = null,
39     val largeScreenConstraintsChanges: ConstraintChange? = null
40 ) {
plusnull41     operator fun plus(other: ConstraintsChanges) = ConstraintsChanges(
42         qqsConstraintsChanges + other.qqsConstraintsChanges,
43         qsConstraintsChanges + other.qsConstraintsChanges,
44         largeScreenConstraintsChanges + other.largeScreenConstraintsChanges
45     )
46 }
47 
48 /**
49  * Determines [ConstraintChanges] for [ShadeHeaderController] based on configurations.
50  *
51  * Given that the number of different scenarios is not that large, having specific methods instead
52  * of a full map between state and [ConstraintSet] was preferred.
53  */
54 interface CombinedShadeHeadersConstraintManager {
55     /**
56      * Changes for when the visibility of the privacy chip changes
57      */
58     fun privacyChipVisibilityConstraints(visible: Boolean): ConstraintsChanges
59 
60     /**
61      * Changes for situations with no top center cutout (there may be a corner cutout)
62      */
63     fun emptyCutoutConstraints(): ConstraintsChanges
64 
65     /**
66      * Changes to incorporate side insets due to rounded corners/corner cutouts
67      */
68     fun edgesGuidelinesConstraints(
69         cutoutStart: Int,
70         paddingStart: Int,
71         cutoutEnd: Int,
72         paddingEnd: Int
73     ): ConstraintsChanges
74 
75     /**
76      * Changes for situations with top center cutout (in this case, there are no corner cutouts).
77      */
78     fun centerCutoutConstraints(rtl: Boolean, offsetFromEdge: Int): ConstraintsChanges
79 }
80