From 88258ab9e4808f92c310e68b723556be9f2c3d0c Mon Sep 17 00:00:00 2001 From: Martyn Haigh Date: Fri, 17 Oct 2014 08:59:51 +0100 Subject: [PATCH] Bug 866302 - Handle 100+ tabs in counter (r=wesj) --- mobile/android/base/toolbar/TabCounter.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/mobile/android/base/toolbar/TabCounter.java b/mobile/android/base/toolbar/TabCounter.java index 770edc373ff5..794fa8df02cd 100644 --- a/mobile/android/base/toolbar/TabCounter.java +++ b/mobile/android/base/toolbar/TabCounter.java @@ -36,6 +36,8 @@ public class TabCounter extends ThemedTextSwitcher 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, @@ -84,6 +86,12 @@ public class TabCounter extends ThemedTextSwitcher 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); @@ -97,14 +105,21 @@ public class TabCounter extends ThemedTextSwitcher 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; }