feat(Poll): scale animation based on votes
Updates the animation timing, to be based on the amount of votes a option received relative to the other options. This means a option with more votes will run longer than one with less votes. Overall this makes the animation appear more dynamic and smoother.
This commit is contained in:
@@ -150,10 +150,11 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
|||||||
item.showResults = shown;
|
item.showResults = shown;
|
||||||
item.calculateResults();
|
item.calculateResults();
|
||||||
Drawable bg=progressBg;
|
Drawable bg=progressBg;
|
||||||
|
long animationDuration = (long) (ANIMATION_DURATION*item.votesFraction);
|
||||||
int startLevel=shown ? 0 : progressBg.getLevel();
|
int startLevel=shown ? 0 : progressBg.getLevel();
|
||||||
int targetLevel=shown ? Math.round(10000f*item.votesFraction) : 0;
|
int targetLevel=shown ? Math.round(10000f*item.votesFraction) : 0;
|
||||||
ObjectAnimator animator=ObjectAnimator.ofInt(bg, "level", startLevel, targetLevel);
|
ObjectAnimator animator=ObjectAnimator.ofInt(bg, "level", startLevel, targetLevel);
|
||||||
animator.setDuration(ANIMATION_DURATION);
|
animator.setDuration(animationDuration);
|
||||||
animator.setInterpolator(new DecelerateInterpolator());
|
animator.setInterpolator(new DecelerateInterpolator());
|
||||||
button.setBackground(bg);
|
button.setBackground(bg);
|
||||||
if(shown){
|
if(shown){
|
||||||
@@ -161,7 +162,7 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
|||||||
// animate percent
|
// animate percent
|
||||||
percent.setVisibility(View.VISIBLE);
|
percent.setVisibility(View.VISIBLE);
|
||||||
ValueAnimator percentAnimation=ValueAnimator.ofInt(0, Math.round(100f*item.votesFraction));
|
ValueAnimator percentAnimation=ValueAnimator.ofInt(0, Math.round(100f*item.votesFraction));
|
||||||
percentAnimation.setDuration(ANIMATION_DURATION);
|
percentAnimation.setDuration(animationDuration);
|
||||||
percentAnimation.setInterpolator(new DecelerateInterpolator());
|
percentAnimation.setInterpolator(new DecelerateInterpolator());
|
||||||
percentAnimation.addUpdateListener(animation -> percent.setText(String.format(Locale.getDefault(), "%d%%", (int) animation.getAnimatedValue())));
|
percentAnimation.addUpdateListener(animation -> percent.setText(String.format(Locale.getDefault(), "%d%%", (int) animation.getAnimatedValue())));
|
||||||
percentAnimation.start();
|
percentAnimation.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user