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 
18 package com.android.systemui.keyguard.ui.view
19 
20 import android.content.Context
21 import android.text.TextUtils
22 import android.util.AttributeSet
23 import android.view.Gravity
24 import android.view.View
25 import android.view.ViewGroup.LayoutParams.MATCH_PARENT
26 import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
27 import android.widget.LinearLayout
28 import com.android.systemui.res.R
29 import com.android.systemui.statusbar.phone.KeyguardIndicationTextView
30 
31 class KeyguardIndicationArea(
32     context: Context,
33     private val attrs: AttributeSet?,
34 ) :
35     LinearLayout(
36         context,
37         attrs,
38     ) {
39 
40     init {
41         setId(R.id.keyguard_indication_area)
42         orientation = LinearLayout.VERTICAL
43 
44         addView(indicationTopRow(), LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT))
45         addView(
46             indicationBottomRow(),
<lambda>null47             LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
48                 gravity = Gravity.CENTER_HORIZONTAL
49             }
50         )
51     }
52 
setAlphanull53     override fun setAlpha(alpha: Float) {
54         super.setAlpha(alpha)
55 
56         if (alpha == 0f) {
57             importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
58         } else {
59             importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
60         }
61     }
indicationTopRownull62     private fun indicationTopRow(): KeyguardIndicationTextView {
63         return KeyguardIndicationTextView(context, attrs).apply {
64             id = R.id.keyguard_indication_text
65             gravity = Gravity.CENTER
66             accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE
67             setTextAppearance(R.style.TextAppearance_Keyguard_BottomArea)
68 
69             val padding = R.dimen.keyguard_indication_text_padding.dp()
70             setPaddingRelative(padding, 0, padding, 0)
71         }
72     }
73 
indicationBottomRownull74     private fun indicationBottomRow(): KeyguardIndicationTextView {
75         return KeyguardIndicationTextView(context, attrs).apply {
76             id = R.id.keyguard_indication_text_bottom
77             gravity = Gravity.CENTER
78             accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE
79 
80             setTextAppearance(R.style.TextAppearance_Keyguard_BottomArea)
81             setEllipsize(TextUtils.TruncateAt.END)
82             setAlpha(0.8f)
83             setMinHeight(R.dimen.keyguard_indication_text_min_height.dp())
84             setMaxLines(2)
85             setVisibility(View.GONE)
86 
87             val padding = R.dimen.keyguard_indication_text_padding.dp()
88             setPaddingRelative(padding, 0, padding, 0)
89         }
90     }
91 
dpnull92     private fun Int.dp(): Int {
93         return context.resources.getDimensionPixelSize(this)
94     }
95 }
96