From f698c6ebda06997aae998e262ab1714c625ff3b1 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Wed, 17 Jul 2013 18:44:25 -0700 Subject: [PATCH] Simplifying some more stuff related to PagedView Change-Id: I25d41697f4514825664a05e78df1e24fc81c492a --- src/com/android/launcher3/PagedView.java | 54 ++++++++---------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 553f86d1d7..8027fa19c9 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -104,7 +104,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected boolean mFirstLayout = true; protected int mCurrentPage; - protected int mChildCountOnLastMeasure; + protected int mChildCountOnLastLayout; protected int mNextPage = INVALID_PAGE; protected int mMaxScrollX; @@ -783,19 +783,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc mRecomputePageSpacing = false; } } - - if (mScroller.isFinished() && mChildCountOnLastMeasure != getChildCount() && - !mDeferringForDelete) { - setCurrentPage(getNextPage()); - } - mChildCountOnLastMeasure = getChildCount(); - - if (childCount > 0) { - final int index = isLayoutRtl() ? 0 : childCount - 1; - mMaxScrollX = getChildOffset(index) - getRelativeChildOffset(index); - } else { - mMaxScrollX = 0; - } } public void setPageSpacing(int pageSpacing) { @@ -857,6 +844,19 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc setHorizontalScrollBarEnabled(true); mFirstLayout = false; } + + if (childCount > 0) { + final int index = isLayoutRtl() ? 0 : childCount - 1; + mMaxScrollX = getChildOffset(index) - getRelativeChildOffset(index); + } else { + mMaxScrollX = 0; + } + + if (mScroller.isFinished() && mChildCountOnLastLayout != getChildCount() && + !mDeferringForDelete) { + setCurrentPage(getNextPage()); + } + mChildCountOnLastLayout = getChildCount(); } protected void screenScrolled(int screenCenter) { @@ -942,15 +942,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected void invalidateCachedOffsets() { int count = getChildCount(); if (count == 0) { - mChildOffsets = null; mChildRelativeOffsets = null; return; } - mChildOffsets = new int[count]; mChildRelativeOffsets = new int[count]; for (int i = 0; i < count; i++) { - mChildOffsets[i] = -1; mChildRelativeOffsets[i] = -1; } } @@ -959,28 +956,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (index < 0 || index > getChildCount() - 1) return 0; final boolean isRtl = isLayoutRtl(); - int[] childOffsets = mChildOffsets; - if (childOffsets != null && childOffsets[index] != -1) { - return childOffsets[index]; - } else { - if (getChildCount() == 0) - return 0; - - final int startIndex = isRtl ? getChildCount() - 1 : 0; - final int endIndex = isRtl ? index : index; - final int delta = isRtl ? -1 : 1; - - int offset = getRelativeChildOffset(startIndex); - for (int i = startIndex; i != endIndex; i += delta) { - offset += getPageAt(i).getMeasuredWidth() + mPageSpacing; - } - if (childOffsets != null) { - childOffsets[index] = offset; - } - return offset; - } + if (isRtl) index = getChildCount() - index - 1; + int offset = getPageAt(index).getLeft() - getViewportOffsetX(); + return offset; } protected int getRelativeChildOffset(int index) {