Ensure we still build the hw layers when pulling up all apps.

Bug: 30310330
Change-Id: I0d9f2fe01230bdb333c098b5515fc196ac2da2dc
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index 5c7e670..1fe0813 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -250,7 +250,7 @@
 
         final View contentView = toView.getContentView();
         playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
-                animated, initialized, animation, revealDuration, layerViews);
+                animated, initialized, animation, layerViews);
         if (!animated || !initialized) {
             if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
                     toWorkspaceState == Workspace.State.NORMAL_HIDDEN) {
@@ -414,11 +414,22 @@
 
             return animation;
         } else if (animType == PULLUP) {
+            // We are animating the content view alpha, so ensure we have a layer for it
+            layerViews.put(contentView, BUILD_AND_SET_LAYER);
+
             animation.addListener(new AnimatorListenerAdapter() {
                   @Override
                   public void onAnimationEnd(Animator animation) {
                       dispatchOnLauncherTransitionEnd(fromView, animated, false);
                       dispatchOnLauncherTransitionEnd(toView, animated, false);
+
+                      // Disable all necessary layers
+                      for (View v : layerViews.keySet()) {
+                          if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+                              v.setLayerType(View.LAYER_TYPE_NONE, null);
+                          }
+                      }
+
                       cleanupAnimation();
                       pCb.onTransitionComplete();
                   }
@@ -435,9 +446,20 @@
                     // we waited for a layout/draw pass
                     if (mCurrentAnimation != stateAnimation)
                         return;
+
                     dispatchOnLauncherTransitionStart(fromView, animated, false);
                     dispatchOnLauncherTransitionStart(toView, animated, false);
 
+                    // Enable all necessary layers
+                    for (View v : layerViews.keySet()) {
+                        if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+                            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+                        }
+                        if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
+                            v.buildLayer();
+                        }
+                    }
+
                     toView.requestFocus();
                     stateAnimation.start();
                 }
@@ -453,7 +475,7 @@
      */
     private void playCommonTransitionAnimations(
             Workspace.State toWorkspaceState, View fromView, View toView,
-            boolean animated, boolean initialized, AnimatorSet animation, int revealDuration,
+            boolean animated, boolean initialized, AnimatorSet animation,
             HashMap<View, Integer> layerViews) {
         // Create the workspace animation.
         // NOTE: this call apparently also sets the state for the workspace if !animated
@@ -580,7 +602,7 @@
         boolean multiplePagesVisible = toWorkspaceState.hasMultipleVisiblePages;
 
         playCommonTransitionAnimations(toWorkspaceState, fromWorkspace, null,
-                animated, animated, animation, revealDuration, layerViews);
+                animated, animated, animation, layerViews);
 
         if (animated) {
             dispatchOnLauncherTransitionPrepare(fromWorkspace, animated, multiplePagesVisible);
@@ -661,6 +683,8 @@
                 res.getInteger(R.integer.config_overlayItemsAlphaStagger);
 
         final View toView = mLauncher.getWorkspace();
+        final View revealView = fromView.getRevealView();
+        final View contentView = fromView.getContentView();
 
         final HashMap<View, Integer> layerViews = new HashMap<>();
 
@@ -673,7 +697,7 @@
         boolean multiplePagesVisible = toWorkspaceState.hasMultipleVisiblePages;
 
         playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
-                animated, initialized, animation, revealDuration, layerViews);
+                animated, initialized, animation, layerViews);
         if (!animated || !initialized) {
             if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
                     fromWorkspaceState == Workspace.State.NORMAL_HIDDEN) {
@@ -695,9 +719,6 @@
             return null;
         }
         if (animType == CIRCULAR_REVEAL) {
-            final View revealView = fromView.getRevealView();
-            final View contentView = fromView.getContentView();
-
             // hideAppsCustomizeHelper is called in some cases when it is already hidden
             // don't perform all these no-op animations. In particularly, this was causing
             // the all-apps button to pop in and out.
@@ -864,6 +885,9 @@
 
             return animation;
         } else if (animType == PULLUP) {
+            // We are animating the content view alpha, so ensure we have a layer for it
+            layerViews.put(contentView, BUILD_AND_SET_LAYER);
+
             animation.addListener(new AnimatorListenerAdapter() {
                 boolean canceled = false;
                 @Override
@@ -876,10 +900,19 @@
                     if (canceled) return;
                     dispatchOnLauncherTransitionEnd(fromView, animated, false);
                     dispatchOnLauncherTransitionEnd(toView, animated, false);
+
                     // Run any queued runnables
                     if (onCompleteRunnable != null) {
                         onCompleteRunnable.run();
                     }
+
+                    // Disable all necessary layers
+                    for (View v : layerViews.keySet()) {
+                        if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+                            v.setLayerType(View.LAYER_TYPE_NONE, null);
+                        }
+                    }
+
                     cleanupAnimation();
                     pCb.onTransitionComplete();
                 }
@@ -898,9 +931,20 @@
                     // we waited for a layout/draw pass
                     if (mCurrentAnimation != stateAnimation)
                         return;
+
                     dispatchOnLauncherTransitionStart(fromView, animated, false);
                     dispatchOnLauncherTransitionStart(toView, animated, false);
 
+                    // Enable all necessary layers
+                    for (View v : layerViews.keySet()) {
+                        if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+                            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+                        }
+                        if (Utilities.ATLEAST_LOLLIPOP && v.isAttachedToWindow()) {
+                            v.buildLayer();
+                        }
+                    }
+
                     // Focus the new view
                     toView.requestFocus();
                     stateAnimation.start();
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index c2631b0..598ba74 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -394,24 +394,14 @@
             overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel,
                     accessibilityEnabled));
 
-            // For animation optimations, we may need to provide the Launcher transition
-            // with a set of views on which to force build layers in certain scenarios.
-            overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-            qsbContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-            if (layerViews != null) {
-                // If layerViews is not null, we add these views, and indicate that
-                // the caller can manage layer state.
-                layerViews.put(overviewPanel, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
-                layerViews.put(qsbContainer, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
-
-                layerViews.put(mLauncher.getHotseat(),
-                        LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
-                layerViews.put(mWorkspace.getPageIndicator(),
-                        LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
-            } else {
-                // Otherwise let the animator handle layer management.
-                overviewPanelAlpha.withLayer();
-            }
+            // For animation optimization, we may need to provide the Launcher transition
+            // with a set of views on which to force build and manage layers in certain scenarios.
+            layerViews.put(overviewPanel, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
+            layerViews.put(qsbContainer, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
+            layerViews.put(mLauncher.getHotseat(),
+                    LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
+            layerViews.put(mWorkspace.getPageIndicator(),
+                    LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
 
             if (states.workspaceToOverview) {
                 hotseatAlpha.setInterpolator(new DecelerateInterpolator(2));