am 14f122bf: Fix bug 2271894 - Odd animation when press home button from app that wasn\'t in center home screen

Merge commit '14f122bf847e50a3e7730ccbe57abc25d086a01b' into eclair-mr2

* commit '14f122bf847e50a3e7730ccbe57abc25d086a01b':
  Fix bug 2271894 - Odd animation when press home button from app that wasn't in center home screen
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index d76c9a8..fb59017 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -819,7 +819,7 @@
     }
 
     void closeSystemDialogs() {
-        closeAllApps(false);
+        closeAllApps(true);
         getWindow().closeAllPanels();
 
         try {
@@ -854,11 +854,13 @@
             // for example onResume being called when the user pressed the 'back' button.
             mIsNewIntent = true;
 
+            boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
+                        != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
+            boolean allAppsVisible = isAllAppsVisible();
             if (!mWorkspace.isDefaultScreenShowing()) {
-                mWorkspace.moveToDefaultScreen();
+                mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible);
             }
-
-            closeAllApps(false);
+            closeAllApps(alreadyOnHome && allAppsVisible);
 
             final View v = getWindow().peekDecorView();
             if (v != null && v.getWindowToken() != null) {
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index d0cec8a..ac94cca 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -947,6 +947,10 @@
     }
 
     void snapToScreen(int whichScreen) {
+        snapToScreen(whichScreen, true);
+    }
+
+    void snapToScreen(int whichScreen, boolean animate) {
         //if (!mScroller.isFinished()) return;
 
         whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
@@ -970,7 +974,8 @@
         final int delta = newX - mScrollX;
         final int duration = screenDelta * 300;
         awakenScrollBars(duration);
-        mScroller.startScroll(mScrollX, 0, delta, 0, duration);
+        // 1ms is close to don't animate
+        mScroller.startScroll(mScrollX, 0, delta, 0, animate ? duration : 1);
         invalidate();
     }
 
@@ -1420,8 +1425,8 @@
         }
     }
 
-    void moveToDefaultScreen() {
-        snapToScreen(mDefaultScreen);
+    void moveToDefaultScreen(boolean animate) {
+        snapToScreen(mDefaultScreen, animate);
         getChildAt(mDefaultScreen).requestFocus();
     }