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

Commit f66d2f6f authored by Doris Liu's avatar Doris Liu
Browse files

Fix out of order listener callback for animator set containing empty sets

BUG: 31016584

CTS test for this fix is added at:
https://googleplex-android-review.git.corp.google.com/#/c/1348858/

Change-Id: I9427a6791f4e0aafc33f5cc9fac16c3518d1cdbe
parent 7cb86c15
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -635,12 +635,12 @@ public final class AnimatorSet extends Animator {
        boolean setIsEmpty = false;
        if (mStartDelay > 0) {
            start(mRootNode);
        } else if (mNodes.size() > 1) {
        } else if (isEmptySet(this)) {
            // Set is empty or contains only empty animator sets. Skip to end in this case.
            setIsEmpty = true;
        } else {
            // No delay, but there are other animators in the set
            onChildAnimatorEnded(mDelayAnim);
        } else {
            // Set is empty, no delay, no other animation. Skip to end in this case
            setIsEmpty = true;
        }

        if (mListeners != null) {
@@ -657,6 +657,25 @@ public final class AnimatorSet extends Animator {
        }
    }

    // Returns true if set is empty or contains nothing but animator sets with no start delay.
    private static boolean isEmptySet(AnimatorSet set) {
        if (set.getStartDelay() > 0) {
            return false;
        }
        for (int i = 0; i < set.getChildAnimations().size(); i++) {
            Animator anim = set.getChildAnimations().get(i);
            if (!(anim instanceof AnimatorSet)) {
                // Contains non-AnimatorSet, not empty.
                return false;
            } else {
                if (!isEmptySet((AnimatorSet) anim)) {
                    return false;
                }
            }
        }
        return true;
    }

    private void updateAnimatorsDuration() {
        if (mDuration >= 0) {
            // If the duration was set on this AnimatorSet, pass it along to all child animations