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.statusbar.notification.stack.ui.view
18 
19 import android.content.Context
20 import android.util.AttributeSet
21 import android.view.View
22 import androidx.constraintlayout.widget.ConstraintLayout
23 import androidx.constraintlayout.widget.ConstraintSet
24 import androidx.constraintlayout.widget.ConstraintSet.BOTTOM
25 import androidx.constraintlayout.widget.ConstraintSet.END
26 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
27 import androidx.constraintlayout.widget.ConstraintSet.START
28 import androidx.constraintlayout.widget.ConstraintSet.TOP
29 import androidx.constraintlayout.widget.ConstraintSet.VERTICAL
30 import com.android.systemui.R
31 
32 /**
33  * Container for the stack scroller, so that the bounds can be externally specified, such as from
34  * the keyguard or shade scenes.
35  */
36 class SharedNotificationContainer(
37     context: Context,
38     private val attrs: AttributeSet?,
39 ) :
40     ConstraintLayout(
41         context,
42         attrs,
43     ) {
44 
45     private val baseConstraintSet = ConstraintSet()
46 
47     init {
48         baseConstraintSet.apply {
49             create(R.id.nssl_guideline, VERTICAL)
50             setGuidelinePercent(R.id.nssl_guideline, 0.5f)
51         }
52         baseConstraintSet.applyTo(this)
53     }
54 
55     fun addNotificationStackScrollLayout(nssl: View) {
56         addView(nssl)
57     }
58 
59     fun updateConstraints(
60         useSplitShade: Boolean,
61         marginStart: Int,
62         marginTop: Int,
63         marginEnd: Int,
64         marginBottom: Int
65     ) {
66         val constraintSet = ConstraintSet()
67         constraintSet.clone(baseConstraintSet)
68 
69         val startConstraintId =
70             if (useSplitShade) {
71                 R.id.nssl_guideline
72             } else {
73                 PARENT_ID
74             }
75         val nsslId = R.id.notification_stack_scroller
76         constraintSet.apply {
77             connect(nsslId, START, startConstraintId, START)
78             connect(nsslId, END, PARENT_ID, END)
79             connect(nsslId, BOTTOM, PARENT_ID, BOTTOM)
80             connect(nsslId, TOP, PARENT_ID, TOP)
81             setMargin(nsslId, START, marginStart)
82             setMargin(nsslId, END, marginEnd)
83             setMargin(nsslId, TOP, marginTop)
84             setMargin(nsslId, BOTTOM, marginBottom)
85         }
86         constraintSet.applyTo(this)
87     }
88 }
89