• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.animation.view.LaunchableImageView
8 import com.android.systemui.keyguard.shared.model.KeyguardSection
9 import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder
10 import com.android.systemui.res.R
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         leftShortcutHandle = null
19         rightShortcutHandle?.destroy()
20         rightShortcutHandle = null
21         constraintLayout.removeView(R.id.start_button)
22         constraintLayout.removeView(R.id.end_button)
23     }
24 
addLeftShortcutnull25     protected fun addLeftShortcut(constraintLayout: ConstraintLayout) {
26         val padding =
27             constraintLayout.resources.getDimensionPixelSize(
28                 R.dimen.keyguard_affordance_fixed_padding
29             )
30         val view =
31             LaunchableImageView(constraintLayout.context, null).apply {
32                 id = R.id.start_button
33                 scaleType = ImageView.ScaleType.FIT_CENTER
34                 background =
35                     ResourcesCompat.getDrawable(
36                         context.resources,
37                         R.drawable.keyguard_bottom_affordance_bg,
38                         context.theme
39                     )
40                 foreground =
41                     ResourcesCompat.getDrawable(
42                         context.resources,
43                         R.drawable.keyguard_bottom_affordance_selected_border,
44                         context.theme
45                     )
46                 visibility = View.INVISIBLE
47                 setPadding(padding, padding, padding, padding)
48             }
49         constraintLayout.addView(view)
50     }
51 
addRightShortcutnull52     protected fun addRightShortcut(constraintLayout: ConstraintLayout) {
53         if (constraintLayout.findViewById<View>(R.id.end_button) != null) return
54 
55         val padding =
56             constraintLayout.resources.getDimensionPixelSize(
57                 R.dimen.keyguard_affordance_fixed_padding
58             )
59         val view =
60             LaunchableImageView(constraintLayout.context, null).apply {
61                 id = R.id.end_button
62                 scaleType = ImageView.ScaleType.FIT_CENTER
63                 background =
64                     ResourcesCompat.getDrawable(
65                         context.resources,
66                         R.drawable.keyguard_bottom_affordance_bg,
67                         context.theme
68                     )
69                 foreground =
70                     ResourcesCompat.getDrawable(
71                         context.resources,
72                         R.drawable.keyguard_bottom_affordance_selected_border,
73                         context.theme
74                     )
75                 visibility = View.INVISIBLE
76                 setPadding(padding, padding, padding, padding)
77             }
78         constraintLayout.addView(view)
79     }
80 
81     /**
82      * Defines equality as same class.
83      *
84      * This is to enable set operations to be done as an optimization to blueprint transitions.
85      */
equalsnull86     override fun equals(other: Any?): Boolean {
87         return other is BaseShortcutSection
88     }
89 
90     /**
91      * Defines hashcode as class.
92      *
93      * This is to enable set operations to be done as an optimization to blueprint transitions.
94      */
hashCodenull95     override fun hashCode(): Int {
96         return KEY.hashCode()
97     }
98 
99     companion object {
100         private const val KEY = "shortcuts"
101     }
102 }
103