From a2f48f5d4ae748c8fbaf1b1637e5eb5839175d91 Mon Sep 17 00:00:00 2001 From: Brian Nicholson Date: Wed, 1 Feb 2012 14:25:50 -0800 Subject: [PATCH] Bug 719479 - Don't animate tab counter during session restore. r=mfinkle --- mobile/android/base/BrowserToolbar.java | 14 ++++++--- mobile/android/base/GeckoApp.java | 36 +++++++++++++----------- mobile/android/base/Tabs.java | 26 +++++++++++++---- mobile/android/chrome/content/browser.js | 12 ++++++++ 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index b7577d3a5e3..c9122885e57 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -151,7 +151,7 @@ public class BrowserToolbar extends LinearLayout { addTab(); } }); - mTabs.setImageLevel(1); + mTabs.setImageLevel(0); mCounterColor = 0xFFC7D1DB; @@ -224,8 +224,8 @@ public class BrowserToolbar extends LinearLayout { public int getHighlightColor() { return mColor; } - - public void updateTabs(int count) { + + public void updateTabCountAndAnimate(int count) { if (mCount > count) { mTabsCount.setInAnimation(mSlideDownIn); mTabsCount.setOutAnimation(mSlideDownOut); @@ -267,6 +267,12 @@ public class BrowserToolbar extends LinearLayout { }, 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); @@ -326,7 +332,7 @@ public class BrowserToolbar extends LinearLayout { setSecurityMode(tab.getSecurityMode()); setProgressVisibility(tab.isLoading()); setShadowVisibility(!(tab.getURL().startsWith("about:"))); - updateTabs(Tabs.getInstance().getCount()); + updateTabCountAndAnimate(Tabs.getInstance().getCount()); } } } diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 97cacfb3530..70e69bf727f 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1659,6 +1659,20 @@ abstract public class GeckoApp 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) @@ -1672,8 +1686,12 @@ abstract public class GeckoApp 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) @@ -1698,20 +1716,6 @@ abstract public class GeckoApp 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 @@ -1727,7 +1731,7 @@ abstract public class GeckoApp 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()); diff --git a/mobile/android/base/Tabs.java b/mobile/android/base/Tabs.java index 93981efdb33..012e98bfb55 100644 --- a/mobile/android/base/Tabs.java +++ b/mobile/android/base/Tabs.java @@ -55,6 +55,7 @@ public class Tabs implements GeckoEventListener { private HashMap tabs; private ArrayList order; private ContentResolver resolver; + private boolean mRestoringSession = false; private Tabs() { tabs = new HashMap(); @@ -68,6 +69,8 @@ public class Tabs implements GeckoEventListener { 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() { @@ -88,11 +91,13 @@ public class Tabs implements GeckoEventListener { 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; @@ -197,7 +202,7 @@ public class Tabs implements GeckoEventListener { 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.hidePlugins(closedTab, true); } @@ -290,6 +295,15 @@ public class Tabs implements GeckoEventListener { 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); diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 5006d720bfc..645f18c5f58 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -292,6 +292,12 @@ var BrowserApp = { // 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); @@ -308,6 +314,12 @@ var BrowserApp = { let params = { selected: restoreToFront }; BrowserApp.addTab("about:home", { showProgress: false }); } + + sendMessageToJava({ + gecko: { + type: "Session:RestoreEnd" + } + }); } }; Services.obs.addObserver(restoreCleanup, "sessionstore-windows-restored", false);