Bug 866302 - Handle 100+ tabs in counter (r=wesj)
authorMartyn Haigh <martyn.haigh@gmail.com>
Fri, 17 Oct 2014 08:59:51 +0100
changeset 210880 d78c76600b5c193b63f7887d395bb89a294c082f
parent 210856 c0d668591c904c012ccee89a7b05d415577a3677
child 210881 1bf2dfb0b674db79aad4f68b694260018ccdda40
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerswesj
bugs866302
milestone36.0a1
Bug 866302 - Handle 100+ tabs in counter (r=wesj)
mobile/android/base/toolbar/TabCounter.java
--- a/mobile/android/base/toolbar/TabCounter.java
+++ b/mobile/android/base/toolbar/TabCounter.java
@@ -31,16 +31,18 @@ public class TabCounter extends ThemedTe
     private final AnimationSet mFlipInForward;
     private final AnimationSet mFlipInBackward;
     private final AnimationSet mFlipOutForward;
     private final AnimationSet mFlipOutBackward;
     private final LayoutInflater mInflater;
     private final int mLayoutId;
 
     private int mCount;
+    public static final int MAX_VISIBLE_TABS = 99;
+    public static final String SO_MANY_TABS_OPEN = "∞";
 
     private enum FadeMode {
         FADE_IN,
         FADE_OUT
     }
 
     public TabCounter(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -79,37 +81,50 @@ public class TabCounter extends ThemedTe
             setCount(count);
             return;
         }
 
         if (mCount == count) {
             return;
         }
 
+        // don't animate if there are still over MAX_VISIBLE_TABS tabs open
+        if (mCount > MAX_VISIBLE_TABS && count > MAX_VISIBLE_TABS) {
+            mCount = count;
+            return;
+        }
+
         if (count < mCount) {
             setInAnimation(mFlipInBackward);
             setOutAnimation(mFlipOutForward);
         } else {
             setInAnimation(mFlipInForward);
             setOutAnimation(mFlipOutBackward);
         }
 
         // Eliminate screen artifact. Set explicit In/Out animation pair order. This will always
         // animate pair in In->Out child order, prevent alternating use of the Out->In case.
         setDisplayedChild(0);
 
         // Set In value, trigger animation to Out value
-        setCurrentText(String.valueOf(mCount));
-        setText(String.valueOf(count));
+        setCurrentText(formatForDisplay(mCount));
+        setText(formatForDisplay(count));
 
         mCount = count;
     }
 
+    private String formatForDisplay(int count) {
+        if (count > MAX_VISIBLE_TABS) {
+            return SO_MANY_TABS_OPEN;
+        }
+        return String.valueOf(count);
+    }
+
     void setCount(int count) {
-        setCurrentText(String.valueOf(count));
+        setCurrentText(formatForDisplay(count));
         mCount = count;
     }
 
     // Alpha animations in editing mode cause action bar corruption on the
     // Nexus 7 (bug 961749). As a workaround, skip these animations in editing
     // mode.
     void onEnterEditingMode() {
         final int childCount = getChildCount();