improving performance of first AllApps/Customize animation

Change-Id: I71e5cc634f7e1346617d101efd6945c00484cab3
diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java
index 57d41fa..28bb78b 100644
--- a/src/com/android/launcher2/PagedViewCellLayout.java
+++ b/src/com/android/launcher2/PagedViewCellLayout.java
@@ -40,7 +40,8 @@
     private static int sDefaultCellDimensions = 96;
     protected PagedViewCellLayoutChildren mChildren;
     private PagedViewCellLayoutChildren mHolographicChildren;
-    private boolean mUseHardwareLayers = false;
+    private boolean mAllowHardwareLayerCreation = false;
+    private boolean mCreateHardwareLayersIfAllowed = false;
 
     public PagedViewCellLayout(Context context) {
         this(context, null);
@@ -74,8 +75,17 @@
         addView(mHolographicChildren);
     }
 
-    public void enableHardwareLayers() {
-        mUseHardwareLayers = true;
+    public void allowHardwareLayerCreation() {
+        // This is called after the first time we launch into All Apps. Before that point,
+        // there's no need for hardware layers here since there's a hardware layer set on the
+        // parent, AllAppsTabbed, during the AllApps transition -- creating hardware layers here
+        // before the animation is done slows down the animation
+        if (!mAllowHardwareLayerCreation) {
+            mAllowHardwareLayerCreation = true;
+            if (mCreateHardwareLayersIfAllowed) {
+                createHardwareLayers();
+            }
+        }
     }
 
     @Override
@@ -85,13 +95,18 @@
     }
 
     void destroyHardwareLayers() {
-        if (mUseHardwareLayers) {
+        // called when a page is no longer visible (triggered by loadAssociatedPages ->
+        // removeAllViewsOnPage)
+        mCreateHardwareLayersIfAllowed = false;
+        if (mAllowHardwareLayerCreation) {
             mChildren.destroyHardwareLayer();
             mHolographicChildren.destroyHardwareLayer();
         }
     }
     void createHardwareLayers() {
-        if (mUseHardwareLayers) {
+        // called when a page is visible (triggered by loadAssociatedPages -> syncPageItems)
+        mCreateHardwareLayersIfAllowed = true;
+        if (mAllowHardwareLayerCreation) {
             mChildren.createHardwareLayer();
             mHolographicChildren.createHardwareLayer();
         }
@@ -127,7 +142,7 @@
 
             if (child instanceof PagedViewIcon) {
                 PagedViewIcon pagedViewIcon = (PagedViewIcon) child;
-                if (mUseHardwareLayers) {
+                if (mAllowHardwareLayerCreation) {
                     pagedViewIcon.disableCache();
                 }
                 mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(), index, lp);