Skip to content

Commit

Permalink
Add support for disabling progress glow (#11)
Browse files Browse the repository at this point in the history
* Add support for disabling progress glow
* Add information to README
  • Loading branch information
mictab authored and tankery committed Jun 19, 2018
1 parent cd7a221 commit a26e9ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ app:cs_pointer_alpha_ontouch = "integer"
app:cs_pointer_angle = "float"
app:cs_start_angle = "float"
app:cs_end_angle = "float"
app:cs_disable_progress_glow = "boolean"
```

Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class CircularSeekBar extends View {
private static final boolean DEFAULT_LOCK_ENABLED = true;
private static final boolean DEFAULT_DISABLE_POINTER = false;
private static final boolean DEFAULT_NEGATIVE_ENABLED = false;
private static final boolean DEFAULT_DISABLE_PROGRESS_GLOW = false;

/**
* {@code Paint} instance used to draw the inactive circle.
Expand All @@ -102,6 +103,11 @@ public class CircularSeekBar extends View {
*/
private Paint mCircleProgressPaint;

/**
* If progress glow is disabled, there is no glow from the progress bar when filled
*/
private boolean mDisableProgressGlow;

/**
* {@code Paint} instance used to draw the glow from the active circle.
*/
Expand Down Expand Up @@ -435,6 +441,7 @@ private void initAttributes(TypedArray attrArray) {
mDisablePointer = attrArray.getBoolean(R.styleable.cs_CircularSeekBar_cs_disable_pointer, DEFAULT_DISABLE_POINTER);
negativeEnabled = attrArray.getBoolean(R.styleable.cs_CircularSeekBar_cs_negative_enabled, DEFAULT_NEGATIVE_ENABLED);
isInNegativeHalf = false;
mDisableProgressGlow = attrArray.getBoolean(R.styleable.cs_CircularSeekBar_cs_disable_progress_glow, DEFAULT_DISABLE_PROGRESS_GLOW);

// Modulo 360 right now to avoid constant conversion
mStartAngle = ((360f + (attrArray.getFloat((R.styleable.cs_CircularSeekBar_cs_start_angle), DEFAULT_START_ANGLE) % 360f)) % 360f);
Expand Down Expand Up @@ -492,9 +499,11 @@ private void initPaints() {
mCircleProgressPaint.setStrokeJoin(Paint.Join.ROUND);
mCircleProgressPaint.setStrokeCap(mCircleStyle);

mCircleProgressGlowPaint = new Paint();
mCircleProgressGlowPaint.set(mCircleProgressPaint);
mCircleProgressGlowPaint.setMaskFilter(new BlurMaskFilter((5f * DPTOPX_SCALE), BlurMaskFilter.Blur.NORMAL));
if (!mDisableProgressGlow) {
mCircleProgressGlowPaint = new Paint();
mCircleProgressGlowPaint.set(mCircleProgressPaint);
mCircleProgressGlowPaint.setMaskFilter(new BlurMaskFilter((5f * DPTOPX_SCALE), BlurMaskFilter.Blur.NORMAL));
}

mPointerPaint = new Paint();
mPointerPaint.setAntiAlias(true);
Expand Down Expand Up @@ -620,7 +629,11 @@ protected void onDraw(Canvas canvas) {
canvas.translate(this.getWidth() / 2, this.getHeight() / 2);

canvas.drawPath(mCirclePath, mCirclePaint);
canvas.drawPath(mCircleProgressPath, mCircleProgressGlowPaint);

if (!mDisableProgressGlow) {
canvas.drawPath(mCircleProgressPath, mCircleProgressGlowPaint);
}

canvas.drawPath(mCircleProgressPath, mCircleProgressPaint);

canvas.drawPath(mCirclePath, mCircleFillPaint);
Expand Down
3 changes: 2 additions & 1 deletion circularSeekBar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<attr name="cs_pointer_angle" format="float"/>
<attr name="cs_start_angle" format="float"/>
<attr name="cs_end_angle" format="float"/>
<attr name="cs_disable_progress_glow" format="boolean"/>
</declare-styleable>

</resources>
</resources>

0 comments on commit a26e9ff

Please sign in to comment.