From ee68816be8e4667548ac8925a14d014f1d66d460 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 12 Feb 2016 14:24:21 -0800 Subject: [PATCH] Fixing homescreen getting blank when returning from the overlay Change-Id: Ie11b92cd59c90e71b9b58eeede742ef0c5b28380 --- src/com/android/launcher3/PagedView.java | 23 ++++++++++++++--------- src/com/android/launcher3/Workspace.java | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index b3a714b81f..ef89192ddb 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -1042,24 +1042,25 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } protected void getVisiblePages(int[] range) { - final int pageCount = getChildCount(); + final int count = getChildCount(); range[0] = -1; range[1] = -1; - if (pageCount > 0) { - int lastVisiblePageIndex = 0; + if (count > 0) { final int visibleLeft = -getLeft(); final int visibleRight = visibleLeft + getViewportWidth(); + final Matrix pageShiftMatrix = getPageShiftMatrix(); + int curScreen = 0; - for (int currPageIndex = 0; currPageIndex < pageCount; currPageIndex++) { - View currPage = getPageAt(currPageIndex); + for (int i = 0; i < count; i++) { + View currPage = getPageAt(i); // Verify if the page bounds are within the visible range. sTmpRectF.left = 0; 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) { @@ -1068,19 +1069,23 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc break; } } + curScreen = i; if (range[0] < 0) { - range[0] = currPageIndex; + range[0] = curScreen; } - lastVisiblePageIndex = currPageIndex; } - range[1] = lastVisiblePageIndex; + range[1] = curScreen; } else { range[0] = -1; range[1] = -1; } } + 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 e983e79762..7fa71f291a 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -170,6 +170,7 @@ public class Workspace extends PagedView @Thunk float[] mDragViewVisualCenter = new float[2]; private float[] mTempCellLayoutCenterCoordinates = new float[2]; private int[] mTempVisiblePagesRange = new int[2]; + private Matrix mTempMatrix = new Matrix(); private SpringLoadedDragController mSpringLoadedDragController; private float mSpringLoadedShrinkFactor; @@ -1297,6 +1298,7 @@ public class Workspace extends PagedView 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 @@ -1314,6 +1316,18 @@ public class Workspace extends PagedView } } + @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);