Methods Summary |
---|
public void | cancelDecrement()
mDecrement = false;
|
public void | cancelIncrement()
mIncrement = false;
|
private void | changeCurrent(int current)
// Wrap around the values if we go past the start or end
if (current > mEnd) {
current = mStart;
} else if (current < mStart) {
current = mEnd;
}
mPrevious = mCurrent;
mCurrent = current;
notifyChange();
updateView();
|
private java.lang.String | formatNumber(int value)
return (mFormatter != null)
? mFormatter.toString(value)
: String.valueOf(value);
|
public int | getCurrent()
return mCurrent;
|
private int | getSelectedPos(java.lang.String str)
if (mDisplayedValues == null) {
return Integer.parseInt(str);
} else {
for (int i = 0; i < mDisplayedValues.length; i++) {
/* Don't force the user to type in jan when ja will do */
str = str.toLowerCase();
if (mDisplayedValues[i].toLowerCase().startsWith(str)) {
return mStart + i;
}
}
/* The user might have typed in a number into the month field i.e.
* 10 instead of OCT so support that too.
*/
try {
return Integer.parseInt(str);
} catch (NumberFormatException e) {
/* Ignore as if it's not a number we don't care */
}
}
return mStart;
|
private void | notifyChange()
if (mListener != null) {
mListener.onChanged(this, mPrevious, mCurrent);
}
|
public void | onClick(android.view.View v)
validateInput(mText);
if (!mText.hasFocus()) mText.requestFocus();
// now perform the increment/decrement
if (R.id.increment == v.getId()) {
changeCurrent(mCurrent + 1);
} else if (R.id.decrement == v.getId()) {
changeCurrent(mCurrent - 1);
}
|
public void | onFocusChange(android.view.View v, boolean hasFocus)
/* When focus is lost check that the text field
* has valid values.
*/
if (!hasFocus) {
validateInput(v);
}
|
public boolean | onLongClick(android.view.View v)We start the long click here but rely on the {@link NumberPickerButton}
to inform us when the long click has ended.
/* The text view may still have focus so clear it's focus which will
* trigger the on focus changed and any typed values to be pulled.
*/
mText.clearFocus();
if (R.id.increment == v.getId()) {
mIncrement = true;
mHandler.post(mRunnable);
} else if (R.id.decrement == v.getId()) {
mDecrement = true;
mHandler.post(mRunnable);
}
return true;
|
public void | setCurrent(int current)
mCurrent = current;
updateView();
|
public void | setEnabled(boolean enabled)
super.setEnabled(enabled);
mIncrementButton.setEnabled(enabled);
mDecrementButton.setEnabled(enabled);
mText.setEnabled(enabled);
|
public void | setFormatter(com.android.internal.widget.NumberPicker$Formatter formatter)
mFormatter = formatter;
|
public void | setOnChangeListener(com.android.internal.widget.NumberPicker$OnChangedListener listener)
mListener = listener;
|
public void | setRange(int start, int end)Set the range of numbers allowed for the number picker. The current
value will be automatically set to the start.
mStart = start;
mEnd = end;
mCurrent = start;
updateView();
|
public void | setRange(int start, int end, java.lang.String[] displayedValues)Set the range of numbers allowed for the number picker. The current
value will be automatically set to the start. Also provide a mapping
for values used to display to the user.
mDisplayedValues = displayedValues;
mStart = start;
mEnd = end;
mCurrent = start;
updateView();
|
public void | setSpeed(long speed)The speed (in milliseconds) at which the numbers will scroll
when the the +/- buttons are longpressed. Default is 300ms.
mSpeed = speed;
|
private void | updateView()
/* If we don't have displayed values then use the
* current number else find the correct value in the
* displayed values for the current number.
*/
if (mDisplayedValues == null) {
mText.setText(formatNumber(mCurrent));
} else {
mText.setText(mDisplayedValues[mCurrent - mStart]);
}
mText.setSelection(mText.getText().length());
|
private void | validateCurrentView(java.lang.CharSequence str)
int val = getSelectedPos(str.toString());
if ((val >= mStart) && (val <= mEnd)) {
mPrevious = mCurrent;
mCurrent = val;
notifyChange();
}
updateView();
|
private void | validateInput(android.view.View v)
String str = String.valueOf(((TextView) v).getText());
if ("".equals(str)) {
// Restore to the old value as we don't allow empty values
updateView();
} else {
// Check the new value and ensure it's in range
validateCurrentView(str);
}
|