summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Powell <adamp@google.com> 2015-06-02 17:47:50 -0700
committer Adam Powell <adamp@google.com> 2015-06-03 10:56:45 -0700
commita3aa6d827860a27217b147aca6baf44fe14d1db3 (patch)
tree0b0eabcdceb61bebc26fd948eea2f0d190bb4ab1
parente25f6587d84c94331b2692e4eb6a2c1cbeb4be5b (diff)
Properly restore RTL state in HorizontalScrollView
Fix an incorrect unparceling of the previous saved state in HorizontalScrollView. Remove an unneeded field in the saved state by storing scroll offset from start instead of scrollX + isRtl. Bug 20666194 Change-Id: I1ec45b3e3bd0846b5f659356df7ff94f42e61055
-rw-r--r--core/java/android/widget/HorizontalScrollView.java24
1 files changed, 9 insertions, 15 deletions
diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java
index cf67905af3d6..ebc7eb3e3646 100644
--- a/core/java/android/widget/HorizontalScrollView.java
+++ b/core/java/android/widget/HorizontalScrollView.java
@@ -1505,11 +1505,9 @@ public class HorizontalScrollView extends FrameLayout {
final int scrollRange = Math.max(0,
childWidth - (r - l - mPaddingLeft - mPaddingRight));
if (mSavedState != null) {
- if (isLayoutRtl() == mSavedState.isLayoutRtl) {
- mScrollX = mSavedState.scrollPosition;
- } else {
- mScrollX = scrollRange - mSavedState.scrollPosition;
- }
+ mScrollX = isLayoutRtl()
+ ? scrollRange - mSavedState.scrollOffsetFromStart
+ : mSavedState.scrollOffsetFromStart;
mSavedState = null;
} else {
if (isLayoutRtl()) {
@@ -1692,8 +1690,7 @@ public class HorizontalScrollView extends FrameLayout {
}
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
- ss.scrollPosition = mScrollX;
- ss.isLayoutRtl = isLayoutRtl();
+ ss.scrollOffsetFromStart = isLayoutRtl() ? -mScrollX : mScrollX;
return ss;
}
@@ -1705,8 +1702,7 @@ public class HorizontalScrollView extends FrameLayout {
}
static class SavedState extends BaseSavedState {
- public int scrollPosition;
- public boolean isLayoutRtl;
+ public int scrollOffsetFromStart;
SavedState(Parcelable superState) {
super(superState);
@@ -1714,23 +1710,21 @@ public class HorizontalScrollView extends FrameLayout {
public SavedState(Parcel source) {
super(source);
- scrollPosition = source.readInt();
- isLayoutRtl = (source.readInt() == 0) ? true : false;
+ scrollOffsetFromStart = source.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
- dest.writeInt(scrollPosition);
- dest.writeInt(isLayoutRtl ? 1 : 0);
+ dest.writeInt(scrollOffsetFromStart);
}
@Override
public String toString() {
return "HorizontalScrollView.SavedState{"
+ Integer.toHexString(System.identityHashCode(this))
- + " scrollPosition=" + scrollPosition
- + " isLayoutRtl=" + isLayoutRtl + "}";
+ + " scrollPosition=" + scrollOffsetFromStart
+ + "}";
}
public static final Parcelable.Creator<SavedState> CREATOR