Merge "NumberPicker should not throw an exception if no enough values for wrapping."
diff --git a/api/current.txt b/api/current.txt
index 8d6a135..85f36339 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -26676,6 +26676,7 @@
     method public void setOnValueChangedListener(android.widget.NumberPicker.OnValueChangeListener);
     method public void setValue(int);
     method public void setWrapSelectorWheel(boolean);
+    field public static final int SELECTOR_WHEEL_ITEM_COUNT = 5; // 0x5
   }
 
   public static abstract interface NumberPicker.Formatter {
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 @@
 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 @@
      * 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();
         }