am 4a799925: Merge "Fix NumberPicker.setWrapSelectorWheel(boolean) not respecting user choice" into mnc-dev
* commit '4a79992591bd9971764b504bfe10cad656edf632': Fix NumberPicker.setWrapSelectorWheel(boolean) not respecting user choice
This commit is contained in:
@@ -148,6 +148,11 @@ public class NumberPicker extends LinearLayout {
|
|||||||
*/
|
*/
|
||||||
private static final int SIZE_UNSPECIFIED = -1;
|
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
|
* Use a custom NumberPicker formatting callback to use two-digit minutes
|
||||||
* strings like "01". Keeping a static formatter etc. is the most efficient
|
* strings like "01". Keeping a static formatter etc. is the most efficient
|
||||||
@@ -1353,10 +1358,21 @@ public class NumberPicker extends LinearLayout {
|
|||||||
* @param wrapSelectorWheel Whether to wrap.
|
* @param wrapSelectorWheel Whether to wrap.
|
||||||
*/
|
*/
|
||||||
public void setWrapSelectorWheel(boolean wrapSelectorWheel) {
|
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;
|
final boolean wrappingAllowed = (mMaxValue - mMinValue) >= mSelectorIndices.length;
|
||||||
if ((!wrapSelectorWheel || wrappingAllowed) && wrapSelectorWheel != mWrapSelectorWheel) {
|
mWrapSelectorWheel = wrappingAllowed && mWrapSelectorWheelPreferred;
|
||||||
mWrapSelectorWheel = wrapSelectorWheel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1412,8 +1428,7 @@ public class NumberPicker extends LinearLayout {
|
|||||||
if (mMinValue > mValue) {
|
if (mMinValue > mValue) {
|
||||||
mValue = mMinValue;
|
mValue = mMinValue;
|
||||||
}
|
}
|
||||||
boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
|
updateWrapSelectorWheel();
|
||||||
setWrapSelectorWheel(wrapSelectorWheel);
|
|
||||||
initializeSelectorWheelIndices();
|
initializeSelectorWheelIndices();
|
||||||
updateInputTextView();
|
updateInputTextView();
|
||||||
tryComputeMaxWidth();
|
tryComputeMaxWidth();
|
||||||
@@ -1450,8 +1465,7 @@ public class NumberPicker extends LinearLayout {
|
|||||||
if (mMaxValue < mValue) {
|
if (mMaxValue < mValue) {
|
||||||
mValue = mMaxValue;
|
mValue = mMaxValue;
|
||||||
}
|
}
|
||||||
boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
|
updateWrapSelectorWheel();
|
||||||
setWrapSelectorWheel(wrapSelectorWheel);
|
|
||||||
initializeSelectorWheelIndices();
|
initializeSelectorWheelIndices();
|
||||||
updateInputTextView();
|
updateInputTextView();
|
||||||
tryComputeMaxWidth();
|
tryComputeMaxWidth();
|
||||||
|
|||||||
Reference in New Issue
Block a user