From 4de0974c460ce6439cce7931fb0ba945095a4b94 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 12 Dec 2013 16:16:39 -0800 Subject: [PATCH] Fix NPE from feedback (issue 12106858) Change-Id: I63f7f73b85d4c1652d1e722f94c51b567a83cc6b --- src/com/android/launcher3/PagedView.java | 26 +++++++++++++------------- src/com/android/launcher3/Workspace.java | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index c216f926f..1e4f4fa7f 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -1152,22 +1152,22 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc @Override protected void dispatchDraw(Canvas canvas) { - int halfScreenSize = getViewportWidth() / 2; - // mOverScrollX is equal to getScrollX() when we're within the normal scroll range. - // Otherwise it is equal to the scaled overscroll position. - int screenCenter = mOverScrollX + halfScreenSize; - - if (screenCenter != mLastScreenCenter || mForceScreenScrolled) { - // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can - // set it for the next frame - mForceScreenScrolled = false; - screenScrolled(screenCenter); - mLastScreenCenter = screenCenter; - } - // Find out which screens are visible; as an optimization we only call draw on them final int pageCount = getChildCount(); if (pageCount > 0) { + int halfScreenSize = getViewportWidth() / 2; + // mOverScrollX is equal to getScrollX() when we're within the normal scroll range. + // Otherwise it is equal to the scaled overscroll position. + int screenCenter = mOverScrollX + halfScreenSize; + + if (screenCenter != mLastScreenCenter || mForceScreenScrolled) { + // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can + // set it for the next frame + mForceScreenScrolled = false; + screenScrolled(screenCenter); + mLastScreenCenter = screenCenter; + } + getVisiblePages(mTempVisiblePagesRange); final int leftScreen = mTempVisiblePagesRange[0]; final int rightScreen = mTempVisiblePagesRange[1]; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 72399e4ec..52420b73b 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1666,7 +1666,7 @@ public class Workspace extends SmoothPagedView cl.setOverscrollTransformsDirty(true); } } else { - if (mOverscrollTransformsSet) { + if (mOverscrollTransformsSet && getChildCount() > 0) { mOverscrollTransformsSet = false; ((CellLayout) getChildAt(0)).resetOverscrollTransforms(); ((CellLayout) getChildAt(getChildCount() - 1)).resetOverscrollTransforms(); -- 2.11.0