From 53838d265e36fb50341af168f5a91c3341c3cfc3 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Wed, 26 Jan 2011 21:32:33 -0800 Subject: Fixing some ugly StackView relayouts on rotation Change-Id: Ic4b11637ed73e60e1af1fcd27e5610d8f84a31fe --- core/java/android/widget/AdapterViewAnimator.java | 22 +++++++--------------- core/java/android/widget/StackView.java | 15 ++++----------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java index e3a62db..190c0fc 100644 --- a/core/java/android/widget/AdapterViewAnimator.java +++ b/core/java/android/widget/AdapterViewAnimator.java @@ -280,6 +280,10 @@ public abstract class AdapterViewAnimator extends AdapterView * @param whichChild the index of the child view to display */ public void setDisplayedChild(int whichChild) { + setDisplayedChild(whichChild, true); + } + + private void setDisplayedChild(int whichChild, boolean animate) { if (mAdapter != null) { mWhichChild = whichChild; if (whichChild >= getWindowSize()) { @@ -290,7 +294,7 @@ public abstract class AdapterViewAnimator extends AdapterView boolean hasFocus = getFocusedChild() != null; // This will clear old focus if we had it - showOnly(mWhichChild); + showOnly(mWhichChild, animate); if (hasFocus) { // Try to retake focus if we had it requestFocus(FOCUS_FORWARD); @@ -793,23 +797,11 @@ public abstract class AdapterViewAnimator extends AdapterView if (mRemoteViewsAdapter != null && mAdapter == null) { mRestoreWhichChild = mWhichChild; } else { - setDisplayedChild(mWhichChild); + setDisplayedChild(mWhichChild, false); } } /** - * Shows only the specified child. The other displays Views exit the screen - * with the {@link #getOutAnimation() out animation} and the specified child - * enters the screen with the {@link #getInAnimation() in animation}. - * - * @param childIndex The index of the child to be shown. - */ - void showOnly(int childIndex) { - final boolean animate = (!mFirstTime || mAnimateFirstTime); - showOnly(childIndex, animate); - } - - /** * Returns the View corresponding to the currently displayed child. * * @return The View currently displayed. @@ -977,7 +969,7 @@ public abstract class AdapterViewAnimator extends AdapterView // Restore the previous position (see onRestoreInstanceState) if (mRestoreWhichChild > -1) { - setDisplayedChild(mRestoreWhichChild); + setDisplayedChild(mRestoreWhichChild, false); mRestoreWhichChild = -1; } return false; diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index d57d5c6..7a74241 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -549,11 +549,7 @@ public class StackView extends AdapterViewAnimator { mSlideAmount = Math.round(SLIDE_UP_RATIO * getMeasuredHeight()); mSwipeThreshold = Math.round(SWIPE_THRESHOLD_RATIO * mSlideAmount); mFirstLayoutHappened = true; - post(new Runnable() { - public void run() { - updateChildTransforms(); - } - }); + updateChildTransforms(); } if (Float.compare(mPerspectiveShiftY, mNewPerspectiveShiftY) != 0 || @@ -561,12 +557,7 @@ public class StackView extends AdapterViewAnimator { mPerspectiveShiftY = mNewPerspectiveShiftY; mPerspectiveShiftX = mNewPerspectiveShiftX; - - post(new Runnable() { - public void run() { - updateChildTransforms(); - } - }); + updateChildTransforms(); } } @@ -1120,6 +1111,8 @@ public class StackView extends AdapterViewAnimator { mNewPerspectiveShiftX = PERSPECTIVE_SHIFT_FACTOR_X * measuredWidth; mNewPerspectiveShiftY = PERSPECTIVE_SHIFT_FACTOR_Y * measuredHeight; + + // If we have extra space, we try and spread the items out if (maxWidth > 0 && count > 0 && maxWidth < childWidth) { mNewPerspectiveShiftX = measuredWidth - maxWidth; } -- cgit v1.1