Skip to content

Commit

Permalink
Added cpv_roundToBlock attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
SG57 committed Aug 28, 2016
1 parent bc2522f commit 9289105
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public class CircleProgressView extends View {
private float mBlockScale = 0.9f;
private float mBlockDegree = 360 / mBlockCount;
private float mBlockScaleDegree = mBlockDegree * mBlockScale;
private boolean mRoundToBlock = false;


private int mTouchEventCount;
Expand Down Expand Up @@ -225,6 +226,10 @@ public void setBlockCount(int blockCount) {
}
}

public void setRoundToBlock(boolean _roundToBlock ) { mRoundToBlock = _roundToBlock; }

public boolean getRoundToBlock() { return mRoundToBlock; }

public float getBlockScale() {
return mBlockScale;
}
Expand Down Expand Up @@ -671,6 +676,13 @@ public void setDirection(Direction direction) {
* @param _value The value.
*/
public void setValue(float _value) {
// round to block
if (mShowBlock)
if (mRoundToBlock) {
float value_per_block = mMaxValue / (float) mBlockCount;
_value = Math.round(_value / value_per_block) * value_per_block;
}

Message msg = new Message();
msg.what = AnimationMsg.SET_VALUE.ordinal();
msg.obj = new float[]{_value, _value};
Expand Down Expand Up @@ -707,6 +719,13 @@ public void setValueAnimated(float _valueTo, long _animationDuration) {
* @param _animationDuration the duration of the animation in milliseconds
*/
public void setValueAnimated(float _valueFrom, float _valueTo, long _animationDuration) {
// round to block
if (mShowBlock)
if (mRoundToBlock) {
float value_per_block = mMaxValue / (float) mBlockCount;
_valueTo = Math.round(_valueTo / value_per_block) * value_per_block;
}

mAnimationDuration = _animationDuration;
Message msg = new Message();
msg.what = AnimationMsg.SET_VALUE_ANIMATED.ordinal();
Expand Down Expand Up @@ -858,6 +877,8 @@ private void parseAttributes(TypedArray a) {

setMaxValue(a.getFloat(R.styleable.CircleProgressView_cpv_maxValue, mMaxValue));

setRoundToBlock(a.getBoolean(R.styleable.CircleProgressView_cpv_roundToBlock, mRoundToBlock));

setUnit(a.getString(R.styleable.CircleProgressView_cpv_unit));
setUnitVisible(a.getBoolean(R.styleable.CircleProgressView_cpv_showUnit, mShowUnit));

Expand Down
1 change: 1 addition & 0 deletions CircleProgressView/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<!-- Block -->
<attr name="cpv_blockCount" format="integer"/>
<attr name="cpv_blockScale" format="float"/>
<attr format="boolean" name="cpv_roundToBlock"/>

<attr name="cpv_textMode" format="enum">
<enum name="Text" value="0"/>
Expand Down

0 comments on commit 9289105

Please sign in to comment.