Bug 964861 - Don't update the toolbar state before it gets attached. r=bnicholson, a=sledru
authorLucas Rocha <lucasr@mozilla.com>
Tue, 17 Jun 2014 14:29:31 +0100
changeset 209138 e1b73deedcb4510a03615fc1e364ac912805b938
parent 209137 5f975bb5e02c2d7a69ed5638a3601559cd746a9d
child 209139 86f3313577835eea2e1d1aecaffa5355d6807e20
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson, sledru
bugs964861
milestone32.0a2
Bug 964861 - Don't update the toolbar state before it gets attached. r=bnicholson, a=sledru
mobile/android/base/toolbar/ToolbarDisplayLayout.java
--- a/mobile/android/base/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/toolbar/ToolbarDisplayLayout.java
@@ -94,16 +94,18 @@ public class ToolbarDisplayLayout extend
     interface OnTitleChangeListener {
         public void onTitleChange(CharSequence title);
     }
 
     private final BrowserApp mActivity;
 
     private UIMode mUiMode;
 
+    private boolean mIsAttached;
+
     private ThemedTextView mTitle;
     private int mTitlePadding;
     private ToolbarTitlePrefs mTitlePrefs;
     private OnTitleChangeListener mTitleChangeListener;
 
     private ImageButton mSiteSecurity;
     private boolean mSiteSecurityVisible;
 
@@ -162,16 +164,17 @@ public class ToolbarDisplayLayout extend
         mSiteIdentityPopup.setAnchor(mSiteSecurity);
 
         mStop = (ImageButton) findViewById(R.id.stop);
         mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
     }
 
     @Override
     public void onAttachedToWindow() {
+        mIsAttached = true;
         mTitlePrefs = new ToolbarTitlePrefs();
 
         Button.OnClickListener faviconListener = new Button.OnClickListener() {
             @Override
             public void onClick(View view) {
                 if (mSiteSecurity.getVisibility() != View.VISIBLE) {
                     return;
                 }
@@ -215,16 +218,17 @@ public class ToolbarDisplayLayout extend
         final int lockAnimDuration = 300;
         mLockFadeIn.setDuration(lockAnimDuration);
         mTitleSlideLeft.setDuration(lockAnimDuration);
         mTitleSlideRight.setDuration(lockAnimDuration);
     }
 
     @Override
     public void onDetachedFromWindow() {
+        mIsAttached = false;
         mTitlePrefs.close();
     }
 
     @Override
     public void onAnimationStart(Animation animation) {
         if (animation.equals(mLockFadeIn)) {
             if (mSiteSecurityVisible)
                 mSiteSecurity.setVisibility(View.VISIBLE);
@@ -255,16 +259,22 @@ public class ToolbarDisplayLayout extend
     public void setNextFocusDownId(int nextId) {
         mFavicon.setNextFocusDownId(nextId);
         mStop.setNextFocusDownId(nextId);
         mSiteSecurity.setNextFocusDownId(nextId);
         mPageActionLayout.setNextFocusDownId(nextId);
     }
 
     void updateFromTab(Tab tab, EnumSet<UpdateFlags> flags) {
+        // Several parts of ToolbarDisplayLayout's state depends
+        // on the views being attached to the view tree.
+        if (!mIsAttached) {
+            return;
+        }
+
         if (flags.contains(UpdateFlags.TITLE)) {
             updateTitle(tab);
         }
 
         if (flags.contains(UpdateFlags.FAVICON)) {
             updateFavicon(tab);
         }