diff options
| author | Doris Liu <tianliu@google.com> | 2015-06-19 15:00:24 -0700 |
|---|---|---|
| committer | Doris Liu <tianliu@google.com> | 2015-06-19 16:33:39 -0700 |
| commit | bcfdead943ace3bc3f870979849db1885466ebf3 (patch) | |
| tree | 7bcbd4e471a25914e0dc8340640943d712a8b20e /core/java/android/widget/NumberPicker.java | |
| parent | 728b7500b3d34cd89f7aff0bad1bb7fe3e097f11 (diff) | |
Fix NumberPicker.setWrapSelectorWheel(boolean) not respecting user choice
The issue states that NumberPicker.setWrapSelectorWheel(false) only works
in a specific call order. The underlying problem is that NumberPicker
does not remember user's preference on whether the selector wheel should
be wrapped. Therefore, it only works when user sets their preference last,
after everything else that could affect the choice gets executed.
Bug: 19049714
Change-Id: Ic27d909cb3dd657993a4df9a04c819b6965ad11b
Diffstat (limited to 'core/java/android/widget/NumberPicker.java')
| -rw-r--r-- | core/java/android/widget/NumberPicker.java | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index e7d9226d66bc..b5fae4ed17a9 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -149,6 +149,11 @@ public class NumberPicker extends LinearLayout { private static final int SIZE_UNSPECIFIED = -1; /** + * User choice on whether the selector wheel should be wrapped. + */ + private boolean mWrapSelectorWheelPreferred = true; + + /** * Use a custom NumberPicker formatting callback to use two-digit minutes * strings like "01". Keeping a static formatter etc. is the most efficient * way to do this; it avoids creating temporary objects on every call to @@ -1353,10 +1358,21 @@ public class NumberPicker extends LinearLayout { * @param wrapSelectorWheel Whether to wrap. */ public void setWrapSelectorWheel(boolean wrapSelectorWheel) { + mWrapSelectorWheelPreferred = wrapSelectorWheel; + updateWrapSelectorWheel(); + + } + + /** + * Whether or not the selector wheel should be wrapped is determined by user choice and whether + * the choice is allowed. The former comes from {@link #setWrapSelectorWheel(boolean)}, the + * latter is calculated based on min & max value set vs selector's visual length. Therefore, + * this method should be called any time any of the 3 values (i.e. user choice, min and max + * value) gets updated. + */ + private void updateWrapSelectorWheel() { final boolean wrappingAllowed = (mMaxValue - mMinValue) >= mSelectorIndices.length; - if ((!wrapSelectorWheel || wrappingAllowed) && wrapSelectorWheel != mWrapSelectorWheel) { - mWrapSelectorWheel = wrapSelectorWheel; - } + mWrapSelectorWheel = wrappingAllowed && mWrapSelectorWheelPreferred; } /** @@ -1412,8 +1428,7 @@ public class NumberPicker extends LinearLayout { if (mMinValue > mValue) { mValue = mMinValue; } - boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length; - setWrapSelectorWheel(wrapSelectorWheel); + updateWrapSelectorWheel(); initializeSelectorWheelIndices(); updateInputTextView(); tryComputeMaxWidth(); @@ -1450,8 +1465,7 @@ public class NumberPicker extends LinearLayout { if (mMaxValue < mValue) { mValue = mMaxValue; } - boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length; - setWrapSelectorWheel(wrapSelectorWheel); + updateWrapSelectorWheel(); initializeSelectorWheelIndices(); updateInputTextView(); tryComputeMaxWidth(); |
