Improved support for workspace screen thumbnails

- Shrinking workspace view in All Apps
- Added vertical margin for workspace screen thumnbnails
- Fixed bugs in a few of the Launcher state transitions (e.g. customization to all apps)

Change-Id: I9ad1c8861585d78fdb2e3bc986a614526b3cfe5f
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index be60e98..8102d19 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1266,7 +1266,7 @@
             // Animate the widget chooser up from the bottom of the screen
             if (!isCustomizationDrawerVisible()) {
                 showCustomizationDrawer();
-                mWorkspace.shrink();
+                mWorkspace.shrinkToTop();
             }
         } else {
             showAddDialog(mMenuAddInfo);
@@ -2023,7 +2023,8 @@
 
     // AllAppsView.Watcher
     public void zoomed(float zoom) {
-        if (zoom == 1.0f) {
+        // In XLarge view, we zoom down the workspace below all apps so it's still visible
+        if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
             mWorkspace.setVisibility(View.GONE);
         }
     }
@@ -2036,6 +2037,7 @@
             mAllAppsGrid.zoom(1.0f, false);
             Animation anim = AnimationUtils.loadAnimation(this, R.anim.all_apps_zoom_in);
             ((View) mAllAppsGrid).startAnimation(anim);
+            mWorkspace.shrinkToBottom();
         } else {
             mAllAppsGrid.zoom(1.0f, animated);
         }
@@ -2099,6 +2101,7 @@
                     }
                 });
                 ((View)mAllAppsGrid).startAnimation(anim);
+                mWorkspace.unshrink();
             } else {
                 mAllAppsGrid.zoom(0.0f, animated);
             }
@@ -2128,7 +2131,7 @@
         mHomeCustomizationDrawer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_up));
     }
 
-    void hideCustomizationDrawer() {
+    private void hideCustomizationDrawer() {
         if (isCustomizationDrawerVisible()) {
             Animation slideDownAnimation = AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_down);
             slideDownAnimation.setAnimationListener(new Animation.AnimationListener() {
@@ -2142,6 +2145,16 @@
         }
     }
 
+    void onWorkspaceUnshrink() {
+        if (isAllAppsVisible()) {
+            // TODO: Make a smoother transition here
+            closeAllApps(false);
+        }
+        if (isCustomizationDrawerVisible()) {
+            hideCustomizationDrawer();
+        }
+    }
+
     /**
      * Displays the shortcut creation dialog and launches, if necessary, the
      * appropriate activity.
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 7fbdd1e..1a2f812 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -548,7 +548,7 @@
         // this is an intercepted event being forwarded from a cell layout
         if (mIsSmall) {
             unshrink((CellLayout)v);
-            mLauncher.hideCustomizationDrawer();
+            mLauncher.onWorkspaceUnshrink();
         }
         return false;
     }
@@ -710,8 +710,9 @@
             final View child = getChildAt(i);
             if (child.getVisibility() != View.GONE) {
                 final int childX = child.getX();
-                child.layout(
-                        childX, 0, childX + child.getMeasuredWidth(), child.getMeasuredHeight());
+                final int childY = child.getY();
+                child.layout(childX, childY,
+                        childX + child.getMeasuredWidth(), childY + child.getMeasuredHeight());
             }
         }
 
@@ -1117,16 +1118,30 @@
         return true;
     }
 
+    void shrinkToTop() {
+        shrink(true);
+    }
+
+    void shrinkToBottom() {
+        shrink(false);
+    }
+
     // we use this to shrink the workspace for the all apps view and the customize view
-    void shrink() {
+    private void shrink(boolean shrinkToTop) {
         mIsSmall = true;
         final int screenWidth = getWidth();
-
-        final int scaledWorkspacePageWidth = (int)(SHRINK_FACTOR*screenWidth);
+        final int screenHeight = getHeight();
+        final int scaledScreenWidth = (int)(SHRINK_FACTOR*screenWidth);
+        final int scaledScreenHeight = (int)(SHRINK_FACTOR*screenHeight);
         final float scaledSpacing = getResources().getDimension(R.dimen.smallScreenSpacing);
 
         final int screenCount = getChildCount();
-        float totalWidth = screenCount * scaledWorkspacePageWidth + (screenCount - 1) * scaledSpacing;
+        float totalWidth = screenCount * scaledScreenWidth + (screenCount - 1) * scaledSpacing;
+
+        float newY = getResources().getDimension(R.dimen.smallScreenVerticalMargin);
+        if (!shrinkToTop) {
+            newY = screenHeight - newY - scaledScreenHeight;
+        }
 
         // We animate all the screens to the centered position in workspace
         // At the same time, the screens become greyed/dimmed
@@ -1136,20 +1151,23 @@
         Sequencer s = new Sequencer();
         for (int i = 0; i < screenCount; i++) {
             CellLayout cl = (CellLayout) getChildAt(i);
-            PropertyAnimator translate = new PropertyAnimator(
+            PropertyAnimator translateX = new PropertyAnimator(
                     500, cl, "x", cl.getX(), (int) newX);
+            PropertyAnimator translateY = new PropertyAnimator(
+                    500, cl, "y", cl.getY(), (int) newY);
             PropertyAnimator scaleX = new PropertyAnimator(
                     500, cl, "scaleX", cl.getScaleX(), SHRINK_FACTOR);
             PropertyAnimator scaleY = new PropertyAnimator(
                     500, cl, "scaleY", cl.getScaleY(), SHRINK_FACTOR);
             PropertyAnimator alpha = new PropertyAnimator(
                     500, cl, "dimmedBitmapAlpha", cl.getDimmedBitmapAlpha(), 1.0f);
-            Sequencer.Builder b = s.play(translate);
+            Sequencer.Builder b = s.play(translateX);
+            b.with(translateY);
             b.with(scaleX);
             b.with(scaleY);
             b.with(alpha);
             // increment newX for the next screen
-            newX += scaledWorkspacePageWidth + scaledSpacing;
+            newX += scaledScreenWidth + scaledSpacing;
             cl.setOnInterceptTouchListener(this);
         }
         setChildrenDrawnWithCacheEnabled(true);
@@ -1184,12 +1202,14 @@
             CellLayout cl = (CellLayout)getChildAt(i);
             int x = screenWidth * i;
 
-            PropertyAnimator translate = new PropertyAnimator(500, cl, "x", cl.getX(), x);
+            PropertyAnimator translateX = new PropertyAnimator(500, cl, "x", cl.getX(), x);
+            PropertyAnimator translateY = new PropertyAnimator(500, cl, "y", cl.getY(), 0);
             PropertyAnimator scaleX = new PropertyAnimator(500, cl, "scaleX", cl.getScaleX(), 1.0f);
             PropertyAnimator scaleY = new PropertyAnimator(500, cl, "scaleY", cl.getScaleY(), 1.0f);
             PropertyAnimator alpha = new PropertyAnimator(
                     500, cl, "dimmedBitmapAlpha", cl.getDimmedBitmapAlpha(), 0.0f);
-            Sequencer.Builder b = s.play(translate);
+            Sequencer.Builder b = s.play(translateX);
+            b.with(translateY);
             b.with(scaleX);
             b.with(scaleY);
             b.with(alpha);