diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-01-24 12:02:31 -0800 |
---|---|---|
committer | Svetoslav Ganov <svetoslavganov@google.com> | 2012-01-24 12:09:11 -0800 |
commit | 3f9c9eab7b41c409c3c7b503b89ad340e408b6a0 (patch) | |
tree | 5e56e93d10668f08cb2af2b763ed0b8f5bc39c5f /core/java/android/widget/NumberPicker.java | |
parent | d4e34d61d01222ff90684b9a1dc4f9c8be560e7c (diff) | |
download | frameworks_base-3f9c9eab7b41c409c3c7b503b89ad340e408b6a0.zip frameworks_base-3f9c9eab7b41c409c3c7b503b89ad340e408b6a0.tar.gz frameworks_base-3f9c9eab7b41c409c3c7b503b89ad340e408b6a0.tar.bz2 |
NumberPicker should not throw an exception if no enough values for wrapping.
1. The selector wheel was throwing an exception if a client requires that it
wraps its selector wheel if the number of values is less that the number
of values shown in the wheel. While wrapping makes no sense if the all
possible values are already shown, we should not throw an exception,
rather to ignore the request.
bug:5911190
Change-Id: Icd90cd39f66d9f39939801752bf1eb1eef8fe757
Diffstat (limited to 'core/java/android/widget/NumberPicker.java')
-rw-r--r-- | core/java/android/widget/NumberPicker.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index a210f0b..182df7a 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -71,6 +71,11 @@ import com.android.internal.R; public class NumberPicker extends LinearLayout { /** + * The number of items show in the selector wheel. + */ + public static final int SELECTOR_WHEEL_ITEM_COUNT = 5; + + /** * The default update interval during long press. */ private static final long DEFAULT_LONG_PRESS_UPDATE_INTERVAL = 300; @@ -1137,14 +1142,17 @@ public class NumberPicker extends LinearLayout { * items shown on the selector wheel) the selector wheel wrapping is * enabled. * </p> - * + * <p> + * <strong>Note:</strong> If the number of items, i.e. the range + * ({@link #getMaxValue()} - {@link #getMinValue()}) is less than + * {@link #SELECTOR_WHEEL_ITEM_COUNT}, the selector wheel will not + * wrap. Hence, in such a case calling this method is a NOP. + * </p> * @param wrapSelectorWheel Whether to wrap. */ public void setWrapSelectorWheel(boolean wrapSelectorWheel) { - if (wrapSelectorWheel && (mMaxValue - mMinValue) < mSelectorIndices.length) { - throw new IllegalStateException("Range less than selector items count."); - } - if (wrapSelectorWheel != mWrapSelectorWheel) { + final boolean wrappingAllowed = (mMaxValue - mMinValue) >= mSelectorIndices.length; + if ((!wrapSelectorWheel || wrappingAllowed) && wrapSelectorWheel != mWrapSelectorWheel) { mWrapSelectorWheel = wrapSelectorWheel; updateIncrementAndDecrementButtonsVisibilityState(); } |