Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal and vertical tolerance added for touch and drag gap #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class IndicatorSeekBar extends View {
private Rect mRect;
private float mCustomDrawableMaxHeight;//the max height for custom drawable
private float lastProgress;
private float mFaultTolerance = -1;//the tolerance for user seek bar touching
private float mFaultToleranceHorizontal = -1;//the tolerance for user seek bar touching horizontally
private float mFaultToleranceVertical = -1;//the tolerance for user seek bar touching vertically
private float mScreenWidth = -1;
private boolean mClearPadding;
private SeekParams mSeekParams;//save the params when seeking change.
Expand Down Expand Up @@ -193,6 +194,8 @@ private void initAttrs(Context context, AttributeSet attrs) {
mOnlyThumbDraggable = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_only_thumb_draggable, builder.onlyThumbDraggable);
mSeekSmoothly = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_seek_smoothly, builder.seekSmoothly);
mR2L = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_r2l, builder.r2l);
mFaultToleranceHorizontal = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_horizontal_touch_gap, SizeUtils.dp2px(context, 5));
mFaultToleranceVertical = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_vertical_touch_gap, SizeUtils.dp2px(context, 5));
//track
mBackgroundTrackSize = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_track_background_size, builder.trackBackgroundSize);
mProgressTrackSize = ta.getDimensionPixelSize(R.styleable.IndicatorSeekBar_isb_track_progress_size, builder.trackProgressSize);
Expand Down Expand Up @@ -1278,11 +1281,14 @@ private float calculateTouchX(float touchX) {
}

private boolean isTouchSeekBar(float mX, float mY) {
if (mFaultTolerance == -1) {
mFaultTolerance = SizeUtils.dp2px(mContext, 5);
if (mFaultToleranceVertical == -1) {
mFaultToleranceVertical = SizeUtils.dp2px(mContext, 5);
}
boolean inWidthRange = mX >= (mPaddingLeft - 2 * mFaultTolerance) && mX <= (mMeasuredWidth - mPaddingRight + 2 * mFaultTolerance);
boolean inHeightRange = mY >= mProgressTrack.top - mThumbTouchRadius - mFaultTolerance && mY <= mProgressTrack.top + mThumbTouchRadius + mFaultTolerance;
if (mFaultToleranceHorizontal == -1) {
mFaultToleranceHorizontal = SizeUtils.dp2px(mContext, 5);
}
boolean inWidthRange = mX >= (mPaddingLeft - 2 * mFaultToleranceHorizontal) && mX <= (mMeasuredWidth - mPaddingRight + 2 * mFaultToleranceHorizontal);
boolean inHeightRange = mY >= mProgressTrack.top - mThumbTouchRadius - mFaultToleranceVertical && mY <= mProgressTrack.top + mThumbTouchRadius + mFaultToleranceVertical;
return inWidthRange && inHeightRange;
}

Expand Down
2 changes: 2 additions & 0 deletions indicatorseekbar/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<attr name="isb_seek_smoothly" format="boolean" /><!--true to seek smoothly when has ticks, default false-->
<attr name="isb_r2l" format="boolean" /><!--compat app local change,like arabic local, default false-->
<attr name="isb_ticks_count" format="integer" /><!--seekBar's ticks count, default zero-->
<attr name="isb_horizontal_touch_gap" format="dimension|reference" /><!--seekBar's ticks count, default zero-->
<attr name="isb_vertical_touch_gap" format="dimension|reference" /><!--seekBar's ticks count, default zero-->
<attr name="isb_user_seekable" format="boolean" /><!--prevent user from seeking,only can be change thumb location by setProgress(), default false-->
<attr name="isb_clear_default_padding" format="boolean" /><!-- set seekBar's leftPadding&rightPadding to zero, default false, default padding is 16dp-->
<attr name="isb_only_thumb_draggable" format="boolean" /><!--user change the thumb's location by touching thumb/touching track,true for touching track to seek. false for touching thumb; default false-->
Expand Down