Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 408b55fe authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Run ktfmt on NotificationWakeUpCoordinator.kt

Bug: 269085199
Test: n/a
Change-Id: I48819780d4e17f59bfa50327a4e239f10d2fe572
parent 9e0349d2
Loading
Loading
Loading
Loading
+100 −72
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ import javax.inject.Inject
import kotlin.math.min

@SysUISingleton
class NotificationWakeUpCoordinator @Inject constructor(
class NotificationWakeUpCoordinator
@Inject
constructor(
    dumpManager: DumpManager,
    private val mHeadsUpManager: HeadsUpManager,
    private val statusBarStateController: StatusBarStateController,
@@ -50,11 +52,14 @@ class NotificationWakeUpCoordinator @Inject constructor(
    private val dozeParameters: DozeParameters,
    private val screenOffAnimationController: ScreenOffAnimationController,
    private val logger: NotificationWakeUpCoordinatorLogger,
) : OnHeadsUpChangedListener, StatusBarStateController.StateListener, ShadeExpansionListener,
) :
    OnHeadsUpChangedListener,
    StatusBarStateController.StateListener,
    ShadeExpansionListener,
    Dumpable {

    private val mNotificationVisibility = object : FloatProperty<NotificationWakeUpCoordinator>(
        "notificationVisibility") {
    private val mNotificationVisibility =
        object : FloatProperty<NotificationWakeUpCoordinator>("notificationVisibility") {

            override fun setValue(coordinator: NotificationWakeUpCoordinator, value: Float) {
                coordinator.setVisibilityAmount(value)
@@ -74,8 +79,7 @@ class NotificationWakeUpCoordinator @Inject constructor(
    private var hardDozeAmountOverrideSource: String = "n/a"
    private var outputLinearDozeAmount: Float = 0.0f
    private var outputEasedDozeAmount: Float = 0.0f
    @VisibleForTesting
    val dozeAmountInterpolator: Interpolator = Interpolators.FAST_OUT_SLOW_IN
    @VisibleForTesting val dozeAmountInterpolator: Interpolator = Interpolators.FAST_OUT_SLOW_IN

    private var mNotificationVisibleAmount = 0.0f
    private var mNotificationsVisible = false
@@ -95,16 +99,21 @@ class NotificationWakeUpCoordinator @Inject constructor(
            field = value
            willWakeUp = false
            if (value) {
                if (mNotificationsVisible && !mNotificationsVisibleForExpansion &&
                    !bypassController.bypassEnabled) {
                if (
                    mNotificationsVisible &&
                        !mNotificationsVisibleForExpansion &&
                        !bypassController.bypassEnabled
                ) {
                    // We're waking up while pulsing, let's make sure the animation looks nice
                    mStackScrollerController.wakeUpFromPulse()
                }
                if (bypassController.bypassEnabled && !mNotificationsVisible) {
                    // Let's make sure our huns become visible once we are waking up in case
                    // they were blocked by the proximity sensor
                    updateNotificationVisibility(animate = shouldAnimateVisibility(),
                            increaseSpeed = false)
                    updateNotificationVisibility(
                        animate = shouldAnimateVisibility(),
                        increaseSpeed = false
                    )
                }
            }
        }
@@ -125,8 +134,10 @@ class NotificationWakeUpCoordinator @Inject constructor(
                // Only when setting pulsing to true we want an immediate update, since we get
                // this already when the doze service finishes which is usually before we get
                // the waking up callback
                updateNotificationVisibility(animate = shouldAnimateVisibility(),
                        increaseSpeed = false)
                updateNotificationVisibility(
                    animate = shouldAnimateVisibility(),
                    increaseSpeed = false
                )
            }
        }

@@ -140,16 +151,16 @@ class NotificationWakeUpCoordinator @Inject constructor(
            }
        }

    /**
     * True if we can show pulsing heads up notifications
     */
    /** True if we can show pulsing heads up notifications */
    var canShowPulsingHuns: Boolean = false
        private set
        get() {
            var canShow = pulsing
            if (bypassController.bypassEnabled) {
                // We also allow pulsing on the lock screen!
                canShow = canShow || (wakingUp || willWakeUp || fullyAwake) &&
                canShow =
                    canShow ||
                        (wakingUp || willWakeUp || fullyAwake) &&
                            statusBarStateController.state == StatusBarState.KEYGUARD
                // We want to hide the notifications when collapsed too much
                if (collapsedEnoughToHide) {
@@ -159,7 +170,8 @@ class NotificationWakeUpCoordinator @Inject constructor(
            return canShow
        }

    private val bypassStateChangedListener = object : OnBypassStateChangedListener {
    private val bypassStateChangedListener =
        object : OnBypassStateChangedListener {
            override fun onBypassStateChanged(isEnabled: Boolean) {
                // When the bypass state changes, we have to check whether we should re-show the
                // notifications by clearing the doze amount override which hides them.
@@ -172,17 +184,24 @@ class NotificationWakeUpCoordinator @Inject constructor(
        mHeadsUpManager.addListener(this)
        statusBarStateController.addCallback(this)
        bypassController.registerOnBypassStateChangedListener(bypassStateChangedListener)
        addListener(object : WakeUpListener {
        addListener(
            object : WakeUpListener {
                override fun onFullyHiddenChanged(isFullyHidden: Boolean) {
                    if (isFullyHidden && mNotificationsVisibleForExpansion) {
                    // When the notification becomes fully invisible, let's make sure our expansion
                    // flag also changes. This can happen if the bouncer shows when dragging down
                        // When the notification becomes fully invisible, let's make sure our
                        // expansion
                        // flag also changes. This can happen if the bouncer shows when dragging
                        // down
                        // and then the screen turning off, where we don't reset this state.
                    setNotificationsVisibleForExpansion(visible = false, animate = false,
                            increaseSpeed = false)
                        setNotificationsVisibleForExpansion(
                            visible = false,
                            animate = false,
                            increaseSpeed = false
                        )
                    }
                }
        })
            }
        )
    }

    fun setStackScroller(stackScrollerController: NotificationStackScrollLayoutController) {
@@ -228,16 +247,17 @@ class NotificationWakeUpCoordinator @Inject constructor(
        wakeUpListeners.remove(listener)
    }

    private fun updateNotificationVisibility(
        animate: Boolean,
        increaseSpeed: Boolean
    ) {
    private fun updateNotificationVisibility(animate: Boolean, increaseSpeed: Boolean) {
        // TODO: handle Lockscreen wakeup for bypass when we're not pulsing anymore
        var visible = mNotificationsVisibleForExpansion || mHeadsUpManager.hasNotifications()
        visible = visible && canShowPulsingHuns

        if (!visible && mNotificationsVisible && (wakingUp || willWakeUp) &&
                outputLinearDozeAmount != 0.0f) {
        if (
            !visible &&
                mNotificationsVisible &&
                (wakingUp || willWakeUp) &&
                outputLinearDozeAmount != 0.0f
        ) {
            // let's not make notifications invisible while waking up, otherwise the animation
            // is strange
            return
@@ -303,8 +323,11 @@ class NotificationWakeUpCoordinator @Inject constructor(
        val changed = outputLinearDozeAmount != newOutputLinearDozeAmount

        // notify when the animation is starting
        if (newOutputLinearDozeAmount != 1.0f && newOutputLinearDozeAmount != 0.0f &&
                (outputLinearDozeAmount == 0.0f || outputLinearDozeAmount == 1.0f)) {
        if (
            newOutputLinearDozeAmount != 1.0f &&
                newOutputLinearDozeAmount != 0.0f &&
                (outputLinearDozeAmount == 0.0f || outputLinearDozeAmount == 1.0f)
        ) {
            // Let's notify the scroller that an animation started
            notifyAnimationStart(outputLinearDozeAmount == 1.0f)
        }
@@ -317,13 +340,17 @@ class NotificationWakeUpCoordinator @Inject constructor(
            hardOverride = hardDozeAmountOverride,
            outputLinear = outputLinearDozeAmount,
            state = statusBarStateController.state,
                changed = changed)
            changed = changed
        )
        mStackScrollerController.setDozeAmount(outputEasedDozeAmount)
        updateHideAmount()
        if (changed && outputLinearDozeAmount == 0.0f) {
            setNotificationsVisible(visible = false, animate = false, increaseSpeed = false)
            setNotificationsVisibleForExpansion(visible = false, animate = false,
                    increaseSpeed = false)
            setNotificationsVisibleForExpansion(
                visible = false,
                animate = false,
                increaseSpeed = false
            )
        }
    }

@@ -351,7 +378,9 @@ class NotificationWakeUpCoordinator @Inject constructor(
            // the doze amount to 0f (not dozing) so that the notifications are no longer hidden.
            // See: UnlockedScreenOffAnimationController.onFinishedWakingUp()
            setHardDozeAmountOverride(
                    dozing = false, source = "Override: Shade->Shade (lock cancelled by unlock)")
                dozing = false,
                source = "Override: Shade->Shade (lock cancelled by unlock)"
            )
            this.state = newState
            return
        }
@@ -425,8 +454,10 @@ class NotificationWakeUpCoordinator @Inject constructor(
            val willRemove = (!onKeyguard || !dozing) && !bypass && !animating
            logger.logMaybeClearHardDozeAmountOverrideHidingNotifs(
                willRemove = willRemove,
                    onKeyguard = onKeyguard, dozing = dozing,
                    bypass = bypass, animating = animating,
                onKeyguard = onKeyguard,
                dozing = dozing,
                bypass = bypass,
                animating = animating,
            )
            if (willRemove) {
                clearHardDozeAmountOverride()
@@ -453,10 +484,9 @@ class NotificationWakeUpCoordinator @Inject constructor(

    private fun startVisibilityAnimation(increaseSpeed: Boolean) {
        if (mNotificationVisibleAmount == 0f || mNotificationVisibleAmount == 1f) {
            mVisibilityInterpolator = if (mNotificationsVisible)
                Interpolators.TOUCH_RESPONSE
            else
                Interpolators.FAST_OUT_SLOW_IN_REVERSE
            mVisibilityInterpolator =
                if (mNotificationsVisible) Interpolators.TOUCH_RESPONSE
                else Interpolators.FAST_OUT_SLOW_IN_REVERSE
        }
        val target = if (mNotificationsVisible) 1.0f else 0.0f
        val visibilityAnimator = ObjectAnimator.ofFloat(this, mNotificationVisibility, target)
@@ -472,8 +502,7 @@ class NotificationWakeUpCoordinator @Inject constructor(

    private fun setVisibilityAmount(visibilityAmount: Float) {
        mLinearVisibilityAmount = visibilityAmount
        mVisibilityAmount = mVisibilityInterpolator.getInterpolation(
                visibilityAmount)
        mVisibilityAmount = mVisibilityInterpolator.getInterpolation(visibilityAmount)
        handleAnimationFinished()
        updateHideAmount()
    }
@@ -554,13 +583,12 @@ class NotificationWakeUpCoordinator @Inject constructor(
    }

    interface WakeUpListener {
        /**
         * Called whenever the notifications are fully hidden or shown
         */
        /** Called whenever the notifications are fully hidden or shown */
        @JvmDefault fun onFullyHiddenChanged(isFullyHidden: Boolean) {}

        /**
         * Called whenever the pulseExpansion changes
         *
         * @param expandingChanged if the user has started or stopped expanding
         */
        @JvmDefault fun onPulseExpansionChanged(expandingChanged: Boolean) {}