diff --git a/README.md b/README.md
index fe60bba..2418d64 100644
--- a/README.md
+++ b/README.md
@@ -82,7 +82,8 @@ add `xmlns:app="http://schemas.android.com/apk/res-auto"`
|np_textColor|The text color of the numbers.|
|np_textSize|The text size of the numbers.|
|np_typeface|The typeface of the numbers.|
-|np_wheel_item_count|The number of items show in the selector wheel.|
+|np_wheelItemCount|The number of items show in the selector wheel.|
+|np_wrapSelectorWheel|Flag whether the selector should wrap around.|
## Gradle
@@ -96,7 +97,7 @@ buildscript {
}
dependencies {
- compile 'com.shawnlin:number-picker:2.2.0'
+ compile 'com.shawnlin:number-picker:2.3.0'
}
```
diff --git a/gradle.properties b/gradle.properties
index cb8f209..07e7743 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
-VERSION_CODE=6
-VERSION_NAME=2.2.0
+VERSION_CODE=7
+VERSION_NAME=2.3.0
GROUP=com.shawnlin
ARTIFACT_ID=number-picker
diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
index 729dd8f..528ba1d 100644
--- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
+++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
@@ -584,8 +584,7 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
mTextSize = attributesArray.getDimension(R.styleable.NumberPicker_np_textSize, mTextSize);
mTypeface = Typeface.create(attributesArray.getString(R.styleable.NumberPicker_np_typeface), Typeface.NORMAL);
mFormatter = stringToFormatter(attributesArray.getString(R.styleable.NumberPicker_np_formatter));
- mWheelItemCount = attributesArray.getInt(R.styleable.NumberPicker_np_wheel_item_count, mWheelItemCount);
- attributesArray.recycle();
+ mWheelItemCount = attributesArray.getInt(R.styleable.NumberPicker_np_wheelItemCount, mWheelItemCount);
// By default Linearlayout that we extend is not drawn. This is
// its draw() method is not called but dispatchDraw() is called
@@ -628,6 +627,9 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
setWheelItemCount(mWheelItemCount);
+ mWrapSelectorWheel = attributesArray.getBoolean(R.styleable.NumberPicker_np_wrapSelectorWheel, mWrapSelectorWheel);
+ setWrapSelectorWheel(mWrapSelectorWheel);
+
if (mWidth != SIZE_UNSPECIFIED && mHeight != SIZE_UNSPECIFIED) {
setScaleX(mWidth / mMinWidth);
setScaleY(mHeight / mMaxHeight);
@@ -655,6 +657,8 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
}
}
+
+ attributesArray.recycle();
}
@Override
@@ -858,8 +862,6 @@ public boolean onTouchEvent(MotionEvent event) {
}
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
}
- mVelocityTracker.recycle();
- mVelocityTracker = null;
} else {
int initialVelocity = (int) velocityTracker.getYVelocity();
if (Math.abs(initialVelocity) > mMinimumFlingVelocity) {
@@ -880,9 +882,9 @@ public boolean onTouchEvent(MotionEvent event) {
}
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
}
- mVelocityTracker.recycle();
- mVelocityTracker = null;
}
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
}
break;
}
@@ -1040,51 +1042,51 @@ public void setEnabled(boolean enabled) {
@Override
public void scrollBy(int x, int y) {
int[] selectorIndices = mSelectorIndices;
- if (!mWrapSelectorWheel && y > 0
+ int gap;
+ if (isHorizontalMode()) {
+ if (!mWrapSelectorWheel && x > 0
&& selectorIndices[mWheelMiddleItemIndex] <= mMinValue) {
- mCurrentScrollOffset = mInitialScrollOffset;
- return;
- }
- if (!mWrapSelectorWheel && y < 0
+ mCurrentScrollOffset = mInitialScrollOffset;
+ return;
+ }
+ if (!mWrapSelectorWheel && x < 0
&& selectorIndices[mWheelMiddleItemIndex] >= mMaxValue) {
- mCurrentScrollOffset = mInitialScrollOffset;
- return;
- }
- if (isHorizontalMode()) {
+ mCurrentScrollOffset = mInitialScrollOffset;
+ return;
+ }
+
mCurrentScrollOffset += x;
- while (mCurrentScrollOffset - mInitialScrollOffset > mSelectorTextGapWidth) {
- mCurrentScrollOffset -= mSelectorElementSize;
- decrementSelectorIndices(selectorIndices);
- setValueInternal(selectorIndices[mWheelMiddleItemIndex], true);
- if (!mWrapSelectorWheel && selectorIndices[mWheelMiddleItemIndex] <= mMinValue) {
- mCurrentScrollOffset = mInitialScrollOffset;
- }
+ gap = mSelectorTextGapWidth;
+ } else {
+ if (!mWrapSelectorWheel && y > 0
+ && selectorIndices[mWheelMiddleItemIndex] <= mMinValue) {
+ mCurrentScrollOffset = mInitialScrollOffset;
+ return;
}
- while (mCurrentScrollOffset - mInitialScrollOffset < -mSelectorTextGapWidth) {
- mCurrentScrollOffset += mSelectorElementSize;
- incrementSelectorIndices(selectorIndices);
- setValueInternal(selectorIndices[mWheelMiddleItemIndex], true);
- if (!mWrapSelectorWheel && selectorIndices[mWheelMiddleItemIndex] >= mMaxValue) {
- mCurrentScrollOffset = mInitialScrollOffset;
- }
+ if (!mWrapSelectorWheel && y < 0
+ && selectorIndices[mWheelMiddleItemIndex] >= mMaxValue) {
+ mCurrentScrollOffset = mInitialScrollOffset;
+ return;
}
- } else {
+
mCurrentScrollOffset += y;
- while (mCurrentScrollOffset - mInitialScrollOffset > mSelectorTextGapHeight) {
- mCurrentScrollOffset -= mSelectorElementSize;
- decrementSelectorIndices(selectorIndices);
- setValueInternal(selectorIndices[mWheelMiddleItemIndex], true);
- if (!mWrapSelectorWheel && selectorIndices[mWheelMiddleItemIndex] <= mMinValue) {
- mCurrentScrollOffset = mInitialScrollOffset;
- }
+ gap = mSelectorTextGapHeight;
+ }
+
+ while (mCurrentScrollOffset - mInitialScrollOffset > gap) {
+ mCurrentScrollOffset -= mSelectorElementSize;
+ decrementSelectorIndices(selectorIndices);
+ setValueInternal(selectorIndices[mWheelMiddleItemIndex], true);
+ if (!mWrapSelectorWheel && selectorIndices[mWheelMiddleItemIndex] <= mMinValue) {
+ mCurrentScrollOffset = mInitialScrollOffset;
}
- while (mCurrentScrollOffset - mInitialScrollOffset < -mSelectorTextGapHeight) {
- mCurrentScrollOffset += mSelectorElementSize;
- incrementSelectorIndices(selectorIndices);
- setValueInternal(selectorIndices[mWheelMiddleItemIndex], true);
- if (!mWrapSelectorWheel && selectorIndices[mWheelMiddleItemIndex] >= mMaxValue) {
- mCurrentScrollOffset = mInitialScrollOffset;
- }
+ }
+ while (mCurrentScrollOffset - mInitialScrollOffset < -gap) {
+ mCurrentScrollOffset += mSelectorElementSize;
+ incrementSelectorIndices(selectorIndices);
+ setValueInternal(selectorIndices[mWheelMiddleItemIndex], true);
+ if (!mWrapSelectorWheel && selectorIndices[mWheelMiddleItemIndex] >= mMaxValue) {
+ mCurrentScrollOffset = mInitialScrollOffset;
}
}
}
@@ -1637,17 +1639,16 @@ private void initializeSelectorWheel() {
initializeSelectorWheelIndices();
int[] selectorIndices = mSelectorIndices;
int totalTextSize = selectorIndices.length * (int) mTextSize;
+ float textGapCount = selectorIndices.length;
int editTextTextPosition;
if (isHorizontalMode()) {
float totalTextGapWidth = (getRight() - getLeft()) - totalTextSize;
- float textGapCount = selectorIndices.length;
mSelectorTextGapWidth = (int) (totalTextGapWidth / textGapCount + 0.5f);
mSelectorElementSize = (int) mTextSize + mSelectorTextGapWidth;
// Ensure that the middle item is positioned the same as the text in mInputText
editTextTextPosition = mInputText.getRight() / 2;
} else {
float totalTextGapHeight = (getBottom() - getTop()) - totalTextSize;
- float textGapCount = selectorIndices.length;
mSelectorTextGapHeight = (int) (totalTextGapHeight / textGapCount + 0.5f);
mSelectorElementSize = (int) mTextSize + mSelectorTextGapHeight;
// Ensure that the middle item is positioned the same as the text in mInputText
@@ -1677,10 +1678,8 @@ private void onScrollerFinished(Scroller scroller) {
updateInputTextView();
}
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
- } else {
- if (mScrollState != OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
- updateInputTextView();
- }
+ } else if (mScrollState != OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
+ updateInputTextView();
}
}
@@ -1698,7 +1697,7 @@ private void onScrollStateChange(int scrollState) {
}
/**
- * Flings the selector with the given velocityY
.
+ * Flings the selector with the given velocity
.
*/
private void fling(int velocity) {
if (isHorizontalMode()) {
@@ -1919,7 +1918,9 @@ private void postSetSelectionCommand(int selectionStart, int selectionEnd) {
'\u0665', '\u0666', '\u0667', '\u0668', '\u0669',
// Extended Arabic-Indic
'\u06f0', '\u06f1', '\u06f2', '\u06f3', '\u06f4',
- '\u06f5', '\u06f6', '\u06f7', '\u06f8', '\u06f9'
+ '\u06f5', '\u06f6', '\u06f7', '\u06f8', '\u06f9',
+ // Negative
+ '-'
};
/**
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 5a21ee9..9ad3472 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -19,6 +19,7 @@
-
+
+
\ No newline at end of file