Skip to content

Commit

Permalink
Reformatted code according to my code style
Browse files Browse the repository at this point in the history
  • Loading branch information
lecho committed Mar 7, 2015
1 parent aed475f commit fb81ccd
Show file tree
Hide file tree
Showing 91 changed files with 7,597 additions and 7,646 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
/**
* Listener used to listen for chart animation start and stop events. Implementations of this interface can be used for
* all types of chart animations(data, viewport, PieChart rotation).
*
*/
public interface ChartAnimationListener {

public void onAnimationStarted();
public void onAnimationStarted();

public void onAnimationFinished();
public void onAnimationFinished();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

public interface ChartDataAnimator {

public static final long DEFAULT_ANIMATION_DURATION = 500;
public static final long DEFAULT_ANIMATION_DURATION = 500;

public void startAnimation(long duration);
public void startAnimation(long duration);

public void cancelAnimation();
public void cancelAnimation();

public boolean isAnimationStarted();
public boolean isAnimationStarted();

public void setChartAnimationListener(ChartAnimationListener animationListener);
public void setChartAnimationListener(ChartAnimationListener animationListener);

}
Original file line number Diff line number Diff line change
@@ -1,76 +1,77 @@
package lecho.lib.hellocharts.animation;

import lecho.lib.hellocharts.view.Chart;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;

import lecho.lib.hellocharts.view.Chart;

@SuppressLint("NewApi")
public class ChartDataAnimatorV14 implements ChartDataAnimator, AnimatorListener, AnimatorUpdateListener {
private ValueAnimator animator;
private final Chart chart;
private ChartAnimationListener animationListener = new DummyChartAnimationListener();
private ValueAnimator animator;
private final Chart chart;
private ChartAnimationListener animationListener = new DummyChartAnimationListener();

public ChartDataAnimatorV14(Chart chart) {
this.chart = chart;
animator = ValueAnimator.ofFloat(0.0f, 1.0f);
animator.addListener(this);
animator.addUpdateListener(this);
}
public ChartDataAnimatorV14(Chart chart) {
this.chart = chart;
animator = ValueAnimator.ofFloat(0.0f, 1.0f);
animator.addListener(this);
animator.addUpdateListener(this);
}

@Override
public void startAnimation(long duration) {
if (duration >= 0) {
animator.setDuration(duration);
} else {
animator.setDuration(DEFAULT_ANIMATION_DURATION);
}
animator.start();
}
@Override
public void startAnimation(long duration) {
if (duration >= 0) {
animator.setDuration(duration);
} else {
animator.setDuration(DEFAULT_ANIMATION_DURATION);
}
animator.start();
}

@Override
public void cancelAnimation() {
animator.cancel();
}
@Override
public void cancelAnimation() {
animator.cancel();
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
chart.animationDataUpdate(animation.getAnimatedFraction());
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
chart.animationDataUpdate(animation.getAnimatedFraction());
}

@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}

@Override
public void onAnimationEnd(Animator animation) {
chart.animationDataFinished();
animationListener.onAnimationFinished();
}
@Override
public void onAnimationEnd(Animator animation) {
chart.animationDataFinished();
animationListener.onAnimationFinished();
}

@Override
public void onAnimationRepeat(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}

@Override
public void onAnimationStart(Animator animation) {
animationListener.onAnimationStarted();
}
@Override
public void onAnimationStart(Animator animation) {
animationListener.onAnimationStarted();
}

@Override
public boolean isAnimationStarted() {
return animator.isStarted();
}
@Override
public boolean isAnimationStarted() {
return animator.isStarted();
}

@Override
public void setChartAnimationListener(ChartAnimationListener animationListener) {
if (null == animationListener) {
this.animationListener = new DummyChartAnimationListener();
} else {
this.animationListener = animationListener;
}
}
@Override
public void setChartAnimationListener(ChartAnimationListener animationListener) {
if (null == animationListener) {
this.animationListener = new DummyChartAnimationListener();
} else {
this.animationListener = animationListener;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,76 +1,77 @@
package lecho.lib.hellocharts.animation;

import lecho.lib.hellocharts.view.Chart;
import android.os.Handler;
import android.os.SystemClock;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;

import lecho.lib.hellocharts.view.Chart;

public class ChartDataAnimatorV8 implements ChartDataAnimator {

long start;
boolean isAnimationStarted = false;
long duration;
final Chart chart;
final Handler handler;
final Interpolator interpolator = new AccelerateDecelerateInterpolator();
private ChartAnimationListener animationListener = new DummyChartAnimationListener();
private final Runnable runnable = new Runnable() {
long start;
boolean isAnimationStarted = false;
long duration;
final Chart chart;
final Handler handler;
final Interpolator interpolator = new AccelerateDecelerateInterpolator();
private ChartAnimationListener animationListener = new DummyChartAnimationListener();
private final Runnable runnable = new Runnable() {

@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
if (elapsed > duration) {
isAnimationStarted = false;
handler.removeCallbacks(runnable);
chart.animationDataFinished();
return;
}
float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
chart.animationDataUpdate(scale);
handler.postDelayed(this, 16);
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
if (elapsed > duration) {
isAnimationStarted = false;
handler.removeCallbacks(runnable);
chart.animationDataFinished();
return;
}
float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
chart.animationDataUpdate(scale);
handler.postDelayed(this, 16);

}
};
}
};

public ChartDataAnimatorV8(Chart chart) {
this.chart = chart;
this.handler = new Handler();
}
public ChartDataAnimatorV8(Chart chart) {
this.chart = chart;
this.handler = new Handler();
}

@Override
public void startAnimation(long duration) {
if (duration >= 0) {
this.duration = duration;
} else {
this.duration = DEFAULT_ANIMATION_DURATION;
}
@Override
public void startAnimation(long duration) {
if (duration >= 0) {
this.duration = duration;
} else {
this.duration = DEFAULT_ANIMATION_DURATION;
}

isAnimationStarted = true;
animationListener.onAnimationStarted();
start = SystemClock.uptimeMillis();
handler.post(runnable);
}
isAnimationStarted = true;
animationListener.onAnimationStarted();
start = SystemClock.uptimeMillis();
handler.post(runnable);
}

@Override
public void cancelAnimation() {
isAnimationStarted = false;
handler.removeCallbacks(runnable);
chart.animationDataFinished();
animationListener.onAnimationFinished();
}
@Override
public void cancelAnimation() {
isAnimationStarted = false;
handler.removeCallbacks(runnable);
chart.animationDataFinished();
animationListener.onAnimationFinished();
}

@Override
public boolean isAnimationStarted() {
return isAnimationStarted;
}
@Override
public boolean isAnimationStarted() {
return isAnimationStarted;
}

@Override
public void setChartAnimationListener(ChartAnimationListener animationListener) {
if (null == animationListener) {
this.animationListener = new DummyChartAnimationListener();
} else {
this.animationListener = animationListener;
}
}
@Override
public void setChartAnimationListener(ChartAnimationListener animationListener) {
if (null == animationListener) {
this.animationListener = new DummyChartAnimationListener();
} else {
this.animationListener = animationListener;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

public interface ChartViewportAnimator {

public static final int FAST_ANIMATION_DURATION = 300;
public static final int FAST_ANIMATION_DURATION = 300;

public void startAnimation(Viewport startViewport, Viewport targetViewport);
public void startAnimation(Viewport startViewport, Viewport targetViewport);

public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration);
public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration);

public void cancelAnimation();
public void cancelAnimation();

public boolean isAnimationStarted();
public boolean isAnimationStarted();

public void setChartAnimationListener(ChartAnimationListener animationListener);
public void setChartAnimationListener(ChartAnimationListener animationListener);

}
Loading

0 comments on commit fb81ccd

Please sign in to comment.