Manual merge of 40245 (ed5c973fc23a6733fd473ad13b4eb317e74e9bb5) DO NOT MERGE.

Prevent infinite loop in the Phone UI.
diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java
index 16a695f..c0581e7 100644
--- a/core/java/android/view/animation/Animation.java
+++ b/core/java/android/view/animation/Animation.java
@@ -282,8 +282,8 @@
      */
     public void detach() {
         if (mStarted && !mEnded) {
-            if (mListener != null) mListener.onAnimationEnd(this);
             mEnded = true;
+            if (mListener != null) mListener.onAnimationEnd(this);
         }
     }
 
@@ -777,10 +777,10 @@
         if (expired) {
             if (mRepeatCount == mRepeated) {
                 if (!mEnded) {
+                    mEnded = true;
                     if (mListener != null) {
                         mListener.onAnimationEnd(this);
                     }
-                    mEnded = true;
                 }
             } else {
                 if (mRepeatCount > 0) {