diff --git a/README.md b/README.md
index 7c537e4..cb29b8e 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,15 @@ numberPicker.setMaxValue(data.length);
numberPicker.setDisplayedValues(data);
numberPicker.setValue(7);
+// Set fading edge enabled
+numberPicker.setFadingEdgeEnabled(true);
+
+// Set scroller enabled
+numberPicker.setScrollerEnabled(true);
+
+// Set wrap selector wheel
+numberPicker.setWrapSelectorWheel(true);
+
// OnClickListener
numberPicker.setOnClickListener(new View.OnClickListener() {
@Override
@@ -116,11 +125,13 @@ add `xmlns:app="http://schemas.android.com/apk/res-auto"`
|np_dividerColor|The color of the selection divider.|
|np_dividerDistance|The distance between the two selection dividers.|
|np_dividerThickness|The thickness of the selection divider.|
+|np_fadingEdgeEnabled|Flag whether the fading edge should enabled.|
|np_formatter|The formatter of the numbers.|
|np_max|The max value of this widget.|
|np_min|The min value of this widget.|
|np_order|The order of this widget. Default is ascending.|
|np_orientation|The orientation of this widget. Default is vertical.|
+|np_scrollerEnabled|Flag whether the scroller should enabled.|
|np_selectedTextColor|The text color of the selected number.|
|np_selectedTextSize|The text size of the selected number.|
|np_textColor|The text color of the numbers.|
diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
index bc8649f..8d28f26 100644
--- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
+++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
@@ -481,6 +481,16 @@ public static final Formatter getTwoDigitFormatter() {
*/
private int mOrder;
+ /**
+ * Flag whether the fading edge should enabled.
+ */
+ private boolean mFadingEdgeEnabled = true;
+
+ /**
+ * Flag whether the scroller should enabled.
+ */
+ private boolean mScrollerEnabled = true;
+
/**
* The context of this widget.
*/
@@ -615,6 +625,8 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
mTextSize = attributesArray.getDimension(R.styleable.NumberPicker_np_textSize, spToPx(mTextSize));
mTypeface = Typeface.create(attributesArray.getString(R.styleable.NumberPicker_np_typeface), Typeface.NORMAL);
mFormatter = stringToFormatter(attributesArray.getString(R.styleable.NumberPicker_np_formatter));
+ mFadingEdgeEnabled = attributesArray.getBoolean(R.styleable.NumberPicker_np_fadingEdgeEnabled, mFadingEdgeEnabled);
+ mScrollerEnabled = attributesArray.getBoolean(R.styleable.NumberPicker_np_scrollerEnabled, mScrollerEnabled);
mWheelItemCount = attributesArray.getInt(R.styleable.NumberPicker_np_wheelItemCount, mWheelItemCount);
// By default Linearlayout that we extend is not drawn. This is
@@ -842,6 +854,9 @@ public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
+ if (!isScrollerEnabled()) {
+ return false;
+ }
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
@@ -997,6 +1012,10 @@ public boolean dispatchTrackballEvent(MotionEvent event) {
@Override
public void computeScroll() {
+ if (!isScrollerEnabled()) {
+ return;
+ }
+
Scroller scroller = mFlingScroller;
if (scroller.isFinished()) {
scroller = mAdjustScroller;
@@ -1035,6 +1054,9 @@ public void setEnabled(boolean enabled) {
@Override
public void scrollBy(int x, int y) {
+ if (!isScrollerEnabled()) {
+ return;
+ }
int[] selectorIndices = getSelectorIndices();
int gap;
if (isHorizontalMode()) {
@@ -1409,22 +1431,22 @@ public void setDisplayedValues(String[] displayedValues) {
@Override
protected float getTopFadingEdgeStrength() {
- return isHorizontalMode() ? 0: FADING_EDGE_STRENGTH;
+ return !isHorizontalMode() && mFadingEdgeEnabled ? FADING_EDGE_STRENGTH : 0;
}
@Override
protected float getBottomFadingEdgeStrength() {
- return isHorizontalMode() ? 0: FADING_EDGE_STRENGTH;
+ return !isHorizontalMode() && mFadingEdgeEnabled ? FADING_EDGE_STRENGTH : 0;
}
@Override
protected float getLeftFadingEdgeStrength() {
- return isHorizontalMode() ? FADING_EDGE_STRENGTH : 0;
+ return isHorizontalMode() && mFadingEdgeEnabled ? FADING_EDGE_STRENGTH : 0;
}
@Override
protected float getRightFadingEdgeStrength() {
- return isHorizontalMode() ? FADING_EDGE_STRENGTH : 0;
+ return isHorizontalMode() && mFadingEdgeEnabled ? FADING_EDGE_STRENGTH : 0;
}
@Override
@@ -1507,7 +1529,7 @@ protected void onDraw(Canvas canvas) {
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(NumberPicker.class.getName());
- event.setScrollable(true);
+ event.setScrollable(isScrollerEnabled());
final int scroll = (mMinValue + mValue) * mSelectorElementSize;
final int maxScroll = (mMaxValue - mMinValue) * mSelectorElementSize;
if (isHorizontalMode()) {
@@ -2150,6 +2172,14 @@ public void setFormatter(@StringRes int stringId) {
setFormatter(getResources().getString(stringId));
}
+ public void setFadingEdgeEnabled(boolean fadingEdgeEnabled) {
+ mFadingEdgeEnabled = fadingEdgeEnabled;
+ }
+
+ public void setScrollerEnabled(boolean scrollerEnabled) {
+ mScrollerEnabled = scrollerEnabled;
+ }
+
public void setSelectedTextColor(@ColorInt int color) {
mSelectedTextColor = color;
mSelectedText.setTextColor(mSelectedTextColor);
@@ -2281,6 +2311,14 @@ public Formatter getFormatter() {
return mFormatter;
}
+ public boolean isFadingEdgeEnabled() {
+ return mFadingEdgeEnabled;
+ }
+
+ public boolean isScrollerEnabled() {
+ return mScrollerEnabled;
+ }
+
public int getSelectedTextColor() {
return mSelectedTextColor;
}
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 235d1ce..e3e60a4 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -10,6 +10,7 @@
+
@@ -20,6 +21,7 @@
+
diff --git a/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java b/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java
index 6b6cc4b..1261836 100644
--- a/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java
+++ b/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java
@@ -61,6 +61,15 @@ protected void onCreate(Bundle savedInstanceState) {
numberPicker.setMinValue(0);
numberPicker.setValue(3);
+ // Set fading edge enabled
+ numberPicker.setFadingEdgeEnabled(true);
+
+ // Set scroller enabled
+ numberPicker.setScrollerEnabled(true);
+
+ // Set wrap selector wheel
+ numberPicker.setWrapSelectorWheel(true);
+
// OnClickListener
numberPicker.setOnClickListener(new View.OnClickListener() {
@Override
diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml
index 9870ae9..dde3eaf 100644
--- a/sample/src/main/res/layout/content_main.xml
+++ b/sample/src/main/res/layout/content_main.xml
@@ -34,10 +34,11 @@
app:np_order="descending"
app:np_orientation="horizontal"
app:np_selectedTextColor="@color/colorAccent"
+ app:np_selectedTextSize="@dimen/selected_text_size"
app:np_textColor="@color/colorAccent"
app:np_textSize="@dimen/text_size"
- app:np_selectedTextSize="@dimen/selected_text_size"
app:np_typeface="@string/roboto_light"
+ app:np_fadingEdgeEnabled="false"
app:np_wrapSelectorWheel="true" />