Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Jan 11, 2018
1 parent 83fa818 commit 6d568d4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class CircularProgressBar extends View {
private static final float DEFAULT_BACKGROUND_STROKE_WIDTH_DP = 1f;
private static final float DEFAULT_START_ANGLE = 270f;
private static final float DEFAULT_INDETERMINATE_MINIMUM_ANGLE = 60f;
private static final int DEFAULT_FOREGROUND_STROKE_CAP = 0;
private static final int DEFAULT_FOREGROUND_STROKE_COLOR = Color.BLUE;
private static final int DEFAULT_BACKGROUND_STROKE_COLOR = Color.BLACK;
private static final int DEFAULT_PROGRESS_ANIMATION_DURATION = 100;
Expand Down Expand Up @@ -252,6 +253,14 @@ public void setForegroundStrokeWidth(@FloatRange(from = 0f, to = Float.MAX_VALUE
invalidate();
}

/**
* Foreground stroke cap
*/
public void setForegroundStrokeCap(@NonNull Paint.Cap cap) {
mForegroundStrokePaint.setStrokeCap(cap);
invalidate();
}

/**
* Background stroke color
*/
Expand Down Expand Up @@ -409,6 +418,7 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
mForegroundStrokePaint.setColor(DEFAULT_FOREGROUND_STROKE_COLOR);
mForegroundStrokePaint
.setStrokeWidth(Math.round(DEFAULT_FOREGROUND_STROKE_WIDTH_DP * displayMetrics.density));
mForegroundStrokePaint.setStrokeCap(getStrokeCap(DEFAULT_FOREGROUND_STROKE_CAP));
mBackgroundStrokePaint.setColor(DEFAULT_BACKGROUND_STROKE_COLOR);
mBackgroundStrokePaint
.setStrokeWidth(Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * displayMetrics.density));
Expand Down Expand Up @@ -453,6 +463,8 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
Math.round(DEFAULT_FOREGROUND_STROKE_WIDTH_DP * displayMetrics.density));
checkWidth(foregroundWidth);
mForegroundStrokePaint.setStrokeWidth(foregroundWidth);
mForegroundStrokePaint.setStrokeCap(getStrokeCap(attributes
.getInt(R.styleable.CircularProgressBar_foregroundStrokeCap, DEFAULT_FOREGROUND_STROKE_CAP)));
float backgroundWidth = attributes.getDimension(R.styleable.CircularProgressBar_backgroundStrokeWidth,
Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * displayMetrics.density));
checkWidth(backgroundWidth);
Expand Down Expand Up @@ -570,6 +582,22 @@ private static void checkWidth(float width) {
}
}

@NonNull
private static Paint.Cap getStrokeCap(int value) {
switch (value) {
case 2: {
return Paint.Cap.SQUARE;
}
case 1: {
return Paint.Cap.ROUND;
}
case 0:
default: {
return Paint.Cap.BUTT;
}
}
}

private final class ProgressUpdateListener implements ValueAnimator.AnimatorUpdateListener {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
<attr format="float" name="indeterminateMinimumAngle"/>
<attr format="integer" name="indeterminateSweepAnimationDuration"/>
<attr format="integer" name="indeterminateRotationAnimationDuration"/>
<attr format="enum" name="foregroundStrokeCap">
<enum name="butt" value="0"/>
<enum name="round" value="1"/>
<enum name="square" value="2"/>
</attr>
</declare-styleable>
</resources>

0 comments on commit 6d568d4

Please sign in to comment.