Created
July 9, 2014 10:38
-
-
Save s1rius/54e36d86db7d3e4ca8a6 to your computer and use it in GitHub Desktop.
ProgressBarAnimation copyed by http://stackoverflow.com/questions/8035682/animate-progressbar-update-in-android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.animation.Animation; | |
import android.view.animation.Transformation; | |
import android.widget.ProgressBar; | |
public class ProgressBarAnimation extends Animation { | |
private ProgressBar mProgressBar; | |
private int mTo; | |
private int mFrom; | |
private long mStepDuration; | |
/** | |
* @param fullDuration - time required to fill progress from 0% to 100% | |
*/ | |
public ProgressBarAnimation(ProgressBar progressBar, long fullDuration) { | |
super(); | |
mProgressBar = progressBar; | |
mStepDuration = fullDuration / progressBar.getMax(); | |
} | |
public void setProgress(int progress) { | |
if (progress < 0) { | |
progress = 0; | |
} | |
if (progress > mProgressBar.getMax()) { | |
progress = mProgressBar.getMax(); | |
} | |
mTo = progress; | |
mFrom = mProgressBar.getProgress(); | |
setDuration(Math.abs(mTo - mFrom) * mStepDuration); | |
mProgressBar.startAnimation(this); | |
} | |
@Override | |
protected void applyTransformation(float interpolatedTime, Transformation t) { | |
float value = mFrom + (mTo - mFrom) * interpolatedTime; | |
mProgressBar.setProgress((int) value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment