am ade106ef: am 0d2e12fb: am 7f0ad8a4: am f59080ee: Add fade in transition from TL to CV

* commit 'ade106ef606e7793c21b04a16568d2ba24e8e90e':
  Add fade in transition from TL to CV
diff --git a/src/com/android/mail/browse/ConversationPagerController.java b/src/com/android/mail/browse/ConversationPagerController.java
index 87190f5..3b0cc69 100644
--- a/src/com/android/mail/browse/ConversationPagerController.java
+++ b/src/com/android/mail/browse/ConversationPagerController.java
@@ -17,6 +17,7 @@
 
 package com.android.mail.browse;
 
+import android.animation.AnimatorListenerAdapter;
 import android.app.FragmentManager;
 import android.content.Context;
 import android.content.res.TypedArray;
@@ -25,6 +26,7 @@
 import android.graphics.drawable.Drawable;
 import android.support.v4.view.ViewPager;
 import android.view.View;
+import android.view.ViewPropertyAnimator;
 
 import com.android.mail.R;
 import com.android.mail.graphics.PageMarginDrawable;
@@ -84,6 +86,9 @@
      */
     private static final boolean ENABLE_SINGLETON_INITIAL_LOAD = false;
 
+    /** Duration of pager.show(...)'s animation */
+    private static final int SHOW_ANIMATION_DURATION = 300;
+
     public ConversationPagerController(RestrictedActivity activity,
             ActivityController controller) {
         mFragmentManager = activity.getFragmentManager();
@@ -92,8 +97,17 @@
         setupPageMargin(activity.getActivityContext());
     }
 
+    /**
+     * Show the conversation pager for the given conversation and animate in if specified along
+     * with given animation listener.
+     * @param account current account
+     * @param folder current folder
+     * @param initialConversation conversation to display initially in pager
+     * @param changeVisibility true if we need to make the pager appear
+     * @param pagerAnimationListener animation listener for pager fade-in animation
+     */
     public void show(Account account, Folder folder, Conversation initialConversation,
-            boolean changeVisibility) {
+            boolean changeVisibility, AnimatorListenerAdapter pagerAnimationListener) {
         mInitialConversationLoading = true;
 
         if (mShown) {
@@ -114,7 +128,18 @@
         }
 
         if (changeVisibility) {
+            // Reset alpha to 0 before animating/making it visible
+            mPager.setAlpha(0f);
             mPager.setVisibility(View.VISIBLE);
+
+            final ViewPropertyAnimator pagerAnimator = mPager.animate().alpha(1f)
+                    .setDuration(SHOW_ANIMATION_DURATION);
+
+            // If we have any thing that listens in on pager show (see OnePaneController's
+            // showConversation(..) for an example), tack it on
+            if (pagerAnimationListener != null) {
+                pagerAnimator.setListener(pagerAnimationListener);
+            }
         }
 
         mPagerAdapter = new ConversationPagerAdapter(mPager.getContext(), mFragmentManager,
@@ -142,12 +167,20 @@
         mShown = true;
     }
 
+    /**
+     * Hide the pager and cancel any running/pending animation
+     * @param changeVisibility true if we need to make the pager disappear
+     */
     public void hide(boolean changeVisibility) {
         if (!mShown) {
             LogUtils.d(LOG_TAG, "IN CPC.hide, but already hidden");
             return;
         }
         mShown = false;
+
+        // Cancel any potential animations to avoid listener methods running when they shouldn't
+        mPager.animate().cancel();
+
         if (changeVisibility) {
             mPager.setVisibility(View.GONE);
         }
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index 5d87b35..12e3308 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -17,6 +17,8 @@
 
 package com.android.mail.ui;
 
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
 import android.app.Activity;
 import android.app.Fragment;
 import android.app.FragmentManager;
@@ -61,6 +63,39 @@
     /** Whether a conversation list for this account has ever been shown.*/
     private boolean mConversationListNeverShown = true;
 
+    /**
+     * Listener for pager animation to complete and then remove the TL fragment.
+     * This is a work-around for fragment remove animation not working as intended, so we
+     * still get feedback on conversation item tap in the transition from TL to CV.
+     */
+    private final AnimatorListenerAdapter mPagerAnimationListener =
+            new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    // Make sure that while we were animating, the mode did not change back
+                    // If it's still in conversation view mode, remove the TL fragment from behind
+                    if (mViewMode.isConversationMode()) {
+                        // Once the pager is done animating in, we are ready to remove the
+                        // conversation list fragment. Since we track the fragment by either what's
+                        // in content_pane or by the tag, we grab it and remove without animations
+                        // since it's already covered by the conversation view and its white bg.
+                        final FragmentManager fm = mActivity.getFragmentManager();
+                        final FragmentTransaction ft = fm.beginTransaction();
+                        final Fragment f = fm.findFragmentById(R.id.content_pane);
+                        // FragmentManager#findFragmentById can return fragments that are not
+                        // added to the activity. We want to make sure that we don't attempt to
+                        // remove fragments that are not added to the activity, as when the
+                        // transaction is popped off, the FragmentManager will attempt to read
+                        // the same fragment twice.
+                        if (f != null && f.isAdded()) {
+                            ft.remove(f);
+                            ft.commitAllowingStateLoss();
+                            fm.executePendingTransactions();
+                        }
+                    }
+                }
+            };
+
     public OnePaneController(MailActivity activity, ViewMode viewMode) {
         super(activity, viewMode);
     }
@@ -232,6 +267,7 @@
     @Override
     protected void showConversation(Conversation conversation) {
         super.showConversation(conversation);
+
         mConversationListVisible = false;
         if (conversation == null) {
             transitionBackToConversationListMode();
@@ -243,25 +279,9 @@
         } else {
             mViewMode.enterConversationMode();
         }
-        final FragmentManager fm = mActivity.getFragmentManager();
-        final FragmentTransaction ft = fm.beginTransaction();
-        // Switching to conversation view is an incongruous transition:
-        // we are not replacing a fragment with another fragment as
-        // usual. Instead, reveal the heretofore inert conversation
-        // ViewPager and just remove the previously visible fragment
-        // e.g. conversation list, or possibly label list?).
-        final Fragment f = fm.findFragmentById(R.id.content_pane);
-        // FragmentManager#findFragmentById can return fragments that are not added to the activity.
-        // We want to make sure that we don't attempt to remove fragments that are not added to the
-        // activity, as when the transaction is popped off, the FragmentManager will attempt to
-        // readd the same fragment twice
-        if (f != null && f.isAdded()) {
-            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
-            ft.remove(f);
-            ft.commitAllowingStateLoss();
-            fm.executePendingTransactions();
-        }
-        mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */);
+
+        mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */,
+                mPagerAnimationListener);
         onConversationVisibilityChanged(true);
         onConversationListVisibilityChanged(false);
     }
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index f881c73..17e7260 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -348,7 +348,7 @@
     private void showCurrentConversationInPager() {
         if (mConversationToShow != null) {
             mPagerController.show(mAccount, mFolder, mConversationToShow,
-                    false /* changeVisibility */);
+                    false /* changeVisibility */, null /* pagerAnimationListener */);
             mConversationToShow = null;
         }
     }