From 139b27a456662b3a624428da6fff9eda006cec12 Mon Sep 17 00:00:00 2001 From: George Mount Date: Wed, 15 Feb 2023 16:28:34 -0800 Subject: [PATCH] Make Animators pass internal tests Fixes: 269524599 AnimatorSet wasn't properly managing cloning and ViewPropertyAnimatorTest didn't work when the animator took too long to start. This CL fixes both problems. Test: ran animation tests (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9cbebf9fb2066cf8765ba794a9181c6e6fca2ca4) Merged-In: Icdf2e9d75d93fa6a4e99833c24a40b48b051f568 Change-Id: Icdf2e9d75d93fa6a4e99833c24a40b48b051f568 --- core/java/android/animation/AnimatorSet.java | 1 + .../src/android/animation/ViewPropertyAnimatorTest.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java index 257adfe390d66..a700efb7234b1 100644 --- a/core/java/android/animation/AnimatorSet.java +++ b/core/java/android/animation/AnimatorSet.java @@ -1503,6 +1503,7 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim anim.mNodeMap = new ArrayMap(); anim.mNodes = new ArrayList(nodeCount); anim.mEvents = new ArrayList(); + anim.mStartListenersCalled = false; anim.mAnimationEndListener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { diff --git a/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java b/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java index 81cd4da4f425e..8cc88ea230a15 100644 --- a/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java +++ b/core/tests/coretests/src/android/animation/ViewPropertyAnimatorTest.java @@ -135,11 +135,15 @@ public class ViewPropertyAnimatorTest { * @throws Exception */ @Before - public void setUp() throws Exception { + public void setUp() throws Throwable { final BasicAnimatorActivity activity = mActivityRule.getActivity(); Button button = activity.findViewById(R.id.animatingButton); mAnimator = button.animate().x(100).y(100); + mActivityRule.runOnUiThread(() -> { + mAnimator.start(); + mAnimator.cancel(); + }); // mListener is the main testing mechanism of this file. The asserts of each test // are embedded in the listener callbacks that it implements.