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

Modifying sensitivity of seekbar, specially useful when the seekbar is inside a RecyclerView #106

Open
wants to merge 1 commit 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
17 changes: 17 additions & 0 deletions app/src/main/res/layout/discrete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@
app:isb_tick_texts_array="@array/last_next_length_6"
app:isb_ticks_count="6" />

<TextView
style="@style/subtitle_text_style"
android:text="12. Modifying sensitivity of seekbar, specially useful when the seekbar is inside a RecyclerView (longClick, longClickTime (in ms))" />

<com.warkiz.widget.IndicatorSeekBar
android:id="@+id/long_click_drawable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="18dp"
app:isb_progress="40"
app:isb_show_tick_marks_type="oval"
app:isb_show_tick_texts="true"
app:isb_tick_texts_array="@array/last_next_length_6"
app:isb_ticks_count="6"
app:isb_longclick="true"
app:isb_longclick_time="500"/>

<include layout="@layout/source_code_link" />
</LinearLayout>

Expand Down
24 changes: 24 additions & 0 deletions indicatorseekbar/src/main/java/com/warkiz/widget/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Builder {
boolean userSeekable = true;
boolean onlyThumbDraggable = false;
boolean clearPadding = false;
boolean longClick = false;
int longClickTime = 0;
//indicator
int showIndicatorType = IndicatorType.ROUNDED_RECTANGLE;
int indicatorColor = Color.parseColor("#FF4081");
Expand Down Expand Up @@ -163,6 +165,28 @@ public Builder clearPadding(boolean clearPadding) {
return this;
}

/**
* seek bar will respond only on longClick
*
* @param longClick true to set longClick behaviour
* @return Builder
*/
public Builder longClick(boolean longClick){
this.longClick = longClick;
return this;
}

/**
* seek bar will respond on longClick after a time expressed in ms
*
* @param longClickTime time (in ms) before to respond
* @return Builder
*/
public Builder longClickTime(int longClickTime){
this.longClickTime = longClickTime;
return this;
}

/**
* prevent user from touching to seek or not
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Date;

/**
* created by zhuangguangquan on 2017/9/1
Expand Down Expand Up @@ -74,6 +75,10 @@ public class IndicatorSeekBar extends View {
private boolean mSeekSmoothly;//seek continuously
private float[] mProgressArr;//save the progress which at tickMark position.
private boolean mR2L;//right to left,compat local problem.
private boolean mLongClick;//true if seekbar responds on longClick
private int mLongClickTime;//time (in ms) passed before responds onlongClick
private long startTime;
private long endTime;
//tick texts
private boolean mShowTickText;//the palace where the tick text show .
private boolean mShowBothTickTextsOnly;//show the tick texts on the both ends of seek bar before.
Expand Down Expand Up @@ -187,6 +192,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);
mLongClick = ta.getBoolean(R.styleable.IndicatorSeekBar_isb_longclick, builder.longClick);
mLongClickTime = ta.getInteger(R.styleable.IndicatorSeekBar_isb_longclick_time, builder.longClickTime);
//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 @@ -1205,18 +1212,43 @@ public boolean onTouchEvent(MotionEvent event) {
if (mSeekChangeListener != null) {
mSeekChangeListener.onStartTrackingTouch(this);
}
refreshSeekBar(event);
if(!mLongClick) {
refreshSeekBar(event);
}
else{
startTime = event.getEventTime();
}
return true;
}
break;
case MotionEvent.ACTION_MOVE:
refreshSeekBar(event);
if(mLongClick) {
endTime = event.getEventTime();
if (endTime - startTime > mLongClickTime) {
refreshSeekBar(event);
}
}
else{
refreshSeekBar(event);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mIsTouching = false;
if (mSeekChangeListener != null) {
mSeekChangeListener.onStopTrackingTouch(this);

if(mLongClick) {
endTime = event.getEventTime();
if (endTime - startTime > mLongClickTime) {
refreshSeekBar(event);
if (mSeekChangeListener != null) {
mSeekChangeListener.onStopTrackingTouch(this);
}
}
}
else{
if (mSeekChangeListener != null) {
mSeekChangeListener.onStopTrackingTouch(this);
}
}
if (!autoAdjustThumb()) {
invalidate();
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 @@ -12,6 +12,8 @@
<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-->
<attr name="isb_longclick" format="boolean" />
<attr name="isb_longclick_time" format="integer" />
//indicator
<attr name="isb_show_indicator"><!-- the type of indicator, default rectangle_rounded_corner/0.-->
<enum name="none" value="0" />
Expand Down