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