• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.systemui.statusbar
2 
3 import android.content.Context
4 import android.content.res.Configuration
5 import android.util.MathUtils
6 import com.android.systemui.R
7 import com.android.systemui.animation.Interpolators
8 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController
9 import com.android.systemui.statusbar.policy.ConfigurationController
10 import dagger.assisted.Assisted
11 import dagger.assisted.AssistedFactory
12 import dagger.assisted.AssistedInject
13 
14 class SingleShadeLockScreenOverScroller
15 @AssistedInject
16 constructor(
17     configurationController: ConfigurationController,
18     private val context: Context,
19     private val statusBarStateController: SysuiStatusBarStateController,
20     @Assisted private val nsslController: NotificationStackScrollLayoutController
21 ) : LockScreenShadeOverScroller {
22 
23     private var maxOverScrollAmount = 0
24     private var totalDistanceForFullShadeTransition = 0
25 
26     init {
27         updateResources()
28         configurationController.addCallback(
29             object : ConfigurationController.ConfigurationListener {
onConfigChangednull30                 override fun onConfigChanged(newConfig: Configuration?) {
31                     updateResources()
32                 }
33             })
34     }
35 
updateResourcesnull36     private fun updateResources() {
37         val resources = context.resources
38         totalDistanceForFullShadeTransition =
39             resources.getDimensionPixelSize(R.dimen.lockscreen_shade_qs_transition_distance)
40         maxOverScrollAmount =
41             resources.getDimensionPixelSize(R.dimen.lockscreen_shade_max_over_scroll_amount)
42     }
43 
44     override var expansionDragDownAmount: Float = 0f
45         set(value) {
46             if (value == field) {
47                 return
48             }
49             field = value
50             overScroll()
51         }
52 
overScrollnull53     private fun overScroll() {
54         var extraTopInset = 0.0f
55         if (statusBarStateController.state == StatusBarState.KEYGUARD) {
56             val viewHeight = nsslController.height
57             val overallProgress = MathUtils.saturate(expansionDragDownAmount / viewHeight)
58             val transitionProgress =
59                 Interpolators.getOvershootInterpolation(
60                     overallProgress,
61                     0.6f,
62                     totalDistanceForFullShadeTransition.toFloat() / viewHeight.toFloat())
63             extraTopInset = transitionProgress * maxOverScrollAmount
64         }
65         nsslController.setOverScrollAmount(extraTopInset.toInt())
66     }
67 
68     @AssistedFactory
interfacenull69     fun interface Factory {
70         fun create(
71             nsslController: NotificationStackScrollLayoutController
72         ): SingleShadeLockScreenOverScroller
73     }
74 }
75