From 0cb7e7086176720d10b2ef4714a5bccc4d2f9a93 Mon Sep 17 00:00:00 2001 From: ShawnLin013 Date: Fri, 9 Dec 2016 20:27:46 +0800 Subject: [PATCH 1/5] Rename np_wheel_item_count to np_wheelItemCount --- .../src/main/java/com/shawnlin/numberpicker/NumberPicker.java | 2 +- library/src/main/res/values/attrs.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java index 729dd8f..c5eb247 100644 --- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java +++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java @@ -584,7 +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); + mWheelItemCount = attributesArray.getInt(R.styleable.NumberPicker_np_wheelItemCount, mWheelItemCount); attributesArray.recycle(); // By default Linearlayout that we extend is not drawn. This is diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 5a21ee9..f267e7e 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -19,6 +19,6 @@ - + \ No newline at end of file From 2572cfeaa7cdd0fc6b26ed8e8c19549cdb8dc7e3 Mon Sep 17 00:00:00 2001 From: ShawnLin013 Date: Sat, 10 Dec 2016 00:27:17 +0800 Subject: [PATCH 2/5] Add setWrapSelectorWheel in xml --- .../shawnlin/numberpicker/NumberPicker.java | 99 +++++++++---------- library/src/main/res/values/attrs.xml | 1 + 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java index c5eb247..9a9f1ed 100644 --- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java +++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java @@ -585,7 +585,6 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) { 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_wheelItemCount, mWheelItemCount); - attributesArray.recycle(); // 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()) { diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index f267e7e..9ad3472 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -20,5 +20,6 @@ + \ No newline at end of file From 980f2d0cb174c6bedaabf2feadfae7df3f8af756 Mon Sep 17 00:00:00 2001 From: ShawnLin013 Date: Sat, 10 Dec 2016 00:35:08 +0800 Subject: [PATCH 3/5] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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' } ``` From e90bd058f948a7aca95970bbcca895d992ab91c5 Mon Sep 17 00:00:00 2001 From: ShawnLin013 Date: Sat, 10 Dec 2016 01:53:24 +0800 Subject: [PATCH 4/5] Fix issue #23 : Show negative number --- .../src/main/java/com/shawnlin/numberpicker/NumberPicker.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java index 9a9f1ed..528ba1d 100644 --- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java +++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java @@ -1918,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 + '-' }; /** From a0b021e9b5aab3dc0a2d906a9d416f62b73de606 Mon Sep 17 00:00:00 2001 From: ShawnLin013 Date: Sat, 10 Dec 2016 01:53:51 +0800 Subject: [PATCH 5/5] Update version --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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