Merge "Fix bug 3365208 - Contextual Action Bar is not displayed when the context item is changing" into honeycomb
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 0e31fef..a8eb6fe 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -388,6 +388,7 @@
             mActionMode.finish();
         }
 
+        mUpperContextView.killMode();
         ActionMode mode = new ActionModeImpl(callback);
         if (callback.onCreateActionMode(mode, mode.getMenu())) {
             mode.invalidate();
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index 31e7bab..bb0c752 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -160,10 +160,6 @@
     }
 
     public void initForMode(final ActionMode mode) {
-        if (mAnimationMode != ANIMATE_IDLE || mAnimateInOnLayout) {
-            killMode();
-        }
-
         if (mClose == null) {
             LayoutInflater inflater = LayoutInflater.from(mContext);
             mClose = inflater.inflate(R.layout.action_mode_close_item, this, false);
@@ -198,15 +194,15 @@
             return;
         }
 
-        mAnimationMode = ANIMATE_OUT;
         finishAnimation();
+        mAnimationMode = ANIMATE_OUT;
         mCurrentAnimation = makeOutAnimation();
         mCurrentAnimation.start();
     }
 
     private void finishAnimation() {
         final Animator a = mCurrentAnimation;
-        if (a != null && a.isRunning()) {
+        if (a != null) {
             mCurrentAnimation = null;
             a.end();
         }
@@ -448,7 +444,7 @@
 
     @Override
     public void onAnimationEnd(Animator animation) {
-        if (mAnimationMode != ANIMATE_IN) {
+        if (mAnimationMode == ANIMATE_OUT) {
             killMode();
         }
         mAnimationMode = ANIMATE_IDLE;
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index fb20e81..1d0b633 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -1985,6 +1985,7 @@
                 }
 
                 if (mActionModeView != null) {
+                    mActionModeView.killMode();
                     mode = new StandaloneActionMode(getContext(), mActionModeView, wrappedCallback);
                     if (callback.onCreateActionMode(mode, mode.getMenu())) {
                         mode.invalidate();