Bug 1388490 - Cancel animation set if necessary before re-start it. r?walkingice draft
authorJing-wei Wu <topwu.tw@gmail.com>
Mon, 28 Aug 2017 15:04:39 +0800
changeset 653896 2d1a928b14098661481d473688eaea212286eb72
parent 653873 a45bafa77747fe125fd92d5e141597db5650071e
child 653973 8a0a14ab7a20eae3568975e9525aaaf7c5fe1d15
push id76451
push userbmo:topwu.tw@gmail.com
push dateMon, 28 Aug 2017 07:08:00 +0000
reviewerswalkingice
bugs1388490
milestone57.0a1
Bug 1388490 - Cancel animation set if necessary before re-start it. r?walkingice MozReview-Commit-ID: F1pDOxZp1SI
mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/TabCounter.java
--- a/mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/TabCounter.java
+++ b/mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/TabCounter.java
@@ -155,38 +155,42 @@ public class TabCounter extends ThemedRe
 
         animatorSet.play(firstAnimator).with(fadeOut);
         animatorSet.play(fadeOut).before(fadeIn);
         animatorSet.play(fadeIn).with(moveDown);
         animatorSet.play(moveDown).before(moveUp);
     }
 
     void setCountWithAnimation(final int count) {
-        // Don't animate from initial state
+        // Don't animate from initial state.
         if (this.count == 0) {
             setCount(count);
             return;
         }
 
         if (this.count == count) {
             return;
         }
 
-        // don't animate if there are still over MAX_VISIBLE_TABS tabs open
+        // Don't animate if there are still over MAX_VISIBLE_TABS tabs open.
         if (this.count > MAX_VISIBLE_TABS && count > MAX_VISIBLE_TABS) {
             this.count = count;
             return;
         }
 
         adjustTextSize(count);
 
         text.setText(formatForDisplay(count));
         this.count = count;
 
-        // Trigger animation
+        // Cancel previous animations if necessary.
+        if (animationSet.isRunning()) {
+            animationSet.cancel();
+        }
+        // Trigger animations.
         animationSet.start();
     }
 
     private String formatForDisplay(int count) {
         if (count > MAX_VISIBLE_TABS) {
             return SO_MANY_TABS_OPEN;
         }
         return String.valueOf(count);