Delay hiding fragments until transition finishes

Change-Id: I616de20e7e161fe1a53cd5e72912cec48f078df5
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 08167c1e..9d6f71e 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -972,9 +972,17 @@
                         transitionStyle);
                 if (anim != null) {
                     anim.setTarget(fragment.mView);
+                    // Delay the actual hide operation until the animation finishes, otherwise
+                    // the fragment will just immediately disappear
+                    final Fragment finalFragment = fragment;
+                    anim.addListener(new AnimatorListenerAdapter() {
+                        @Override
+                        public void onAnimationEnd(Animator animation) {
+                            finalFragment.mView.setVisibility(View.GONE);
+                        }
+                    });
                     anim.start();
                 }
-                fragment.mView.setVisibility(View.GONE);
             }
             if (fragment.mAdded && fragment.mHasMenu) {
                 mNeedMenuInvalidate = true;