From 404375123110d32d91ad691b315fddfc4914e791 Mon Sep 17 00:00:00 2001 From: Javier Santos Date: Sun, 6 Mar 2016 19:41:13 +0100 Subject: [PATCH] Disable animation when a value is set --- .../com/txusballesteros/widgets/FitChart.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/FitChart/src/main/java/com/txusballesteros/widgets/FitChart.java b/FitChart/src/main/java/com/txusballesteros/widgets/FitChart.java index c35ad87..16b9879 100644 --- a/FitChart/src/main/java/com/txusballesteros/widgets/FitChart.java +++ b/FitChart/src/main/java/com/txusballesteros/widgets/FitChart.java @@ -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 values) { @@ -105,7 +116,23 @@ public void setValues(Collection values) { offsetSweepAngle += sweepAngle; maxSweepAngle += sweepAngle; } - playAnimation(); + playAnimation(true); + } + + public void setValues(Collection 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) { @@ -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);