Skip to content

Instantly share code, notes, and snippets.

@parallelcross
Created October 6, 2014 16:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parallelcross/0179b69cdde93c0c9bfd to your computer and use it in GitHub Desktop.
Save parallelcross/0179b69cdde93c0c9bfd to your computer and use it in GitHub Desktop.
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;
}
@parallelcross
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment