Skip to content

Commit

Permalink
Added default XML spinning option
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Toledano committed Nov 10, 2016
1 parent dbed95d commit 5d5072a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class CircleProgressView extends View {
//Animation
//The amount of degree to move the bar by on each draw
float mSpinSpeed = 2.8f;
//Enable spin
boolean mSpin = false;
/**
* The animation duration in ms
*/
Expand Down Expand Up @@ -211,6 +213,10 @@ public CircleProgressView(Context context, AttributeSet attrs) {
mMaskPaint.setFilterBitmap(false);
mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
setupPaints();

if (mSpin) {
spin();
}
}

private static float calcTextSizeForRect(String _text, Paint _textPaint, RectF _rectBounds) {
Expand Down Expand Up @@ -977,6 +983,9 @@ private void parseAttributes(TypedArray a) {
setSpinSpeed((int) a.getFloat(R.styleable.CircleProgressView_cpv_spinSpeed,
mSpinSpeed));

setSpin(a.getBoolean(R.styleable.CircleProgressView_cpv_spin,
mSpin));

setDirection(Direction.values()[a.getInt(R.styleable.CircleProgressView_cpv_direction, 0)]);

float value = a.getFloat(R.styleable.CircleProgressView_cpv_value, mCurrentValue);
Expand Down Expand Up @@ -1806,16 +1815,21 @@ private void drawBar(Canvas _canvas, float _degrees) {
* Turn off spinning mode
*/
public void stopSpinning() {
setSpin(false);
mAnimationHandler.sendEmptyMessage(AnimationMsg.STOP_SPINNING.ordinal());
}

/**
* Puts the view in spin mode
*/
public void spin() {
setSpin(true);
mAnimationHandler.sendEmptyMessage(AnimationMsg.START_SPINNING.ordinal());
}

private void setSpin(boolean spin) {
mSpin = spin;
}

//----------------------------------
//region touch input
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 @@ -51,6 +51,7 @@
</attr>

<!-- Spinner-->
<attr name="cpv_spin" format="boolean" />
<attr name="cpv_spinColor" format="color" />
<attr name="cpv_spinSpeed" format="float" />
<attr name="cpv_spinBarLength" format="float" />
Expand Down

0 comments on commit 5d5072a

Please sign in to comment.