Run cleanup before end actions of ViewPropertyAnimator.

Bug 27788719

The end action of a ViewPropertyAnimator may do anything,
including starting a new animator. If the next animator has
started prior to cleaning up the previous one, it will capture
the dirty state as the final state. This CL runs the cleanup
Runnables before running the end actions so that any captured
state is the clean state.

Change-Id: Ib005b817d420e79b636e61987669a852e15df9ce
diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java
index f18b7ac..c5b8849 100644
--- a/core/java/android/view/ViewPropertyAnimator.java
+++ b/core/java/android/view/ViewPropertyAnimator.java
@@ -1113,13 +1113,6 @@
             if (mListener != null) {
                 mListener.onAnimationEnd(animation);
             }
-            if (mAnimatorOnEndMap != null) {
-                Runnable r = mAnimatorOnEndMap.get(animation);
-                if (r != null) {
-                    r.run();
-                }
-                mAnimatorOnEndMap.remove(animation);
-            }
             if (mAnimatorCleanupMap != null) {
                 Runnable r = mAnimatorCleanupMap.get(animation);
                 if (r != null) {
@@ -1127,6 +1120,13 @@
                 }
                 mAnimatorCleanupMap.remove(animation);
             }
+            if (mAnimatorOnEndMap != null) {
+                Runnable r = mAnimatorOnEndMap.get(animation);
+                if (r != null) {
+                    r.run();
+                }
+                mAnimatorOnEndMap.remove(animation);
+            }
             mAnimatorMap.remove(animation);
         }