Skip to content

Commit

Permalink
Revert "NumberPicker should adjust min and max when displayed values …
Browse files Browse the repository at this point in the history
…are set." (a.k.a. Santa is back)

This reverted change was adjusting the min and max values for the NumberPicker
which is not desirable since it changes behavior and it will be possible for
an app that works on the current platform to crash on an older one. Also the
adjustment was not implemented correctly.

Updated the documentation to clarify the reltionship between the min value,
max value, and the displayed values array.

Bug:7518172

This reverts commit a1410e6

Change-Id: I109f1b1f54c1e609941243cabab9241871b6b12b
  • Loading branch information
sganov authored and The Android Automerger committed Nov 20, 2012
1 parent cc2e849 commit b361b30
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions core/java/android/widget/NumberPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,12 @@ public int getMinValue() {
/**
* Sets the min value of the picker.
*
* @param minValue The min value.
* @param minValue The min value inclusive.
*
* <strong>Note:</strong> The length of the displayed values array
* set via {@link #setDisplayedValues(String[])} must be equal to the
* range of selectable numbers which is equal to
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
*/
public void setMinValue(int minValue) {
if (mMinValue == minValue) {
Expand Down Expand Up @@ -1317,7 +1322,12 @@ public int getMaxValue() {
/**
* Sets the max value of the picker.
*
* @param maxValue The max value.
* @param maxValue The max value inclusive.
*
* <strong>Note:</strong> The length of the displayed values array
* set via {@link #setDisplayedValues(String[])} must be equal to the
* range of selectable numbers which is equal to
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
*/
public void setMaxValue(int maxValue) {
if (mMaxValue == maxValue) {
Expand Down Expand Up @@ -1351,6 +1361,10 @@ public String[] getDisplayedValues() {
* Sets the values to be displayed.
*
* @param displayedValues The displayed values.
*
* <strong>Note:</strong> The length of the displayed values array
* must be equal to the range of selectable numbers which is equal to
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
*/
public void setDisplayedValues(String[] displayedValues) {
if (mDisplayedValues == displayedValues) {
Expand All @@ -1361,14 +1375,6 @@ public void setDisplayedValues(String[] displayedValues) {
// Allow text entry rather than strictly numeric entry.
mInputText.setRawInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
// Make sure the min, max, respect the size of the displayed
// values. This will take care of the current value as well.
if (getMinValue() >= displayedValues.length) {
setMinValue(0);
}
if (getMaxValue() >= displayedValues.length) {
setMaxValue(displayedValues.length - 1);
}
} else {
mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
}
Expand Down

0 comments on commit b361b30

Please sign in to comment.