Fix content shifting when an Action Mode is displayed

Caused by a small timing issue in the new fade animations.
The context view is GONE initially so may not have been
laid out when the animation actually starts. This can lead
to the container collapsing to 0px height for a short period.

Fixed by using INVISIBLE for the Toolbar instead to maintain
the height.

BUG: 24395058

Change-Id: I3ec3b0c04c6cd2258692efb2c3d879cec6a82875
diff --git a/v7/appcompat/src/android/support/v7/internal/app/WindowDecorActionBar.java b/v7/appcompat/src/android/support/v7/internal/app/WindowDecorActionBar.java
index e76f658..968c781 100644
--- a/v7/appcompat/src/android/support/v7/internal/app/WindowDecorActionBar.java
+++ b/v7/appcompat/src/android/support/v7/internal/app/WindowDecorActionBar.java
@@ -846,7 +846,11 @@
 
         ViewPropertyAnimatorCompat fadeIn, fadeOut;
         if (toActionMode) {
-            fadeOut = mDecorToolbar.setupAnimatorToVisibility(View.GONE,
+            // We use INVISIBLE for the Toolbar to make sure that the container has a non-zero
+            // height throughout. The context view is GONE initially, so will not have been laid
+            // out when the animation starts. This can lead to the container collapsing to 0px
+            // height for a short period.
+            fadeOut = mDecorToolbar.setupAnimatorToVisibility(View.INVISIBLE,
                     FADE_OUT_DURATION_MS);
             fadeIn = mContextView.setupAnimatorToVisibility(View.VISIBLE,
                     FADE_IN_DURATION_MS);
diff --git a/v7/appcompat/src/android/support/v7/internal/widget/ToolbarWidgetWrapper.java b/v7/appcompat/src/android/support/v7/internal/widget/ToolbarWidgetWrapper.java
index 50e03c9..59b52c5 100644
--- a/v7/appcompat/src/android/support/v7/internal/widget/ToolbarWidgetWrapper.java
+++ b/v7/appcompat/src/android/support/v7/internal/widget/ToolbarWidgetWrapper.java
@@ -587,37 +587,31 @@
     }
 
     @Override
-    public ViewPropertyAnimatorCompat setupAnimatorToVisibility(int visibility, long duration) {
-        if (visibility == View.GONE) {
-            ViewPropertyAnimatorCompat anim = ViewCompat.animate(mToolbar).alpha(0f);
-            anim.setDuration(duration);
-            anim.setListener(new ViewPropertyAnimatorListenerAdapter() {
-                private boolean mCanceled = false;
-                @Override
-                public void onAnimationEnd(View view) {
-                    if (!mCanceled) {
-                        mToolbar.setVisibility(View.GONE);
-                    }
-                }
+    public ViewPropertyAnimatorCompat setupAnimatorToVisibility(final int visibility,
+            final long duration) {
+        return ViewCompat.animate(mToolbar)
+                .alpha(visibility == View.VISIBLE ? 1f : 0f)
+                .setDuration(duration)
+                .setListener(new ViewPropertyAnimatorListenerAdapter() {
+                    private boolean mCanceled = false;
 
-                @Override
-                public void onAnimationCancel(View view) {
-                    mCanceled = true;
-                }
-            });
-            return anim;
-        } else if (visibility == View.VISIBLE) {
-            ViewPropertyAnimatorCompat anim = ViewCompat.animate(mToolbar).alpha(1f);
-            anim.setDuration(duration);
-            anim.setListener(new ViewPropertyAnimatorListenerAdapter() {
-                @Override
-                public void onAnimationStart(View view) {
-                    mToolbar.setVisibility(View.VISIBLE);
-                }
-            });
-            return anim;
-        }
-        return null;
+                    @Override
+                    public void onAnimationStart(View view) {
+                        mToolbar.setVisibility(View.VISIBLE);
+                    }
+
+                    @Override
+                    public void onAnimationEnd(View view) {
+                        if (!mCanceled) {
+                            mToolbar.setVisibility(visibility);
+                        }
+                    }
+
+                    @Override
+                    public void onAnimationCancel(View view) {
+                        mCanceled = true;
+                    }
+                });
     }
 
     @Override