Fix bug 2337808 - zoom state gets out of sync when the surface disappears
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java
index 4e1d3a1..1d21da8 100644
--- a/src/com/android/launcher2/AllAppsView.java
+++ b/src/com/android/launcher2/AllAppsView.java
@@ -114,8 +114,10 @@
 
     private boolean mShouldGainFocus;
 
+    private boolean mHaveSurface = false;
     private boolean mZoomDirty = false;
     private boolean mAnimateNextZoom;
+    private float mNextZoom;
     private float mZoom;
     private float mPosX;
     private float mVelocity;
@@ -191,6 +193,10 @@
         super.surfaceDestroyed(holder);
         // Without this, we leak mMessageCallback which leaks the context.
         mRS.mMessageCallback = null;
+        // We may lose any callbacks that are pending, so make sure that we re-sync that
+        // on the next surfaceChanged.
+        mZoomDirty = true;
+        mHaveSurface = false;
     }
 
     @Override
@@ -199,6 +205,8 @@
 
         super.surfaceChanged(holder, format, w, h);
 
+        mHaveSurface = true;
+
         if (mRollo == null) {
             mRollo = new RolloRS();
             mRollo.init(getResources(), w, h);
@@ -633,10 +641,13 @@
      */
     public void zoom(float zoom, boolean animate) {
         cancelLongPress();
-        if (mRollo == null) {
+        mNextZoom = zoom;
+        mAnimateNextZoom = animate;
+        // if we do setZoom while we don't have a surface, we won't
+        // get the callbacks that actually set mZoom.
+        if (mRollo == null || !mHaveSurface) {
             mZoomDirty = true;
             mZoom = zoom;
-            mAnimateNextZoom = animate;
             return;
         } else {
             mRollo.setZoom(zoom, animate);
@@ -1040,7 +1051,7 @@
 
         void dirtyCheck() {
             if (mZoomDirty) {
-                setZoom(mZoom, mAnimateNextZoom);
+                setZoom(mNextZoom, mAnimateNextZoom);
             }
         }