summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2012-04-30 15:23:15 -0700
committerWinson Chung <winsonc@google.com>2012-04-30 15:23:53 -0700
commita128a7b9e5f00559ad6a443f7be8e8d7591942a3 (patch)
treeadbc9ef3ca1e1cb702d8f918e36932a8d3a347b4
parentd7c28056d3fc462f42b508026154d6d8fee5606b (diff)
downloadandroid_packages_apps_Trebuchet-a128a7b9e5f00559ad6a443f7be8e8d7591942a3.tar.gz
android_packages_apps_Trebuchet-a128a7b9e5f00559ad6a443f7be8e8d7591942a3.tar.bz2
android_packages_apps_Trebuchet-a128a7b9e5f00559ad6a443f7be8e8d7591942a3.zip
Fixing issue where last workspace page was offset when rotated. (Bug 6413570)
- Also adding check to prevent NPE in updating scroll indicator Change-Id: If445be7fa00497bd21a4b9a6f9ebce93ceb30f2c
-rw-r--r--src/com/android/launcher2/PagedView.java61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 4bcb4c7d4..adfe0de81 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;