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.keyguard.ui.view.layout.sections
18 
19 import android.content.Context
20 import android.view.LayoutInflater
21 import android.view.View
22 import android.view.ViewGroup
23 import androidx.constraintlayout.widget.ConstraintLayout
24 import androidx.constraintlayout.widget.ConstraintSet
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 com.android.keyguard.dagger.KeyguardStatusBarViewComponent
30 import com.android.systemui.keyguard.shared.model.KeyguardSection
31 import com.android.systemui.res.R
32 import com.android.systemui.scene.shared.flag.SceneContainerFlag
33 import com.android.systemui.shade.NotificationPanelView
34 import com.android.systemui.shade.ShadeViewStateProvider
35 import com.android.systemui.statusbar.phone.KeyguardStatusBarView
36 import com.android.systemui.util.Utils
37 import javax.inject.Inject
38 
39 /** A section for the status bar displayed at the top of the lockscreen. */
40 class DefaultStatusBarSection
41 @Inject
42 constructor(
43     private val context: Context,
44     private val notificationPanelView: NotificationPanelView,
45     private val keyguardStatusBarViewComponentFactory: KeyguardStatusBarViewComponent.Factory,
46 ) : KeyguardSection() {
47 
48     private val statusBarViewId = R.id.keyguard_header
49 
addViewsnull50     override fun addViews(constraintLayout: ConstraintLayout) {
51         if (!SceneContainerFlag.isEnabled) {
52             return
53         }
54 
55         notificationPanelView.findViewById<View>(statusBarViewId)?.let {
56             (it.parent as ViewGroup).removeView(it)
57         }
58 
59         val view =
60             LayoutInflater.from(constraintLayout.context)
61                 .inflate(R.layout.keyguard_status_bar, constraintLayout, false)
62                 as KeyguardStatusBarView
63 
64         constraintLayout.addView(view)
65     }
66 
bindDatanull67     override fun bindData(constraintLayout: ConstraintLayout) {
68         if (!SceneContainerFlag.isEnabled) {
69             return
70         }
71 
72         val statusBarView =
73             constraintLayout.findViewById<KeyguardStatusBarView>(statusBarViewId) ?: return
74 
75         val provider =
76             object : ShadeViewStateProvider {
77                 override val lockscreenShadeDragProgress: Float = 0f
78                 override val panelViewExpandedHeight: Float = 0f
79                 override fun shouldHeadsUpBeVisible(): Boolean {
80                     return false
81                 }
82             }
83         val statusBarViewComponent =
84             keyguardStatusBarViewComponentFactory.build(statusBarView, provider)
85         val controller = statusBarViewComponent.keyguardStatusBarViewController
86         controller.init()
87     }
88 
applyConstraintsnull89     override fun applyConstraints(constraintSet: ConstraintSet) {
90         constraintSet.apply {
91             constrainHeight(statusBarViewId, Utils.getStatusBarHeaderHeightKeyguard(context))
92             connect(statusBarViewId, TOP, PARENT_ID, TOP)
93             connect(statusBarViewId, START, PARENT_ID, START)
94             connect(statusBarViewId, END, PARENT_ID, END)
95         }
96     }
97 
removeViewsnull98     override fun removeViews(constraintLayout: ConstraintLayout) {
99         constraintLayout.removeView(statusBarViewId)
100     }
101 }
102