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

Commit 1baceb4c authored by Bharat Singh's avatar Bharat Singh Committed by Android (Google) Code Review
Browse files

Merge "[SysUI][Floaty] Adjust squeeze effect animation when config duation...

Merge "[SysUI][Floaty] Adjust squeeze effect animation when config duation less than 500ms" into main
parents 6695f3e0 5c0ee2d0
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -38,10 +38,11 @@ import com.android.systemui.testKosmos
import com.android.systemui.topui.TopUiControllerRefactor
import com.android.systemui.topui.mockTopUiController
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.DEFAULT_INITIAL_DELAY_MILLIS
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.DEFAULT_INWARD_EFFECT_DURATION
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.DEFAULT_LONG_PRESS_POWER_DURATION_MILLIS
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.DEFAULT_OUTWARD_EFFECT_DURATION
import com.android.systemui.topwindoweffects.data.repository.fakeSqueezeEffectRepository
import com.android.systemui.topwindoweffects.domain.interactor.SqueezeEffectInteractor
import com.android.systemui.topwindoweffects.ui.viewmodel.SqueezeEffectConfig
import com.android.systemui.topwindoweffects.ui.viewmodel.SqueezeEffectHapticsBuilder
import com.android.systemui.topwindoweffects.ui.viewmodel.squeezeEffectHapticPlayerFactory
import com.android.wm.shell.appzoomout.appZoomOutOptional
@@ -80,6 +81,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            lowTickDuration = primitiveDurations[0],
            quickRiseDuration = primitiveDurations[1],
            tickDuration = primitiveDurations[2],
            totalEffectDuration = DEFAULT_OUTWARD_EFFECT_DURATION + DEFAULT_INWARD_EFFECT_DURATION,
        )

    private val Kosmos.underTest by
@@ -316,14 +318,12 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            assertThat(vibratorHelper.timesCancelled).isEqualTo(timesCancelledBefore)

            // Animation continues: complete inward animation
            animatorTestRule.advanceTimeBy(
                SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong() - 10L
            )
            animatorTestRule.advanceTimeBy(DEFAULT_INWARD_EFFECT_DURATION - 10L)
            runCurrent()
            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(1f)

            // Animation continues: complete outward animation (triggered by inward animation's end)
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_OUTWARD_EFFECT_DURATION.toLong())
            runCurrent()
            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(0f)

@@ -350,7 +350,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            val timesCancelledBefore = vibratorHelper.timesCancelled

            // Complete inward animation
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_INWARD_EFFECT_DURATION.toLong())
            runCurrent()
            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(1f) // Animation proceeds

@@ -359,7 +359,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            assertThat(vibratorHelper.timesCancelled).isEqualTo(timesCancelledBefore)

            // Complete outward animation
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_OUTWARD_EFFECT_DURATION.toLong())
            runCurrent()
            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(0f)

@@ -389,12 +389,12 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            val timesCancelledBefore = vibratorHelper.timesCancelled

            // Complete inward animation
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_INWARD_EFFECT_DURATION.toLong())
            runCurrent()
            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(1f)

            // Outward animation is triggered by the end of the inward animation
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_OUTWARD_EFFECT_DURATION.toLong())
            runCurrent()
            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(0f)

@@ -423,7 +423,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            advanceTime((initialDelay + 1).milliseconds)
            val timesCancelledBefore = vibratorHelper.timesCancelled
            // Progress half-way into inward animation
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong() / 2)
            animatorTestRule.advanceTimeBy(DEFAULT_INWARD_EFFECT_DURATION.toLong() / 2)
            runCurrent()

            val progressBeforeCancel = fakeAppZoomOut.lastTopLevelProgress
@@ -439,7 +439,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            assertThat(vibratorHelper.timesCancelled).isEqualTo(timesCancelledBefore + 1)

            // Complete the cancellation (outward) animation
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_OUTWARD_EFFECT_DURATION.toLong())
            runCurrent()

            assertThat(fakeAppZoomOut.lastTopLevelProgress).isEqualTo(0f)
@@ -485,9 +485,9 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            reset(kosmos.mockTopUiController, kosmos.notificationShadeWindowController)

            // Action: Complete the full animation cycle (inward + outward)
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong() - 1L)
            animatorTestRule.advanceTimeBy(DEFAULT_INWARD_EFFECT_DURATION.toLong() - 1L)
            runCurrent()
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_OUTWARD_EFFECT_DURATION.toLong())
            runCurrent()

            // Verification: setRequestTopUi(false) should be called upon completion
@@ -508,7 +508,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            underTest.start()
            advanceTime((initialDelay + 1).milliseconds) // Pass initial delay
            // Progress animation part way
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong() / 2)
            animatorTestRule.advanceTimeBy(DEFAULT_INWARD_EFFECT_DURATION.toLong() / 2)
            runCurrent()

            // Verification: Ensure TopUI was requested initially
@@ -520,7 +520,7 @@ class TopLevelWindowEffectsTest : SysuiTestCase() {
            fakeKeyEventRepository.setPowerButtonDown(false)
            runCurrent()
            // Allow cancellation animation to complete
            animatorTestRule.advanceTimeBy(SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong())
            animatorTestRule.advanceTimeBy(DEFAULT_OUTWARD_EFFECT_DURATION.toLong())
            runCurrent()

            // Verification: setRequestTopUi(false) should be called upon cancellation
+4 −4
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ import com.android.systemui.keyevent.domain.interactor.KeyEventInteractor
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.topui.TopUiController
import com.android.systemui.topui.TopUiControllerRefactor
import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl.Companion.DEFAULT_OUTWARD_EFFECT_DURATION
import com.android.systemui.topwindoweffects.domain.interactor.SqueezeEffectInteractor
import com.android.systemui.topwindoweffects.ui.viewmodel.SqueezeEffectConfig
import com.android.systemui.topwindoweffects.ui.viewmodel.SqueezeEffectHapticPlayer
import com.android.wm.shell.appzoomout.AppZoomOut
import java.io.PrintWriter
@@ -99,12 +99,12 @@ constructor(
        setRequestTopUi(true)
        animateSqueezeProgressTo(
            targetProgress = 1f,
            duration = SqueezeEffectConfig.INWARD_EFFECT_DURATION.toLong(),
            duration = squeezeEffectInteractor.getInvocationEffectInwardsAnimationDurationMs(),
            interpolator = InterpolatorsAndroidX.LEGACY,
        ) {
            animateSqueezeProgressTo(
                targetProgress = 0f,
                duration = SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong(),
                duration = DEFAULT_OUTWARD_EFFECT_DURATION.toLong(),
                interpolator = InterpolatorsAndroidX.LEGACY,
            ) {
                finishAnimation()
@@ -123,7 +123,7 @@ constructor(
            hapticPlayer?.cancel()
            animateSqueezeProgressTo(
                targetProgress = 0f,
                duration = SqueezeEffectConfig.OUTWARD_EFFECT_DURATION.toLong(),
                duration = DEFAULT_OUTWARD_EFFECT_DURATION.toLong(),
                interpolator = InterpolatorsAndroidX.LEGACY,
            ) {
                finishAnimation()
+2 −0
Original line number Diff line number Diff line
@@ -26,4 +26,6 @@ interface SqueezeEffectRepository {
    val isPowerButtonDownInKeyCombination: Flow<Boolean>

    suspend fun getInvocationEffectInitialDelayMs(): Long

    suspend fun getInvocationEffectInwardsAnimationDurationMs(): Long
}
+11 −1
Original line number Diff line number Diff line
@@ -202,7 +202,6 @@ constructor(

    override suspend fun getInvocationEffectInitialDelayMs(): Long {
        val duration = getLongPressPowerDurationFromSettings()
        // TODO(b/408363187): adjust this difference for values lower than 500ms
        return if (duration > DEFAULT_LONG_PRESS_POWER_DURATION_MILLIS) {
            DEFAULT_INITIAL_DELAY_MILLIS + (duration - DEFAULT_LONG_PRESS_POWER_DURATION_MILLIS)
        } else {
@@ -210,6 +209,15 @@ constructor(
        }
    }

    override suspend fun getInvocationEffectInwardsAnimationDurationMs(): Long {
        val duration = getLongPressPowerDurationFromSettings()
        return if (duration < DEFAULT_LONG_PRESS_POWER_DURATION_MILLIS) {
            DEFAULT_INWARD_EFFECT_DURATION - (DEFAULT_LONG_PRESS_POWER_DURATION_MILLIS - duration)
        } else {
            DEFAULT_INWARD_EFFECT_DURATION.toLong()
        }
    }

    private fun loadIsInvocationEffectEnabledByAssistant(): Boolean {
        val persistedForUser =
            sharedPreferences.getInt(
@@ -301,6 +309,8 @@ constructor(
         */
        @VisibleForTesting const val DEFAULT_INITIAL_DELAY_MILLIS = 150L
        @VisibleForTesting const val DEFAULT_LONG_PRESS_POWER_DURATION_MILLIS = 500L
        @VisibleForTesting const val DEFAULT_INWARD_EFFECT_DURATION = 800 // in milliseconds
        const val DEFAULT_OUTWARD_EFFECT_DURATION = 333 // in milliseconds

        @VisibleForTesting
        const val SET_INVOCATION_EFFECT_PARAMETERS_ACTION = "set_invocation_effect_parameters"
+3 −0
Original line number Diff line number Diff line
@@ -51,4 +51,7 @@ constructor(

    suspend fun getInvocationEffectInitialDelayMs() =
        squeezeEffectRepository.getInvocationEffectInitialDelayMs()

    suspend fun getInvocationEffectInwardsAnimationDurationMs() =
        squeezeEffectRepository.getInvocationEffectInwardsAnimationDurationMs()
}
Loading