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