1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
package com.android.systemui.statusbar
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.content.Context
import android.content.res.Configuration
import android.os.SystemClock
import android.util.IndentingPrintWriter
import android.util.MathUtils
import android.view.MotionEvent
import android.view.View
import android.view.ViewConfiguration
import androidx.annotation.VisibleForTesting
import com.android.systemui.Dumpable
import com.android.systemui.ExpandHelper
import com.android.systemui.Gefingerpoken
import com.android.systemui.R
import com.android.systemui.animation.Interpolators
import com.android.systemui.biometrics.UdfpsKeyguardViewController
import com.android.systemui.classifier.Classifier
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.media.MediaHierarchyManager
import com.android.systemui.plugins.ActivityStarter.OnDismissAction
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.qs.QS
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableView
import com.android.systemui.statusbar.notification.stack.AmbientState
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.statusbar.phone.LSShadeTransitionLogger
import com.android.systemui.statusbar.phone.NotificationPanelViewController
import com.android.systemui.statusbar.phone.ScrimController
import com.android.systemui.statusbar.phone.StatusBar
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.Utils
import java.io.FileDescriptor
import java.io.PrintWriter
import javax.inject.Inject
private const val SPRING_BACK_ANIMATION_LENGTH_MS = 375L
private const val RUBBERBAND_FACTOR_STATIC = 0.15f
private const val RUBBERBAND_FACTOR_EXPANDABLE = 0.5f
/**
* A class that controls the lockscreen to shade transition
*/
@SysUISingleton
class LockscreenShadeTransitionController @Inject constructor(
private val statusBarStateController: SysuiStatusBarStateController,
private val logger: LSShadeTransitionLogger,
private val keyguardBypassController: KeyguardBypassController,
private val lockScreenUserManager: NotificationLockscreenUserManager,
private val falsingCollector: FalsingCollector,
private val ambientState: AmbientState,
private val mediaHierarchyManager: MediaHierarchyManager,
private val scrimController: ScrimController,
private val depthController: NotificationShadeDepthController,
private val context: Context,
wakefulnessLifecycle: WakefulnessLifecycle,
configurationController: ConfigurationController,
falsingManager: FalsingManager,
dumpManager: DumpManager,
) : Dumpable {
private var pulseHeight: Float = 0f
private var useSplitShade: Boolean = false
private lateinit var nsslController: NotificationStackScrollLayoutController
lateinit var notificationPanelController: NotificationPanelViewController
lateinit var statusbar: StatusBar
lateinit var qS: QS
/**
* A handler that handles the next keyguard dismiss animation.
*/
private var animationHandlerOnKeyguardDismiss: ((Long) -> Unit)? = null
/**
* The entry that was just dragged down on.
*/
private var draggedDownEntry: NotificationEntry? = null
/**
* The current animator if any
*/
@VisibleForTesting
internal var dragDownAnimator: ValueAnimator? = null
/**
* The current pulse height animator if any
*/
@VisibleForTesting
internal var pulseHeightAnimator: ValueAnimator? = null
/**
* Distance that the full shade transition takes in order for scrim to fully transition to
* the shade (in alpha)
*/
private var scrimTransitionDistance = 0
/**
* Distance that the full transition takes in order for us to fully transition to the shade
*/
private var fullTransitionDistance = 0
/**
* Flag to make sure that the dragDownAmount is applied to the listeners even when in the
* locked down shade.
*/
private var forceApplyAmount = false
/**
* A flag to suppress the default animation when unlocking in the locked down shade.
*/
private var nextHideKeyguardNeedsNoAnimation = false
/**
* Are we currently waking up to the shade locked
*/
var isWakingToShadeLocked: Boolean = false
private set
/**
* The distance until we're showing the notifications when pulsing
*/
val distanceUntilShowingPulsingNotifications
get() = scrimTransitionDistance
/**
* The udfpsKeyguardViewController if it exists.
*/
var udfpsKeyguardViewController: UdfpsKeyguardViewController? = null
/**
* The touch helper responsible for the drag down animation.
*/
val touchHelper = DragDownHelper(falsingManager, falsingCollector, this, context)
init {
updateResources()
configurationController.addCallback(object : ConfigurationController.ConfigurationListener {
override fun onConfigChanged(newConfig: Configuration?) {
updateResources()
touchHelper.updateResources(context)
}
})
dumpManager.registerDumpable(this)
statusBarStateController.addCallback(object : StatusBarStateController.StateListener {
override fun onExpandedChanged(isExpanded: Boolean) {
// safeguard: When the panel is fully collapsed, let's make sure to reset.
// See b/198098523
if (!isExpanded) {
if (dragDownAmount != 0f && dragDownAnimator?.isRunning != true) {
logger.logDragDownAmountResetWhenFullyCollapsed()
dragDownAmount = 0f
}
if (pulseHeight != 0f && pulseHeightAnimator?.isRunning != true) {
logger.logPulseHeightNotResetWhenFullyCollapsed()
setPulseHeight(0f, animate = false)
}
}
}
})
wakefulnessLifecycle.addObserver(object : WakefulnessLifecycle.Observer {
override fun onPostFinishedWakingUp() {
// when finishing waking up, the UnlockedScreenOffAnimation has another attempt
// to reset keyguard. Let's do it in post
isWakingToShadeLocked = false
}
})
}
private fun updateResources() {
scrimTransitionDistance = context.resources.getDimensionPixelSize(
R.dimen.lockscreen_shade_scrim_transition_distance)
fullTransitionDistance = context.resources.getDimensionPixelSize(
R.dimen.lockscreen_shade_qs_transition_distance)
useSplitShade = Utils.shouldUseSplitNotificationShade(context.resources)
}
fun setStackScroller(nsslController: NotificationStackScrollLayoutController) {
this.nsslController = nsslController
touchHelper.host = nsslController.view
touchHelper.expandCallback = nsslController.expandHelperCallback
}
/**
* Initialize the shelf controller such that clicks on it will expand the shade
*/
fun bindController(notificationShelfController: NotificationShelfController) {
// Bind the click listener of the shelf to go to the full shade
notificationShelfController.setOnClickListener {
if (statusBarStateController.state == StatusBarState.KEYGUARD) {
statusbar.wakeUpIfDozing(SystemClock.uptimeMillis(), it, "SHADE_CLICK")
goToLockedShade(it)
}
}
}
/**
* @return true if the interaction is accepted, false if it should be cancelled
*/
internal fun canDragDown(): Boolean {
return (statusBarStateController.state == StatusBarState.KEYGUARD ||
nsslController.isInLockedDownShade()) &&
(qS.isFullyCollapsed || useSplitShade)
}
/**
* Called by the touch helper when when a gesture has completed all the way and released.
*/
internal fun onDraggedDown(startingChild: View?, dragLengthY: Int) {
if (canDragDown()) {
val cancelRunnable = Runnable {
logger.logGoingToLockedShadeAborted()
setDragDownAmountAnimated(0f)
}
if (nsslController.isInLockedDownShade()) {
logger.logDraggedDownLockDownShade(startingChild)
statusBarStateController.setLeaveOpenOnKeyguardHide(true)
statusbar.dismissKeyguardThenExecute(OnDismissAction {
nextHideKeyguardNeedsNoAnimation = true
false
}, cancelRunnable, false /* afterKeyguardGone */)
} else {
logger.logDraggedDown(startingChild, dragLengthY)
if (!ambientState.isDozing() || startingChild != null) {
// go to locked shade while animating the drag down amount from its current
// value
val animationHandler = { delay: Long ->
if (startingChild is ExpandableNotificationRow) {
startingChild.onExpandedByGesture(
true /* drag down is always an open */)
}
notificationPanelController.animateToFullShade(delay)
notificationPanelController.setTransitionToFullShadeAmount(0f,
true /* animated */, delay)
// Let's reset ourselves, ready for the next animation
// changing to shade locked will make isInLockDownShade true, so let's
// override that
forceApplyAmount = true
// Reset the behavior. At this point the animation is already started
dragDownAmount = 0f
forceApplyAmount = false
}
goToLockedShadeInternal(startingChild, animationHandler, cancelRunnable)
}
}
} else {
logger.logUnSuccessfulDragDown(startingChild)
setDragDownAmountAnimated(0f)
}
}
/**
* Called by the touch helper when the drag down was aborted and should be reset.
*/
internal fun onDragDownReset() {
logger.logDragDownAborted()
nsslController.setDimmed(true /* dimmed */, true /* animated */)
nsslController.resetScrollPosition()
nsslController.resetCheckSnoozeLeavebehind()
setDragDownAmountAnimated(0f)
}
/**
* The user has dragged either above or below the threshold which changes the dimmed state.
* @param above whether they dragged above it
*/
internal fun onCrossedThreshold(above: Boolean) {
nsslController.setDimmed(!above /* dimmed */, true /* animate */)
}
/**
* Called by the touch helper when the drag down was started
*/
internal fun onDragDownStarted(startingChild: ExpandableView?) {
logger.logDragDownStarted(startingChild)
nsslController.cancelLongPress()
nsslController.checkSnoozeLeavebehind()
dragDownAnimator?.apply {
if (isRunning) {
logger.logAnimationCancelled(isPulse = false)
cancel()
}
}
}
/**
* Do we need a falsing check currently?
*/
internal val isFalsingCheckNeeded: Boolean
get() = statusBarStateController.state == StatusBarState.KEYGUARD
/**
* Is dragging down enabled on a given view
* @param view The view to check or `null` to check if it's enabled at all
*/
internal fun isDragDownEnabledForView(view: ExpandableView?): Boolean {
if (isDragDownAnywhereEnabled) {
return true
}
if (nsslController.isInLockedDownShade()) {
if (view == null) {
// Dragging down is allowed in general
return true
}
if (view is ExpandableNotificationRow) {
// Only drag down on sensitive views, otherwise the ExpandHelper will take this
return view.entry.isSensitive
}
}
return false
}
/**
* @return if drag down is enabled anywhere, not just on selected views.
*/
internal val isDragDownAnywhereEnabled: Boolean
get() = (statusBarStateController.getState() == StatusBarState.KEYGUARD &&
!keyguardBypassController.bypassEnabled &&
(qS.isFullyCollapsed || useSplitShade))
/**
* The amount in pixels that the user has dragged down.
*/
internal var dragDownAmount = 0f
set(value) {
if (field != value || forceApplyAmount) {
field = value
if (!nsslController.isInLockedDownShade() || field == 0f || forceApplyAmount) {
nsslController.setTransitionToFullShadeAmount(field)
notificationPanelController.setTransitionToFullShadeAmount(field,
false /* animate */, 0 /* delay */)
val progress = MathUtils.saturate(dragDownAmount / scrimTransitionDistance)
qS.setTransitionToFullShadeAmount(field, progress)
// TODO: appear media also in split shade
val mediaAmount = if (useSplitShade) 0f else field
mediaHierarchyManager.setTransitionToFullShadeAmount(mediaAmount)
transitionToShadeAmountCommon(field)
}
}
}
private fun transitionToShadeAmountCommon(dragDownAmount: Float) {
val scrimProgress = MathUtils.saturate(dragDownAmount / scrimTransitionDistance)
scrimController.setTransitionToFullShadeProgress(scrimProgress)
// Fade out all content only visible on the lockscreen
notificationPanelController.setKeyguardOnlyContentAlpha(1.0f - scrimProgress)
depthController.transitionToFullShadeProgress = scrimProgress
udfpsKeyguardViewController?.setTransitionToFullShadeProgress(scrimProgress)
}
private fun setDragDownAmountAnimated(
target: Float,
delay: Long = 0,
endlistener: (() -> Unit)? = null
) {
logger.logDragDownAnimation(target)
val dragDownAnimator = ValueAnimator.ofFloat(dragDownAmount, target)
dragDownAnimator.interpolator = Interpolators.FAST_OUT_SLOW_IN
dragDownAnimator.duration = SPRING_BACK_ANIMATION_LENGTH_MS
dragDownAnimator.addUpdateListener { animation: ValueAnimator ->
dragDownAmount = animation.animatedValue as Float
}
if (delay > 0) {
dragDownAnimator.startDelay = delay
}
if (endlistener != null) {
dragDownAnimator.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
endlistener.invoke()
}
})
}
dragDownAnimator.start()
this.dragDownAnimator = dragDownAnimator
}
/**
* Animate appear the drag down amount.
*/
private fun animateAppear(delay: Long = 0) {
// changing to shade locked will make isInLockDownShade true, so let's override
// that
forceApplyAmount = true
// we set the value initially to 1 pixel, since that will make sure we're
// transitioning to the full shade. this is important to avoid flickering,
// as the below animation only starts once the shade is unlocked, which can
// be a couple of frames later. if we're setting it to 0, it will use the
// default inset and therefore flicker
dragDownAmount = 1f
setDragDownAmountAnimated(fullTransitionDistance.toFloat(), delay = delay) {
// End listener:
// Reset
dragDownAmount = 0f
forceApplyAmount = false
}
}
/**
* Ask this controller to go to the locked shade, changing the state change and doing
* an animation, where the qs appears from 0 from the top
*
* If secure with redaction: Show bouncer, go to unlocked shade.
* If secure without redaction or no security: Go to [StatusBarState.SHADE_LOCKED].
*
* @param expandView The view to expand after going to the shade
* @param needsQSAnimation if this needs the quick settings to slide in from the top or if
* that's already handled separately
*/
@JvmOverloads
fun goToLockedShade(expandedView: View?, needsQSAnimation: Boolean = true) {
val isKeyguard = statusBarStateController.state == StatusBarState.KEYGUARD
logger.logTryGoToLockedShade(isKeyguard)
if (isKeyguard) {
val animationHandler: ((Long) -> Unit)?
if (needsQSAnimation) {
// Let's use the default animation
animationHandler = null
} else {
// Let's only animate notifications
animationHandler = { delay: Long ->
notificationPanelController.animateToFullShade(delay)
}
}
goToLockedShadeInternal(expandedView, animationHandler,
cancelAction = null)
}
}
/**
* If secure with redaction: Show bouncer, go to unlocked shade.
*
* If secure without redaction or no security: Go to [StatusBarState.SHADE_LOCKED].
*
* @param expandView The view to expand after going to the shade.
* @param animationHandler The handler which performs the go to full shade animation. If null,
* the default handler will do the animation, otherwise the caller is
* responsible for the animation. The input value is a Long for the
* delay for the animation.
* @param cancelAction The runnable to invoke when the transition is aborted. This happens if
* the user goes to the bouncer and goes back.
*/
private fun goToLockedShadeInternal(
expandView: View?,
animationHandler: ((Long) -> Unit)? = null,
cancelAction: Runnable? = null
) {
if (statusbar.isShadeDisabled) {
cancelAction?.run()
logger.logShadeDisabledOnGoToLockedShade()
return
}
var userId: Int = lockScreenUserManager.getCurrentUserId()
var entry: NotificationEntry? = null
if (expandView is ExpandableNotificationRow) {
entry = expandView.entry
entry.setUserExpanded(true /* userExpanded */, true /* allowChildExpansion */)
// Indicate that the group expansion is changing at this time -- this way the group
// and children backgrounds / divider animations will look correct.
entry.setGroupExpansionChanging(true)
userId = entry.sbn.userId
}
var fullShadeNeedsBouncer = (!lockScreenUserManager.userAllowsPrivateNotificationsInPublic(
lockScreenUserManager.getCurrentUserId()) ||
!lockScreenUserManager.shouldShowLockscreenNotifications() ||
falsingCollector.shouldEnforceBouncer())
if (keyguardBypassController.bypassEnabled) {
fullShadeNeedsBouncer = false
}
if (lockScreenUserManager.isLockscreenPublicMode(userId) && fullShadeNeedsBouncer) {
statusBarStateController.setLeaveOpenOnKeyguardHide(true)
var onDismissAction: OnDismissAction? = null
if (animationHandler != null) {
onDismissAction = OnDismissAction {
// We're waiting on keyguard to hide before triggering the action,
// as that will make the animation work properly
animationHandlerOnKeyguardDismiss = animationHandler
false
}
}
val cancelHandler = Runnable {
draggedDownEntry?.apply {
setUserLocked(false)
notifyHeightChanged(false /* needsAnimation */)
draggedDownEntry = null
}
cancelAction?.run()
}
logger.logShowBouncerOnGoToLockedShade()
statusbar.showBouncerWithDimissAndCancelIfKeyguard(onDismissAction, cancelHandler)
draggedDownEntry = entry
} else {
logger.logGoingToLockedShade(animationHandler != null)
if (statusBarStateController.isDozing) {
// Make sure we don't go back to keyguard immediately again after waking up
isWakingToShadeLocked = true
}
statusBarStateController.setState(StatusBarState.SHADE_LOCKED)
// This call needs to be after updating the shade state since otherwise
// the scrimstate resets too early
if (animationHandler != null) {
animationHandler.invoke(0 /* delay */)
} else {
performDefaultGoToFullShadeAnimation(0)
}
}
}
/**
* Notify this handler that the keyguard was just dismissed and that a animation to
* the full shade should happen.
*
* @param delay the delay to do the animation with
* @param previousState which state were we in when we hid the keyguard?
*/
fun onHideKeyguard(delay: Long, previousState: Int) {
logger.logOnHideKeyguard()
if (animationHandlerOnKeyguardDismiss != null) {
animationHandlerOnKeyguardDismiss!!.invoke(delay)
animationHandlerOnKeyguardDismiss = null
} else {
if (nextHideKeyguardNeedsNoAnimation) {
nextHideKeyguardNeedsNoAnimation = false
} else if (previousState != StatusBarState.SHADE_LOCKED) {
// No animation necessary if we already were in the shade locked!
performDefaultGoToFullShadeAnimation(delay)
}
}
draggedDownEntry?.apply {
setUserLocked(false)
draggedDownEntry = null
}
}
/**
* Perform the default appear animation when going to the full shade. This is called when
* not triggered by gestures, e.g. when clicking on the shelf or expand button.
*/
private fun performDefaultGoToFullShadeAnimation(delay: Long) {
logger.logDefaultGoToFullShadeAnimation(delay)
notificationPanelController.animateToFullShade(delay)
animateAppear(delay)
}
//
// PULSE EXPANSION
//
/**
* Set the height how tall notifications are pulsing. This is only set whenever we are expanding
* from a pulse and determines how much the notifications are expanded.
*/
fun setPulseHeight(height: Float, animate: Boolean = false) {
if (animate) {
val pulseHeightAnimator = ValueAnimator.ofFloat(pulseHeight, height)
pulseHeightAnimator.interpolator = Interpolators.FAST_OUT_SLOW_IN
pulseHeightAnimator.duration = SPRING_BACK_ANIMATION_LENGTH_MS
pulseHeightAnimator.addUpdateListener { animation: ValueAnimator ->
setPulseHeight(animation.animatedValue as Float)
}
pulseHeightAnimator.start()
this.pulseHeightAnimator = pulseHeightAnimator
} else {
pulseHeight = height
val overflow = nsslController.setPulseHeight(height)
notificationPanelController.setOverStrechAmount(overflow)
val transitionHeight = if (keyguardBypassController.bypassEnabled) height else 0.0f
transitionToShadeAmountCommon(transitionHeight)
}
}
/**
* Finish the pulse animation when the touch interaction finishes
* @param cancelled was the interaction cancelled and this is a reset?
*/
fun finishPulseAnimation(cancelled: Boolean) {
logger.logPulseExpansionFinished(cancelled)
if (cancelled) {
setPulseHeight(0f, animate = true)
} else {
notificationPanelController.onPulseExpansionFinished()
setPulseHeight(0f, animate = false)
}
}
/**
* Notify this class that a pulse expansion is starting
*/
fun onPulseExpansionStarted() {
logger.logPulseExpansionStarted()
pulseHeightAnimator?.apply {
if (isRunning) {
logger.logAnimationCancelled(isPulse = true)
cancel()
}
}
}
override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) {
IndentingPrintWriter(pw, " ").let {
it.println("LSShadeTransitionController:")
it.increaseIndent()
it.println("pulseHeight: $pulseHeight")
it.println("useSplitShade: $useSplitShade")
it.println("dragDownAmount: $dragDownAmount")
it.println("isDragDownAnywhereEnabled: $isDragDownAnywhereEnabled")
it.println("isFalsingCheckNeeded: $isFalsingCheckNeeded")
it.println("isWakingToShadeLocked: $isWakingToShadeLocked")
it.println("hasPendingHandlerOnKeyguardDismiss: " +
"${animationHandlerOnKeyguardDismiss != null}")
}
}
}
/**
* A utility class to enable the downward swipe on the lockscreen to go to the full shade and expand
* the notification where the drag started.
*/
class DragDownHelper(
private val falsingManager: FalsingManager,
private val falsingCollector: FalsingCollector,
private val dragDownCallback: LockscreenShadeTransitionController,
context: Context
) : Gefingerpoken {
private var dragDownAmountOnStart = 0.0f
lateinit var expandCallback: ExpandHelper.Callback
lateinit var host: View
private var minDragDistance = 0
private var initialTouchX = 0f
private var initialTouchY = 0f
private var touchSlop = 0f
private var slopMultiplier = 0f
private val temp2 = IntArray(2)
private var draggedFarEnough = false
private var startingChild: ExpandableView? = null
private var lastHeight = 0f
var isDraggingDown = false
private set
private val isFalseTouch: Boolean
get() {
return if (!dragDownCallback.isFalsingCheckNeeded) {
false
} else {
falsingManager.isFalseTouch(Classifier.NOTIFICATION_DRAG_DOWN) || !draggedFarEnough
}
}
val isDragDownEnabled: Boolean
get() = dragDownCallback.isDragDownEnabledForView(null)
init {
updateResources(context)
}
fun updateResources(context: Context) {
minDragDistance = context.resources.getDimensionPixelSize(
R.dimen.keyguard_drag_down_min_distance)
val configuration = ViewConfiguration.get(context)
touchSlop = configuration.scaledTouchSlop.toFloat()
slopMultiplier = configuration.scaledAmbiguousGestureMultiplier
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val x = event.x
val y = event.y
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
draggedFarEnough = false
isDraggingDown = false
startingChild = null
initialTouchY = y
initialTouchX = x
}
MotionEvent.ACTION_MOVE -> {
val h = y - initialTouchY
// Adjust the touch slop if another gesture may be being performed.
val touchSlop = if (event.classification
== MotionEvent.CLASSIFICATION_AMBIGUOUS_GESTURE)
touchSlop * slopMultiplier
else
touchSlop
if (h > touchSlop && h > Math.abs(x - initialTouchX)) {
falsingCollector.onNotificationStartDraggingDown()
isDraggingDown = true
captureStartingChild(initialTouchX, initialTouchY)
initialTouchY = y
initialTouchX = x
dragDownCallback.onDragDownStarted(startingChild)
dragDownAmountOnStart = dragDownCallback.dragDownAmount
return startingChild != null || dragDownCallback.isDragDownAnywhereEnabled
}
}
}
return false
}
override fun onTouchEvent(event: MotionEvent): Boolean {
if (!isDraggingDown) {
return false
}
val x = event.x
val y = event.y
when (event.actionMasked) {
MotionEvent.ACTION_MOVE -> {
lastHeight = y - initialTouchY
captureStartingChild(initialTouchX, initialTouchY)
dragDownCallback.dragDownAmount = lastHeight + dragDownAmountOnStart
if (startingChild != null) {
handleExpansion(lastHeight, startingChild!!)
}
if (lastHeight > minDragDistance) {
if (!draggedFarEnough) {
draggedFarEnough = true
dragDownCallback.onCrossedThreshold(true)
}
} else {
if (draggedFarEnough) {
draggedFarEnough = false
dragDownCallback.onCrossedThreshold(false)
}
}
return true
}
MotionEvent.ACTION_UP -> if (!falsingManager.isUnlockingDisabled && !isFalseTouch &&
dragDownCallback.canDragDown()) {
dragDownCallback.onDraggedDown(startingChild, (y - initialTouchY).toInt())
if (startingChild != null) {
expandCallback.setUserLockedChild(startingChild, false)
startingChild = null
}
isDraggingDown = false
} else {
stopDragging()
return false
}
MotionEvent.ACTION_CANCEL -> {
stopDragging()
return false
}
}
return false
}
private fun captureStartingChild(x: Float, y: Float) {
if (startingChild == null) {
startingChild = findView(x, y)
if (startingChild != null) {
if (dragDownCallback.isDragDownEnabledForView(startingChild)) {
expandCallback.setUserLockedChild(startingChild, true)
} else {
startingChild = null
}
}
}
}
private fun handleExpansion(heightDelta: Float, child: ExpandableView) {
var hDelta = heightDelta
if (hDelta < 0) {
hDelta = 0f
}
val expandable = child.isContentExpandable
val rubberbandFactor = if (expandable) {
RUBBERBAND_FACTOR_EXPANDABLE
} else {
RUBBERBAND_FACTOR_STATIC
}
var rubberband = hDelta * rubberbandFactor
if (expandable && rubberband + child.collapsedHeight > child.maxContentHeight) {
var overshoot = rubberband + child.collapsedHeight - child.maxContentHeight
overshoot *= 1 - RUBBERBAND_FACTOR_STATIC
rubberband -= overshoot
}
child.actualHeight = (child.collapsedHeight + rubberband).toInt()
}
private fun cancelChildExpansion(child: ExpandableView) {
if (child.actualHeight == child.collapsedHeight) {
expandCallback.setUserLockedChild(child, false)
return
}
val anim = ObjectAnimator.ofInt(child, "actualHeight",
child.actualHeight, child.collapsedHeight)
anim.interpolator = Interpolators.FAST_OUT_SLOW_IN
anim.duration = SPRING_BACK_ANIMATION_LENGTH_MS
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
expandCallback.setUserLockedChild(child, false)
}
})
anim.start()
}
private fun stopDragging() {
falsingCollector.onNotificationStopDraggingDown()
if (startingChild != null) {
cancelChildExpansion(startingChild!!)
startingChild = null
}
isDraggingDown = false
dragDownCallback.onDragDownReset()
}
private fun findView(x: Float, y: Float): ExpandableView? {
host.getLocationOnScreen(temp2)
return expandCallback.getChildAtRawPosition(x + temp2[0], y + temp2[1])
}
}
|