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 
17 package com.android.systemui.shade
18 
19 import android.view.ViewGroup
20 import androidx.constraintlayout.widget.ConstraintSet
21 import com.android.systemui.res.R
22 import com.android.systemui.dagger.SysUISingleton
23 
24 /**
25  * Standard implementation of [CombinedShadeHeadersConstraintManager].
26  */
27 @SysUISingleton
28 object CombinedShadeHeadersConstraintManagerImpl : CombinedShadeHeadersConstraintManager {
29 
privacyChipVisibilityConstraintsnull30     override fun privacyChipVisibilityConstraints(visible: Boolean): ConstraintsChanges {
31         val constraintAlpha = if (visible) 0f else 1f
32         return ConstraintsChanges(
33             qqsConstraintsChanges = {
34                 setAlpha(R.id.shade_header_system_icons, constraintAlpha)
35             }
36         )
37     }
38 
emptyCutoutConstraintsnull39     override fun emptyCutoutConstraints(): ConstraintsChanges {
40         return ConstraintsChanges(
41             qqsConstraintsChanges = {
42                 connect(R.id.date, ConstraintSet.END, R.id.barrier, ConstraintSet.START)
43                 createBarrier(
44                     R.id.barrier,
45                     ConstraintSet.START,
46                     0,
47                     R.id.shade_header_system_icons,
48                     R.id.privacy_container
49                 )
50                 connect(R.id.shade_header_system_icons, ConstraintSet.START, R.id.date,
51                     ConstraintSet.END)
52                 connect(R.id.privacy_container, ConstraintSet.START, R.id.date, ConstraintSet.END)
53                 constrainWidth(R.id.shade_header_system_icons, ViewGroup.LayoutParams.WRAP_CONTENT)
54                 constrainedWidth(R.id.date, true)
55                 constrainedWidth(R.id.shade_header_system_icons, true)
56             }
57         )
58     }
59 
edgesGuidelinesConstraintsnull60     override fun edgesGuidelinesConstraints(
61         cutoutStart: Int,
62         paddingStart: Int,
63         cutoutEnd: Int,
64         paddingEnd: Int
65     ): ConstraintsChanges {
66         val change: ConstraintChange = {
67             setGuidelineBegin(R.id.begin_guide, Math.max(cutoutStart - paddingStart, 0))
68             setGuidelineEnd(R.id.end_guide, Math.max(cutoutEnd - paddingEnd, 0))
69         }
70         return ConstraintsChanges(
71             qqsConstraintsChanges = change,
72             qsConstraintsChanges = change,
73             largeScreenConstraintsChanges = change,
74         )
75     }
76 
centerCutoutConstraintsnull77     override fun centerCutoutConstraints(rtl: Boolean, offsetFromEdge: Int): ConstraintsChanges {
78         val centerStart = if (!rtl) R.id.center_left else R.id.center_right
79         val centerEnd = if (!rtl) R.id.center_right else R.id.center_left
80         // Use guidelines to block the center cutout area.
81         return ConstraintsChanges(
82             qqsConstraintsChanges = {
83                 setGuidelineBegin(centerStart, offsetFromEdge)
84                 setGuidelineEnd(centerEnd, offsetFromEdge)
85                 connect(R.id.date, ConstraintSet.END, centerStart, ConstraintSet.START)
86                 connect(
87                     R.id.shade_header_system_icons,
88                     ConstraintSet.START,
89                     centerEnd,
90                     ConstraintSet.END
91                 )
92                 connect(
93                     R.id.privacy_container,
94                     ConstraintSet.START,
95                     centerEnd,
96                     ConstraintSet.END
97                 )
98                 constrainedWidth(R.id.date, true)
99                 constrainedWidth(R.id.shade_header_system_icons, true)
100             },
101             qsConstraintsChanges = {
102                 setGuidelineBegin(centerStart, offsetFromEdge)
103                 setGuidelineEnd(centerEnd, offsetFromEdge)
104                 connect(
105                     R.id.privacy_container,
106                     ConstraintSet.START,
107                     centerEnd,
108                     ConstraintSet.END
109                 )
110             }
111         )
112     }
113 }
114