Created
October 6, 2014 16:26
-
-
Save parallelcross/0179b69cdde93c0c9bfd to your computer and use it in GitHub Desktop.
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
private ObjectAnimator animateRegularProgress(int finalProgress) { | |
ObjectAnimator animation = ObjectAnimator.ofInt(regularProgressBar, PROPERTY_NAME, 0, finalProgress); | |
animation.setDuration(ANIM_PROGRESS); | |
animation.setInterpolator(new LinearInterpolator()); | |
return animation; | |
} | |
private void animateTextProgress(float end, float total, ObjectAnimator barAnimationToCoupleTo) { | |
Func0<Observable<CharSequence[]>> f = (() -> Observable.just(getValuesToAnimateOver(end, total))); | |
Observable.defer(f) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.doOnCompleted(() -> barAnimationToCoupleTo.start()) | |
.doOnCompleted(() -> crossFadeWhatsCovered(false)) | |
.subscribe(charSequences -> setupAnimationsForCharSequence(charSequences)); | |
} | |
private void setupAnimationsForCharSequence(CharSequence [] values) { | |
ValueAnimator animation = new ValueAnimator(); | |
animation.setObjectValues(values); | |
animation.addUpdateListener(valueAnimator -> textProgressOnBar.setText((CharSequence) valueAnimator.getAnimatedValue())); | |
animation.setEvaluator((fraction, startValue, endValue) -> endValue); | |
animation.setDuration(ANIM_PROGRESS); | |
animation.setInterpolator(new LinearInterpolator()); | |
animation.start(); | |
} | |
private CharSequence[] getValuesToAnimateOver(float end, float total) { | |
CharSequence values[] = new CharSequence[(int)end]; | |
int count = 0; | |
for (int i = 0; i < (int)end; i++) { | |
values[count++] = String.format(getString(R.string.text_progress_string), moneyFormat.format(i), moneyFormat.format(total)); | |
} | |
values[(int)end - 1] = String.format(getString(R.string.text_progress_string), moneyFormat.format(end), moneyFormat.format(total)); | |
return values; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo: https://www.dropbox.com/s/ljd3w0ycb5adyyk/progress_bar_animation.mp4