Skip to content

Commit

Permalink
Disable animation when a value is set
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed Mar 6, 2016
1 parent 994edfb commit 4043751
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions FitChart/src/main/java/com/txusballesteros/widgets/FitChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ public void setValue(float value) {
chartValue.setSweepAngle(calculateSweepAngle(value));
chartValues.add(chartValue);
maxSweepAngle = chartValue.getSweepAngle();
playAnimation();
playAnimation(true);
}

public void setValue(float value, boolean withAnimation) {
chartValues.clear();
FitChartValue chartValue = new FitChartValue(value, valueStrokeColor);
chartValue.setPaint(buildPaintForValue());
chartValue.setStartAngle(START_ANGLE);
chartValue.setSweepAngle(calculateSweepAngle(value));
chartValues.add(chartValue);
maxSweepAngle = chartValue.getSweepAngle();
playAnimation(withAnimation);
}

public void setValues(Collection<FitChartValue> values) {
Expand All @@ -105,7 +116,23 @@ public void setValues(Collection<FitChartValue> values) {
offsetSweepAngle += sweepAngle;
maxSweepAngle += sweepAngle;
}
playAnimation();
playAnimation(true);
}

public void setValues(Collection<FitChartValue> values, boolean withAnimation) {
chartValues.clear();
maxSweepAngle = 0;
float offsetSweepAngle = START_ANGLE;
for (FitChartValue chartValue : values) {
float sweepAngle = calculateSweepAngle(chartValue.getValue());
chartValue.setPaint(buildPaintForValue());
chartValue.setStartAngle(offsetSweepAngle);
chartValue.setSweepAngle(sweepAngle);
chartValues.add(chartValue);
offsetSweepAngle += sweepAngle;
maxSweepAngle += sweepAngle;
}
playAnimation(withAnimation);
}

public void setAnimationMode(AnimationMode mode) {
Expand Down Expand Up @@ -283,10 +310,12 @@ private float calculateSweepAngle(float value) {
return (value * chartValuesScale);
}

private void playAnimation() {
private void playAnimation(boolean withAnimation) {
int duration = withAnimation ? ANIMATION_DURATION : 0;

ObjectAnimator animator = ObjectAnimator.ofFloat(this, "animationSeek", 0.0f, 1.0f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(ANIMATION_DURATION);
animatorSet.setDuration(duration);
animatorSet.setInterpolator(new DecelerateInterpolator());
animatorSet.setTarget(this);
animatorSet.play(animator);
Expand Down

0 comments on commit 4043751

Please sign in to comment.