Fixing homescreen getting blank when returning from the overlay

Change-Id: Ie11b92cd59c90e71b9b58eeede742ef0c5b28380
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 56a7613..b0e46f9 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1055,16 +1055,16 @@
     }
 
     protected void getVisiblePages(int[] range) {
-        final int pageCount = getChildCount();
+        final int count = getChildCount();
         range[0] = -1;
         range[1] = -1;
 
-        if (pageCount > 0) {
+        if (count > 0) {
             final int visibleLeft = -getLeft();
             final int visibleRight = visibleLeft + getViewportWidth();
+            final Matrix pageShiftMatrix = getPageShiftMatrix();
             int curScreen = 0;
 
-            int count = getChildCount();
             for (int i = 0; i < count; i++) {
                 View currPage = getPageAt(i);
 
@@ -1073,7 +1073,7 @@
                 sTmpRectF.right = currPage.getMeasuredWidth();
                 currPage.getMatrix().mapRect(sTmpRectF);
                 sTmpRectF.offset(currPage.getLeft() - getScrollX(), 0);
-                getMatrix().mapRect(sTmpRectF);
+                pageShiftMatrix.mapRect(sTmpRectF);
 
                 if (sTmpRectF.left > visibleRight || sTmpRectF.right < visibleLeft) {
                     if (range[0] == -1) {
@@ -1096,6 +1096,10 @@
         }
     }
 
+    protected Matrix getPageShiftMatrix() {
+        return getMatrix();
+    }
+
     protected boolean shouldDrawChild(View child) {
         return child.getVisibility() == VISIBLE;
     }
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index f941996..4eb4d45 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -173,6 +173,7 @@
     @Thunk float[] mDragViewVisualCenter = new float[2];
     private float[] mTempCellLayoutCenterCoordinates = new float[2];
     private Matrix mTempInverseMatrix = new Matrix();
+    private Matrix mTempMatrix = new Matrix();
 
     private SpringLoadedDragController mSpringLoadedDragController;
     private float mSpringLoadedShrinkFactor;
@@ -1344,6 +1345,7 @@
         if (mIsRtl) {
             transX = -transX;
         }
+        mOverlayTranslation = transX;
 
         // TODO(adamcohen): figure out a final effect here. We may need to recommend
         // different effects based on device performance. On at least one relatively high-end
@@ -1361,6 +1363,18 @@
         }
     }
 
+    @Override
+    protected Matrix getPageShiftMatrix() {
+        if (Float.compare(mOverlayTranslation, 0) != 0) {
+            // The pages are translated by mOverlayTranslation. incorporate that in the
+            // visible page calculation by shifting everything back by that same amount.
+            mTempMatrix.set(getMatrix());
+            mTempMatrix.postTranslate(-mOverlayTranslation, 0);
+            return mTempMatrix;
+        }
+        return super.getPageShiftMatrix();
+    }
+
     private void setTranslationAndAlpha(View v, float transX, float alpha) {
         if (v != null) {
             v.setTranslationX(transX);