1 package com.android.systemui.keyguard.ui.view.layout.sections
2 
3 import android.view.View
4 import android.widget.ImageView
5 import androidx.constraintlayout.widget.ConstraintLayout
6 import androidx.core.content.res.ResourcesCompat
7 import com.android.systemui.res.R
8 import com.android.systemui.animation.view.LaunchableImageView
9 import com.android.systemui.keyguard.shared.model.KeyguardSection
10 import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder
11 
12 abstract class BaseShortcutSection : KeyguardSection() {
13     protected var leftShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null
14     protected var rightShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null
15 
removeViewsnull16     override fun removeViews(constraintLayout: ConstraintLayout) {
17         leftShortcutHandle?.destroy()
18         rightShortcutHandle?.destroy()
19         constraintLayout.removeView(R.id.start_button)
20         constraintLayout.removeView(R.id.end_button)
21     }
22 
addLeftShortcutnull23     protected fun addLeftShortcut(constraintLayout: ConstraintLayout) {
24         val padding =
25             constraintLayout.resources.getDimensionPixelSize(
26                 R.dimen.keyguard_affordance_fixed_padding
27             )
28         val view =
29             LaunchableImageView(constraintLayout.context, null).apply {
30                 id = R.id.start_button
31                 scaleType = ImageView.ScaleType.FIT_CENTER
32                 background =
33                     ResourcesCompat.getDrawable(
34                         context.resources,
35                         R.drawable.keyguard_bottom_affordance_bg,
36                         context.theme
37                     )
38                 foreground =
39                     ResourcesCompat.getDrawable(
40                         context.resources,
41                         R.drawable.keyguard_bottom_affordance_selected_border,
42                         context.theme
43                     )
44                 visibility = View.INVISIBLE
45                 setPadding(padding, padding, padding, padding)
46             }
47         constraintLayout.addView(view)
48     }
49 
addRightShortcutnull50     protected fun addRightShortcut(constraintLayout: ConstraintLayout) {
51         if (constraintLayout.findViewById<View>(R.id.end_button) != null) return
52 
53         val padding =
54             constraintLayout.resources.getDimensionPixelSize(
55                 R.dimen.keyguard_affordance_fixed_padding
56             )
57         val view =
58             LaunchableImageView(constraintLayout.context, null).apply {
59                 id = R.id.end_button
60                 scaleType = ImageView.ScaleType.FIT_CENTER
61                 background =
62                     ResourcesCompat.getDrawable(
63                         context.resources,
64                         R.drawable.keyguard_bottom_affordance_bg,
65                         context.theme
66                     )
67                 foreground =
68                     ResourcesCompat.getDrawable(
69                         context.resources,
70                         R.drawable.keyguard_bottom_affordance_selected_border,
71                         context.theme
72                     )
73                 visibility = View.INVISIBLE
74                 setPadding(padding, padding, padding, padding)
75             }
76         constraintLayout.addView(view)
77     }
78     /**
79      * Defines equality as same class.
80      *
81      * This is to enable set operations to be done as an optimization to blueprint transitions.
82      */
equalsnull83     override fun equals(other: Any?): Boolean {
84         return other is BaseShortcutSection
85     }
86 
87     /**
88      * Defines hashcode as class.
89      *
90      * This is to enable set operations to be done as an optimization to blueprint transitions.
91      */
hashCodenull92     override fun hashCode(): Int {
93         return KEY.hashCode()
94     }
95 
96     companion object {
97         private const val KEY = "shortcuts"
98     }
99 }
100