From 3f9c9eab7b41c409c3c7b503b89ad340e408b6a0 Mon Sep 17 00:00:00 2001
From: Svetoslav Ganov
Date: Tue, 24 Jan 2012 12:02:31 -0800
Subject: 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
---
core/java/android/widget/NumberPicker.java | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
(limited to 'core/java/android/widget/NumberPicker.java')
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.
*
- *
+ *
+ * Note: 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.
+ *
* @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();
}
--
cgit v1.1