Bug 719479 - Don't animate tab counter during session restore. r=mfinkle a=akeybl
authorBrian Nicholson <bnicholson@mozilla.com>
Wed, 01 Feb 2012 14:25:50 -0800
changeset 88336 3f61c19f697d865995bea8d6fe90bb2e810ace4d
parent 88335 c9fb84b0331eacdeaf36d3c71e10cabb03b8dffe
child 88337 f68ab5b1ce7afafce5dd920f205b889c2f7789fa
push idunknown
push userunknown
push dateunknown
reviewersmfinkle, akeybl
bugs719479
milestone12.0a2
Bug 719479 - Don't animate tab counter during session restore. r=mfinkle a=akeybl
mobile/android/base/BrowserToolbar.java
mobile/android/base/GeckoApp.java
mobile/android/base/Tabs.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -146,17 +146,17 @@ public class BrowserToolbar extends Line
         mTabs.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 if (Tabs.getInstance().getCount() > 1)
                     showTabs();
                 else
                     addTab();
             }
         });
-        mTabs.setImageLevel(1);
+        mTabs.setImageLevel(0);
 
         mCounterColor = 0xFFC7D1DB;
 
         mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count);
         mTabsCount.removeAllViews();
         mTabsCount.setFactory(new ViewFactory() {
             public View makeView() {
                 TextView text = new TextView(mContext);
@@ -219,18 +219,18 @@ public class BrowserToolbar extends Line
 
     private void doStop() {
         GeckoApp.mAppContext.doStop();
     }
 
     public int getHighlightColor() {
         return mColor;
     }
-    
-    public void updateTabs(int count) {
+
+    public void updateTabCountAndAnimate(int count) {
         if (mCount > count) {
             mTabsCount.setInAnimation(mSlideDownIn);
             mTabsCount.setOutAnimation(mSlideDownOut);
         } else if (mCount < count) {
             mTabsCount.setInAnimation(mSlideUpIn);
             mTabsCount.setOutAnimation(mSlideUpOut);
         }
 
@@ -262,16 +262,22 @@ public class BrowserToolbar extends Line
                     mTabs.setImageLevel(1);
                     mTabsCount.setVisibility(View.GONE);
                 }
                 ((TextView) mTabsCount.getCurrentView()).setTextColor(mCounterColor);
             }
         }, 2 * mDuration);
     }
 
+    public void updateTabCount(int count) {
+        mTabsCount.setCurrentText(String.valueOf(count));
+        mTabs.setImageLevel(count);
+        mTabsCount.setVisibility(count > 1 ? View.VISIBLE : View.INVISIBLE);
+    }
+
     public void setProgressVisibility(boolean visible) {
         if (visible) {
             mFavicon.setImageDrawable(mProgressSpinner);
             mProgressSpinner.start();
             setStopVisibility(true);
             Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber start");
         } else {
             mProgressSpinner.stop();
@@ -321,12 +327,12 @@ public class BrowserToolbar extends Line
     public void refresh() {
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab != null) {
             setTitle(tab.getDisplayTitle());
             setFavicon(tab.getFavicon());
             setSecurityMode(tab.getSecurityMode());
             setProgressVisibility(tab.isLoading());
             setShadowVisibility(!(tab.getURL().startsWith("about:")));
-            updateTabs(Tabs.getInstance().getCount());
+            updateTabCountAndAnimate(Tabs.getInstance().getCount());
         }
     }
 }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1552,31 +1552,49 @@ abstract public class GeckoApp
             }
         }
 
         if (ACTION_UPDATE.equals(intent.getAction()) || args != null && args.contains("-alert update-app")) {
             Log.i(LOGTAG,"onCreate: Update request");
             checkAndLaunchUpdate();
         }
 
+        super.onCreate(savedInstanceState);
+
+        setContentView(R.layout.gecko_app);
+
+        mOrientation = getResources().getConfiguration().orientation;
+
+        if (Build.VERSION.SDK_INT >= 11) {
+            refreshActionBar();
+        } else {
+            mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
+        }
+
+        mBrowserToolbar.setTitle(mLastTitle);
+
         String passedUri = null;
         String uri = getURIFromIntent(intent);
         if (uri != null && uri.length() > 0)
             passedUri = mLastTitle = uri;
 
         if (passedUri == null || passedUri.equals("about:home")) {
             // show about:home if we aren't restoring previous session
             Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - start check sessionstore.bak exists");
             File profileDir = getProfileDir();
             boolean sessionExists = false;
             if (profileDir != null)
                 sessionExists = new File(profileDir, "sessionstore.bak").exists();
             Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - finish check sessionstore.bak exists");
-            if (!sessionExists)
+            if (!sessionExists) {
+                mBrowserToolbar.updateTabCount(1);
                 showAboutHome();
+            }
+        } else {
+            mBrowserToolbar.updateTabCount(1);
         }
 
         if (sGREDir == null)
             sGREDir = new File(this.getApplicationInfo().dataDir);
 
         Uri data = intent.getData();
         if (data != null && "http".equals(data.getScheme()) &&
             isHostOnPrefetchWhitelist(data.getHost())) {
@@ -1591,46 +1609,32 @@ abstract public class GeckoApp
             passedUri = null;
         }
 
         sGeckoThread = new GeckoThread(intent, passedUri, mRestoreSession);
         if (!ACTION_DEBUG.equals(intent.getAction()) &&
             checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
             sGeckoThread.start();
 
-        super.onCreate(savedInstanceState);
-
-        setContentView(R.layout.gecko_app);
-
-        mOrientation = getResources().getConfiguration().orientation;
-
-        if (Build.VERSION.SDK_INT >= 11) {
-            refreshActionBar();
-        } else {
-            mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
-        }
-
-        mBrowserToolbar.setTitle(mLastTitle);
-
         mFavicons = new Favicons(this);
 
         // setup gecko layout
         mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
         mMainLayout = (LinearLayout) findViewById(R.id.main_layout);
 
         mDoorHangerPopup = new DoorHangerPopup(this);
         mAutoCompletePopup = (AutoCompletePopup) findViewById(R.id.autocomplete_popup);
 
         Tabs tabs = Tabs.getInstance();
         Tab tab = tabs.getSelectedTab();
         if (tab != null) {
             mBrowserToolbar.setTitle(tab.getDisplayTitle());
             mBrowserToolbar.setFavicon(tab.getFavicon());
             mBrowserToolbar.setProgressVisibility(tab.isLoading());
-            mBrowserToolbar.updateTabs(Tabs.getInstance().getCount()); 
+            mBrowserToolbar.updateTabCountAndAnimate(Tabs.getInstance().getCount()); 
         }
 
         tabs.setContentResolver(getContentResolver()); 
 
         if (cameraView == null) {
             cameraView = new SurfaceView(this);
             cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
         }
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -50,29 +50,32 @@ import android.util.Log;
 
 public class Tabs implements GeckoEventListener {
     private static final String LOGTAG = "GeckoTabs";
 
     private Tab selectedTab;
     private HashMap<Integer, Tab> tabs;
     private ArrayList<Tab> order;
     private ContentResolver resolver;
+    private boolean mRestoringSession = false;
 
     private Tabs() {
         tabs = new HashMap<Integer, Tab>();
         order = new ArrayList<Tab>();
         GeckoAppShell.registerGeckoEventListener("SessionHistory:New", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Back", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Forward", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Goto", this);
         GeckoAppShell.registerGeckoEventListener("SessionHistory:Purge", this);
         GeckoAppShell.registerGeckoEventListener("Tab:Added", this);
         GeckoAppShell.registerGeckoEventListener("Tab:Close", this);
         GeckoAppShell.registerGeckoEventListener("Tab:Select", this);
         GeckoAppShell.registerGeckoEventListener("Tab:ScreenshotData", this);
+        GeckoAppShell.registerGeckoEventListener("Session:RestoreBegin", this);
+        GeckoAppShell.registerGeckoEventListener("Session:RestoreEnd", this);
     }
 
     public int getCount() {
         return tabs.size();
     }
 
     public Tab addTab(JSONObject params) throws JSONException {
         int id = params.getInt("tabID");
@@ -83,21 +86,23 @@ public class Tabs implements GeckoEventL
         Boolean external = params.getBoolean("external");
         int parentId = params.getInt("parentId");
         String title = params.getString("title");
 
         Tab tab = new Tab(id, url, external, parentId, title);
         tabs.put(id, tab);
         order.add(tab);
 
-        GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
-            public void run() {
-                GeckoApp.mBrowserToolbar.updateTabs(getCount());
-            }
-        });
+        if (!mRestoringSession) {
+            GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
+                public void run() {
+                    GeckoApp.mBrowserToolbar.updateTabCountAndAnimate(getCount());
+                }
+            });
+        }
 
         Log.i(LOGTAG, "Added a tab with id: " + id + ", url: " + url);
         return tab;
     }
 
     public void removeTab(int id) {
         if (tabs.containsKey(id)) {
             order.remove(getTab(id));
@@ -192,17 +197,17 @@ public class Tabs implements GeckoEventL
         int tabId = tab.getId();
         removeTab(tabId);
         tab.removeAllDoorHangers();
 
         final Tab closedTab = tab;
         GeckoApp.mAppContext.mMainHandler.post(new Runnable() { 
             public void run() {
                 GeckoApp.mAppContext.onTabsChanged(closedTab);
-                GeckoApp.mBrowserToolbar.updateTabs(Tabs.getInstance().getCount());
+                GeckoApp.mBrowserToolbar.updateTabCountAndAnimate(Tabs.getInstance().getCount());
                 GeckoApp.mDoorHangerPopup.updatePopup();
                 GeckoApp.mAppContext.hidePluginViews(closedTab);
             }
         });
 
         // Pass a message to Gecko to update tab state in BrowserApp
         GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Closed", String.valueOf(tabId)));
     }
@@ -285,16 +290,25 @@ public class Tabs implements GeckoEventL
                 selectTab(message.getInt("tabID"));
             } else if (event.equals("Tab:ScreenshotData")) {
                 Tab tab = getTab(message.getInt("tabID"));
                 String data = message.getString("data");
                 if (data.length() < 22)
                     return;
                 byte[] compressed = GeckoAppShell.decodeBase64(data.substring(22));
                 GeckoApp.mAppContext.processThumbnail(tab, null, compressed);
+            } else if (event.equals("Session:RestoreBegin")) {
+                mRestoringSession = true;
+            } else if (event.equals("Session:RestoreEnd")) {
+                mRestoringSession = false;
+                GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
+                    public void run() {
+                        GeckoApp.mBrowserToolbar.updateTabCount(getCount());
+                    }
+                });
             }
         } catch (Exception e) { 
             Log.i(LOGTAG, "handleMessage throws " + e + " for message: " + event);
         }
     }
 
     public void refreshThumbnails() {
         Iterator<Tab> iterator = tabs.values().iterator();
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -287,32 +287,44 @@ var BrowserApp = {
     window.dispatchEvent(event);
 
     // restore the previous session
     let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
     if (forceRestore || ss.shouldRestore()) {
       // A restored tab should not be active if we are loading a URL
       let restoreToFront = false;
 
+      sendMessageToJava({
+        gecko: {
+          type: "Session:RestoreBegin"
+        }
+      });
+
       // Open any commandline URLs, except the homepage
       if (url && url != "about:home") {
         this.addTab(url);
       } else {
         // Let the session make a restored tab active
         restoreToFront = true;
       }
 
       // Be ready to handle any restore failures by making sure we have a valid tab opened
       let restoreCleanup = {
         observe: function(aSubject, aTopic, aData) {
           Services.obs.removeObserver(restoreCleanup, "sessionstore-windows-restored");
           if (aData == "fail") {
             let params = { selected: restoreToFront };
             BrowserApp.addTab("about:home", { showProgress: false });
           }
+
+          sendMessageToJava({
+            gecko: {
+              type: "Session:RestoreEnd"
+            }
+          });
         }
       };
       Services.obs.addObserver(restoreCleanup, "sessionstore-windows-restored", false);
 
       // Start the restore
       ss.restoreLastSession(restoreToFront, forceRestore);
     } else {
       this.addTab(url, { showProgress: url != "about:home" });