public void setSelectedTextColor(int selectedTextColor){ if(mTextColorSelected == selectedTextColor) return; mTextColorSelected = selectedTextColor; postInvalidate(); }
private void clickItem(int showCountIndex){ if(0 <= showCountIndex && showCountIndex < mShowCount) { //clicked the showCountIndex of the view scrollByIndexSmoothly(showCountIndex - mShowCount/2); }else{ //wrong } }
private void setData(NumberPickerView picker, int minValue, int maxValue, int value){ picker.setMinValue(minValue); picker.setMaxValue(maxValue); picker.setValue(value); }
/** * get the "fromValue" by using getValue(), if your picker's minValue is not 0, * make sure you can get the accurate value by getValue(), or you can use * smoothScrollToValue(int fromValue, int toValue, boolean needRespond) * @param toValue the value you want picker to scroll to */ public void smoothScrollToValue(int toValue){ smoothScrollToValue(getValue(), toValue, true); }
public void setPickedIndexRelativeToMin(int pickedIndexToMin){ if(0 <= pickedIndexToMin && pickedIndexToMin < getOneRecycleSize()){ mPrevPickedIndex = pickedIndexToMin + mMinShowIndex; correctPositionByDefaultValue(pickedIndexToMin, mWrapSelectorWheel && mWrapSelectorWheelCheck); postInvalidate(); } }
private void updateValueForInit(){ inflateDisplayedValuesIfNull(); updateWrapStateByContent(); if(mMinShowIndex == -1){ mMinShowIndex = 0; } if(mMaxShowIndex == -1){ mMaxShowIndex = mDisplayedValues.length - 1; } setMinAndMaxShowIndex(mMinShowIndex, mMaxShowIndex, false); }
private void internalSetWrapToLinear(){ int rawIndex = getPickedIndexRelativeToRaw(); correctPositionByDefaultValue(rawIndex - mMinShowIndex, false); mWrapSelectorWheel = false; postInvalidate(); }
public void setPickedIndexRelativeToRaw(int pickedIndexToRaw){ if(mMinShowIndex > -1){ if(mMinShowIndex <= pickedIndexToRaw && pickedIndexToRaw <= mMaxShowIndex){ mPrevPickedIndex = pickedIndexToRaw; correctPositionByDefaultValue(pickedIndexToRaw - mMinShowIndex, mWrapSelectorWheel && mWrapSelectorWheelCheck); postInvalidate(); } } }
private void updateValue(){ inflateDisplayedValuesIfNull(); updateWrapStateByContent(); mMinShowIndex = 0; mMaxShowIndex = mDisplayedValues.length - 1; }
private void updateContentAndIndex(String[] newDisplayedValues){ mMinShowIndex = 0; mMaxShowIndex = newDisplayedValues.length - 1; mDisplayedValues = newDisplayedValues; updateWrapStateByContent(); }
public int getPickedIndexRelativeToRaw(){ int willPickIndex; if(mCurrDrawFirstItemY != 0){ if(mCurrDrawFirstItemY < (-mItemHeight/2)){ willPickIndex = getWillPickIndexByGlobalY(mCurrDrawGlobalY + mItemHeight + mCurrDrawFirstItemY); }else{ willPickIndex = getWillPickIndexByGlobalY(mCurrDrawGlobalY + mCurrDrawFirstItemY); } }else{ willPickIndex = getWillPickIndexByGlobalY(mCurrDrawGlobalY); } return willPickIndex; }
private void onScrollStateChange(int scrollState) { if (mScrollState == scrollState) { return; } mScrollState = scrollState; if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChange(this, scrollState); } }
public NumberPickerView(Context context) { super(context); init(context); } public NumberPickerView(Context context, AttributeSet attrs) {
public void setMinValue(int minValue){ mMinValue = minValue; mMinShowIndex = 0; updateNotWrapYLimit(); }
private void updateNotWrapYLimit(){ mNotWrapLimitYTop = 0; mNotWrapLimitYBottom = -mShowCount * mItemHeight; if(mDisplayedValues != null){ mNotWrapLimitYTop = (getOneRecycleSize() - mShowCount / 2 - 1)* mItemHeight; mNotWrapLimitYBottom = -(mShowCount / 2) * mItemHeight; } }
public int getValue(){ return getPickedIndexRelativeToRaw() + mMinValue; }
/** * get the "fromValue" by using getValue(), if your picker's minValue is not 0, * make sure you can get the accurate value by getValue(), or you can use * smoothScrollToValue(int fromValue, int toValue, boolean needRespond) * @param toValue the value you want picker to scroll to * @param needRespond set if you want picker to respond onValueChange listener */ public void smoothScrollToValue(int toValue, boolean needRespond){ smoothScrollToValue(getValue(), toValue, needRespond); }
public void setNormalTextColor(int normalTextColor){ if(mTextColorNormal == normalTextColor) return; mTextColorNormal = normalTextColor; postInvalidate(); }