Revert "Revert "Speed up All Apps -> Workspace transition""

- also, undo enabling hardware layers for
    scroll indicator, which could have caused
    slowness
- fix bug where scroll indicator was not seen
    after the first visit to all apps
- eliminate a some needless hardware layer redraws
- making items under All Apps invisible when we're
    in All Apps
- making workspace spaces invisible if their alpha is 0
    to prevent more hardware layer rebuilding

This reverts commit 9753d13c7bda09c1203c611ac6717021037f39c3.

Change-Id: Ib908ae0b456b2d4b8a171991a95f20aea4749da1
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index 023946b..a5964df 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -347,38 +347,46 @@
 
     /* LauncherTransitionable overrides */
     @Override
-    public void onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace) {
+    public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
         mInTransition = true;
-        boolean animated = (animation != null);
 
-        mContent.setVisibility(VISIBLE);
+        if (toWorkspace) {
+            // Going from All Apps -> Workspace
+            setVisibilityOfSiblingsWithLowerZOrder(VISIBLE);
+        } else {
+            // Going from Workspace -> All Apps
+            mContent.setVisibility(VISIBLE);
 
-        if (!toWorkspace) {
             // Make sure the current page is loaded (we start loading the side pages after the
             // transition to prevent slowing down the animation)
             mAppsCustomizePane.loadAssociatedPages(mAppsCustomizePane.getCurrentPage(), true);
-        }
-        if (animated) {
-            enableAndBuildHardwareLayer();
+
+            if (!LauncherApplication.isScreenLarge()) {
+                mAppsCustomizePane.showScrollingIndicator(true);
+            }
         }
 
-        if (!toWorkspace && !LauncherApplication.isScreenLarge()) {
-            mAppsCustomizePane.showScrollingIndicator(false);
-        }
         if (mResetAfterTransition) {
             mAppsCustomizePane.reset();
             mResetAfterTransition = false;
         }
+
+        if (animated) {
+            enableAndBuildHardwareLayer();
+        }
     }
 
     @Override
-    public void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace) {
+    public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
         mInTransition = false;
-        if (animation != null) {
+        if (animated) {
             setLayerType(LAYER_TYPE_NONE, null);
         }
 
         if (!toWorkspace) {
+            // Going from Workspace -> All Apps
+            setVisibilityOfSiblingsWithLowerZOrder(INVISIBLE);
+
             // Dismiss the workspace cling and show the all apps cling (if not already shown)
             l.dismissWorkspaceCling(null);
             mAppsCustomizePane.showAllAppsCling();
@@ -392,6 +400,26 @@
         }
     }
 
+    private void setVisibilityOfSiblingsWithLowerZOrder(int visibility) {
+        ViewGroup parent = (ViewGroup) getParent();
+        final int count = parent.getChildCount();
+        if (!isChildrenDrawingOrderEnabled()) {
+            for (int i = 0; i < count; i++) {
+                final View child = parent.getChildAt(i);
+                if (child == this) {
+                    break;
+                } else {
+                    if (child.getVisibility() == GONE) {
+                        continue;
+                    }
+                    child.setVisibility(visibility);
+                }
+            }
+        } else {
+            throw new RuntimeException("Failed; can't get z-order of views");
+        }
+    }
+
     public void onWindowVisible() {
         if (getVisibility() == VISIBLE) {
             mContent.setVisibility(VISIBLE);