• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.systemui.statusbar
2 
3 import android.content.Context
4 import android.util.IndentingPrintWriter
5 import android.util.MathUtils
6 import com.android.systemui.R
7 import com.android.systemui.dump.DumpManager
8 import com.android.systemui.media.controls.ui.MediaHierarchyManager
9 import com.android.systemui.shade.NotificationPanelViewController
10 import com.android.systemui.statusbar.policy.ConfigurationController
11 import dagger.assisted.Assisted
12 import dagger.assisted.AssistedFactory
13 import dagger.assisted.AssistedInject
14 
15 /** Controls the lockscreen to shade transition for the keyguard elements. */
16 class LockscreenShadeKeyguardTransitionController
17 @AssistedInject
18 constructor(
19     private val mediaHierarchyManager: MediaHierarchyManager,
20     @Assisted private val notificationPanelController: NotificationPanelViewController,
21     context: Context,
22     configurationController: ConfigurationController,
23     dumpManager: DumpManager
24 ) : AbstractLockscreenShadeTransitionController(context, configurationController, dumpManager) {
25 
26     /**
27      * Distance that the full shade transition takes in order for the keyguard content on
28      * NotificationPanelViewController to fully fade (e.g. Clock & Smartspace).
29      */
30     private var alphaTransitionDistance = 0
31 
32     /**
33      * Distance that the full shade transition takes in order for the keyguard elements to fully
34      * translate into their final position
35      */
36     private var keyguardTransitionDistance = 0
37 
38     /** The amount of vertical offset for the keyguard during the full shade transition. */
39     private var keyguardTransitionOffset = 0
40 
41     /** The amount of alpha that was last set on the keyguard elements. */
42     private var alpha = 0f
43 
44     /** The latest progress [0,1] of the alpha transition. */
45     private var alphaProgress = 0f
46 
47     /** The amount of alpha that was last set on the keyguard status bar. */
48     private var statusBarAlpha = 0f
49 
50     /** The amount of translationY that was last set on the keyguard elements. */
51     private var translationY = 0
52 
53     /** The latest progress [0,1] of the translationY progress. */
54     private var translationYProgress = 0f
55 
updateResourcesnull56     override fun updateResources() {
57         alphaTransitionDistance =
58             context.resources.getDimensionPixelSize(
59                 R.dimen.lockscreen_shade_npvc_keyguard_content_alpha_transition_distance)
60         keyguardTransitionDistance =
61             context.resources.getDimensionPixelSize(
62                 R.dimen.lockscreen_shade_keyguard_transition_distance)
63         keyguardTransitionOffset =
64             context.resources.getDimensionPixelSize(
65                 R.dimen.lockscreen_shade_keyguard_transition_vertical_offset)
66     }
67 
onDragDownAmountChangednull68     override fun onDragDownAmountChanged(dragDownAmount: Float) {
69         alphaProgress = MathUtils.saturate(dragDownAmount / alphaTransitionDistance)
70         alpha = 1f - alphaProgress
71         translationY = calculateKeyguardTranslationY(dragDownAmount)
72         notificationPanelController.setKeyguardTransitionProgress(alpha, translationY)
73 
74         statusBarAlpha = if (useSplitShade) alpha else -1f
75         notificationPanelController.setKeyguardStatusBarAlpha(statusBarAlpha)
76     }
77 
calculateKeyguardTranslationYnull78     private fun calculateKeyguardTranslationY(dragDownAmount: Float): Int {
79         if (!useSplitShade) {
80             return 0
81         }
82         // On split-shade, the translationY of the keyguard should stay in sync with the
83         // translation of media.
84         if (mediaHierarchyManager.isCurrentlyInGuidedTransformation()) {
85             return mediaHierarchyManager.getGuidedTransformationTranslationY()
86         }
87         // When media is not showing, apply the default distance
88         translationYProgress = MathUtils.saturate(dragDownAmount / keyguardTransitionDistance)
89         val translationY = translationYProgress * keyguardTransitionOffset
90         return translationY.toInt()
91     }
92 
dumpnull93     override fun dump(indentingPrintWriter: IndentingPrintWriter) {
94         indentingPrintWriter.let {
95             it.println("LockscreenShadeKeyguardTransitionController:")
96             it.increaseIndent()
97             it.println("Resources:")
98             it.increaseIndent()
99             it.println("alphaTransitionDistance: $alphaTransitionDistance")
100             it.println("keyguardTransitionDistance: $keyguardTransitionDistance")
101             it.println("keyguardTransitionOffset: $keyguardTransitionOffset")
102             it.decreaseIndent()
103             it.println("State:")
104             it.increaseIndent()
105             it.println("dragDownAmount: $dragDownAmount")
106             it.println("alpha: $alpha")
107             it.println("alphaProgress: $alphaProgress")
108             it.println("statusBarAlpha: $statusBarAlpha")
109             it.println("translationProgress: $translationYProgress")
110             it.println("translationY: $translationY")
111         }
112     }
113 
114     @AssistedFactory
interfacenull115     fun interface Factory {
116         fun create(
117             notificationPanelController: NotificationPanelViewController
118         ): LockscreenShadeKeyguardTransitionController
119     }
120 }
121