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

Commit a326efd4 authored by Matt Pietal's avatar Matt Pietal
Browse files

Fix flickering notifs...

... and leaking animator. The smartspace view animator could be
leaked when going to/from AOD while the clock transition was
running. This left a predraw listener attached forever, and was
most noticeably causing flicker on notifications.

It turns out there's no guarantee that an animator underlying a
transition will end, which left the predraw listener attached.
Using a TransitionListener instead seems to be more reliable.

Fixes: 334528077
Fixes: 332979277
Test: Repeatedly switch between large and small clocks with
and without media. Observe traces to ensure no predraw
listener remains attached.
Flag: N/A

Change-Id: Iac51bdde8de524a8ad95bfd116e2eeb55cd47eeb
parent 5e899586
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.graphics.Rect
import android.transition.Transition
import android.transition.TransitionListenerAdapter
import android.transition.TransitionSet
import android.transition.TransitionValues
import android.util.Log
@@ -169,6 +170,18 @@ class ClockSizeTransition(
                    return@OnPreDrawListener true
                }

                this@VisibilityBoundsTransition.addListener(
                    object : TransitionListenerAdapter() {
                        override fun onTransitionStart(t: Transition) {
                            toView.viewTreeObserver.addOnPreDrawListener(predrawCallback)
                        }

                        override fun onTransitionEnd(t: Transition) {
                            toView.viewTreeObserver.removeOnPreDrawListener(predrawCallback)
                        }
                    }
                )

                val listener =
                    object : AnimatorListenerAdapter() {
                        override fun onAnimationStart(anim: Animator) {
@@ -178,26 +191,11 @@ class ClockSizeTransition(
                        override fun onAnimationEnd(anim: Animator) {
                            assignAnimValues("end", 1f, toVis)
                            if (sendToBack) toView.translationZ = 0f
                            toView.viewTreeObserver.removeOnPreDrawListener(predrawCallback)
                        }

                        override fun onAnimationPause(anim: Animator) {
                            toView.viewTreeObserver.removeOnPreDrawListener(predrawCallback)
                        }

                        override fun onAnimationResume(anim: Animator) {
                            toView.viewTreeObserver.addOnPreDrawListener(predrawCallback)
                        }
                    }

                anim.duration = duration
                anim.startDelay = startDelay
                anim.interpolator = interpolator
                anim.addListener(listener)
                anim.addPauseListener(listener)

                assignAnimValues("init", 0f, fromVis)
                toView.viewTreeObserver.addOnPreDrawListener(predrawCallback)
            }
        }