Skip to content

Commit

Permalink
Added some attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
waynell committed Nov 8, 2016
1 parent e2f6a7f commit 1bb21a9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ repositories {
}
dependencies {
compile 'com.github.waynell:VideoRangeSlider:1.0'
compile 'com.github.waynell:VideoRangeSlider:1.0.1'
}
```

## Usage
1. Add VideoRangeSlider into your layout
1. Add VideoRangeSlider into your layout, like the following
```xml
<com.waynell.videorangeslider.RangeSlider
app:lineSize="3dp"
app:lineHeight="3dp"
app:lineColor="@color/colorAccent"
app:thumbWidth="@dimen/range_thumb_width"
app:tickCount="100"
app:leftThumbIndex="10"
app:leftThumbDrawable="@drawable/thumb_drawable"
app:rightThumbDrawable="@drawable/thumb_drawable"
android:id="@+id/range_slider"
Expand All @@ -44,11 +46,12 @@ slider.setRangeChangeListener(new RangeSlider.OnRangeChangeListener() {

Developers can customize the following attributes (both via XML and programmatically):
- line color
- line size
- thumb size
- line height
- thumb width
- left and right thumb drawable
- left and right thumb index
- mask color

- tick count

## License
MIT License
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
android:paddingRight="@dimen/range_thumb_width"/>

<com.waynell.videorangeslider.RangeSlider
app:lineSize="3dp"
app:lineHeight="3dp"
app:lineColor="@color/colorAccent"
app:thumbWidth="@dimen/range_thumb_width"
app:tickCount="100"
app:leftThumbIndex="10"
app:leftThumbDrawable="@drawable/thumb_drawable"
app:rightThumbDrawable="@drawable/thumb_drawable"
android:id="@+id/range_slider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public RangeSlider(Context context, AttributeSet attrs, int defStyleAttr) {

TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RangeSlider, 0, 0);
mThumbWidth = array.getDimensionPixelOffset(R.styleable.RangeSlider_thumbWidth, DEFAULT_THUMB_WIDTH);
mLineSize = array.getDimensionPixelOffset(R.styleable.RangeSlider_lineSize, DEFAULT_LINE_SIZE);
mLineSize = array.getDimensionPixelOffset(R.styleable.RangeSlider_lineHeight, DEFAULT_LINE_SIZE);
mBgPaint = new Paint();
mBgPaint.setColor(array.getColor(R.styleable.RangeSlider_maskColor, DEFAULT_MASK_BACKGROUND));

Expand All @@ -70,9 +70,9 @@ public RangeSlider(Context context, AttributeSet attrs, int defStyleAttr) {
Drawable rDrawable = array.getDrawable(R.styleable.RangeSlider_rightThumbDrawable);
mLeftThumb = new ThumbView(context, mThumbWidth, lDrawable == null ? new ColorDrawable(DEFAULT_LINE_COLOR) : lDrawable);
mRightThumb = new ThumbView(context, mThumbWidth, rDrawable == null ? new ColorDrawable(DEFAULT_LINE_COLOR) : rDrawable);
mLeftThumb.setTickIndex(DEFAULT_TICK_START);
mRightThumb.setTickIndex(DEFAULT_TICK_END);

setTickCount(array.getInteger(R.styleable.RangeSlider_tickCount, DEFAULT_TICK_END));
setRangeIndex(array.getInteger(R.styleable.RangeSlider_leftThumbIndex, DEFAULT_TICK_START),
array.getInteger(R.styleable.RangeSlider_rightThumbIndex, mTickCount));
array.recycle();

addView(mLeftThumb);
Expand Down Expand Up @@ -155,7 +155,7 @@ protected void onDraw(Canvas canvas) {
height, mLinePaint);

if (lThumbOffset > mThumbWidth) {
canvas.drawRect(mThumbWidth, 0, lThumbOffset, height, mBgPaint);
canvas.drawRect(mThumbWidth, 0, lThumbOffset + mThumbWidth, height, mBgPaint);
}
if (rThumbOffset < width - mThumbWidth) {
canvas.drawRect(rThumbOffset, 0, width, height, mBgPaint);
Expand Down Expand Up @@ -280,31 +280,16 @@ public void setRangeChangeListener(OnRangeChangeListener rangeChangeListener) {
}

/**
* Sets the start tick in the RangeSlider.
*
* @param tickInterval Integer specifying the number of ticks.
*/
public void setTickInterval(int tickInterval) {
int tickCount = (mTickEnd - mTickStart) / tickInterval;
if (isValidTickCount(tickCount)) {
mTickCount = tickCount;
mTickInterval = tickInterval;
} else {
throw new IllegalArgumentException("tickCount less than 2; invalid tickCount.");
}
}

/**
* Sets the end tick in the RangeSlider.
* Sets the tick count in the RangeSlider.
*
* @param tickEnd Integer specifying the number of ticks.
* @param count Integer specifying the number of ticks.
*/
public void setTickEnd(int tickEnd) {
int tickCount = (tickEnd - mTickStart) / mTickInterval;
public void setTickCount(int count) {
int tickCount = (count - mTickStart) / mTickInterval;
if (isValidTickCount(tickCount)) {
mTickEnd = tickEnd;
mTickEnd = count;
mTickCount = tickCount;
mRightThumb.setTickIndex(mTickEnd);
mRightThumb.setTickIndex(mTickCount);
} else {
throw new IllegalArgumentException("tickCount less than 2; invalid tickCount.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@SuppressLint("ViewConstructor")
class ThumbView extends View {

private static final int EXTEND_TOUCH_SLOP = 10;
private static final int EXTEND_TOUCH_SLOP = 15;

private final int mExtendTouchSlop;

Expand Down
5 changes: 4 additions & 1 deletion video-range-slider/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="RangeSlider">
<attr name="lineSize" format="dimension" />
<attr name="lineHeight" format="dimension" />
<attr name="thumbWidth" format="dimension" />
<attr name="lineColor" format="color" />
<attr name="maskColor" format="color" />
<attr name="tickCount" format="integer" />
<attr name="leftThumbIndex" format="integer" />
<attr name="rightThumbIndex" format="integer" />
<attr name="leftThumbDrawable" format="reference" />
<attr name="rightThumbDrawable" format="reference" />
</declare-styleable>
Expand Down

0 comments on commit 1bb21a9

Please sign in to comment.