diff options
author | Winson Chung <winsonc@google.com> | 2012-04-30 15:41:32 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-04-30 15:41:32 -0700 |
commit | 30ae706668cca53a3fd4a233352be69be0aa5fbd (patch) | |
tree | 40fb566635d8a23b179514d6317ad3520f68f355 | |
parent | 7d2d6b5f0972354df05249082d4179dcdc442723 (diff) | |
parent | a128a7b9e5f00559ad6a443f7be8e8d7591942a3 (diff) | |
download | packages_apps_trebuchet-30ae706668cca53a3fd4a233352be69be0aa5fbd.zip packages_apps_trebuchet-30ae706668cca53a3fd4a233352be69be0aa5fbd.tar.gz packages_apps_trebuchet-30ae706668cca53a3fd4a233352be69be0aa5fbd.tar.bz2 |
Merge "Fixing issue where last workspace page was offset when rotated. (Bug 6413570)" into jb-dev
-rw-r--r-- | src/com/android/launcher2/PagedView.java | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 4bcb4c7..adfe0de 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -292,7 +292,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc * the previous tab page. */ protected void updateCurrentPageScroll() { - int newX = getChildOffset(mCurrentPage) - getRelativeChildOffset(mCurrentPage); + int offset = getChildOffset(mCurrentPage); + int relOffset = getRelativeChildOffset(mCurrentPage); + int newX = offset - relOffset; scrollTo(newX, 0); mScroller.setFinalX(newX); mScroller.forceFinished(true); @@ -505,6 +507,23 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc setMeasuredDimension(widthSize, heightSize); + if (childCount > 0) { + if (DEBUG) Log.d(TAG, "getRelativeChildOffset(): " + getMeasuredWidth() + ", " + + getChildWidth(0)); + + // Calculate the variable page spacing if necessary + if (mPageSpacing < 0) { + // The gap between pages in the PagedView should be equal to the gap from the page + // to the edge of the screen (so it is not visible in the current screen). To + // account for unequal padding on each side of the paged view, we take the maximum + // of the left/right gap and use that as the gap between each page. + int offset = getRelativeChildOffset(0); + int spacing = Math.max(offset, widthSize - offset - + getChildAt(0).getMeasuredWidth()); + setPageSpacing(spacing); + } + } + // We can't call getChildOffset/getRelativeChildOffset until we set the measured dimensions. // We also wait until we set the measured dimensions before flushing the cache as well, to // ensure that the cache is filled with good values. @@ -577,24 +596,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc if (DEBUG) Log.d(TAG, "PagedView.onLayout()"); final int verticalPadding = getPaddingTop() + getPaddingBottom(); final int childCount = getChildCount(); - int childLeft = 0; - if (childCount > 0) { - if (DEBUG) Log.d(TAG, "getRelativeChildOffset(): " + getMeasuredWidth() + ", " - + getChildWidth(0)); - childLeft = getRelativeChildOffset(0); - - // Calculate the variable page spacing if necessary - if (mPageSpacing < 0) { - // The gap between pages in the PagedView should be equal to the gap from the page - // to the edge of the screen (so it is not visible in the current screen). To - // account for unequal padding on each side of the paged view, we take the maximum - // of the left/right gap and use that as the gap between each page. - int offset = getRelativeChildOffset(0); - int spacing = Math.max(offset, (right - left) - offset - - getChildAt(0).getMeasuredWidth()); - setPageSpacing(spacing); - } - } + int childLeft = getRelativeChildOffset(0); for (int i = 0; i < childCount; i++) { final View child = getPageAt(i); @@ -619,10 +621,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc setHorizontalScrollBarEnabled(true); mFirstLayout = false; } - - if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) { - mFirstLayout = false; - } } protected void screenScrolled(int screenCenter) { @@ -709,13 +707,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } - protected int getScaledRelativeChildOffset(int index) { - final int padding = getPaddingLeft() + getPaddingRight(); - final int offset = getPaddingLeft() + (getMeasuredWidth() - padding - - getScaledMeasuredWidth(getPageAt(index))) / 2; - return offset; - } - protected int getScaledMeasuredWidth(View child) { // This functions are called enough times that it actually makes a difference in the // profiler -- so just inline the max() here @@ -1702,10 +1693,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // found if (mHasScrollIndicator && mScrollIndicator == null) { ViewGroup parent = (ViewGroup) getParent(); - mScrollIndicator = (View) (parent.findViewById(R.id.paged_view_indicator)); - mHasScrollIndicator = mScrollIndicator != null; - if (mHasScrollIndicator) { - mScrollIndicator.setVisibility(View.VISIBLE); + if (parent != null) { + mScrollIndicator = (View) (parent.findViewById(R.id.paged_view_indicator)); + mHasScrollIndicator = mScrollIndicator != null; + if (mHasScrollIndicator) { + mScrollIndicator.setVisibility(View.VISIBLE); + } } } return mScrollIndicator; |