Bug 817526 - Ensure awesome screen animation always starts from correct state (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Mon, 10 Dec 2012 13:03:56 +0000
changeset 124594 03e4cc5b322d1cdfc9f5204390acb9236316f66e
parent 124593 e5e7bb731ca1e1fb5cc6fa33f49a44f9d9a3f526
child 124595 e5082df102225e816deca3dc71ae5b4f9d0d4884
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs817526
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 817526 - Ensure awesome screen animation always starts from correct state (r=mfinkle)
mobile/android/base/BrowserToolbar.java
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -420,25 +420,96 @@ public class BrowserToolbar implements V
     }
 
     @Override
     public View makeView() {
         // This returns a TextView for the TextSwitcher.
         return mInflater.inflate(R.layout.tabs_counter, null);
     }
 
+    private int prepareAwesomeBarAnimation() {
+        // Keep the entry highlighted during the animation
+        mAwesomeBar.setSelected(true);
+
+        // Expand the entry to fill all the horizontal space available during the
+        // animation. The fake right edge will slide on top of it to give the effect
+        // of expanding the entry.
+        MarginLayoutParams entryParams = (MarginLayoutParams) mAwesomeBarEntry.getLayoutParams();
+        mAwesomeBarEntryRightMargin = entryParams.rightMargin;
+        entryParams.rightMargin = 0;
+        mAwesomeBarEntry.requestLayout();
+
+        // Remove any curves from the toolbar background and expand it to fill all
+        // the horizontal space.
+        MarginLayoutParams barParams = (MarginLayoutParams) mAddressBarBg.getLayoutParams();
+        mAddressBarBgRightMargin = barParams.rightMargin;
+        barParams.rightMargin = 0;
+        mAddressBarBgCurveTowards = mAddressBarBg.getCurveTowards();
+        mAddressBarBg.setCurveTowards(BrowserToolbarBackground.CurveTowards.NONE);
+        mAddressBarBg.requestLayout();
+
+        // If we don't have any menu_items, then we simply slide all elements on the
+        // rigth side of the toolbar out of screen.
+        int translation = mAwesomeBarEntryRightMargin;
+
+        if (mActionItemBar.getVisibility() == View.VISIBLE) {
+            // If the toolbar has action items (e.g. on the tablet UI), the translation will
+            // be in relation to the left side of their container (i.e. mActionItemBar).
+            MarginLayoutParams itemBarParams = (MarginLayoutParams) mActionItemBar.getLayoutParams();
+            translation = itemBarParams.rightMargin + mActionItemBar.getWidth() - entryParams.leftMargin;
+
+            // Expand the whole entry container to fill all the horizontal space available
+            View awesomeBarParent = (View) mAwesomeBar.getParent();
+            mAwesomeBarParams = (LayoutParams) awesomeBarParent.getLayoutParams();
+            awesomeBarParent.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+                                                              ViewGroup.LayoutParams.MATCH_PARENT));
+
+            // Align the fake right edge to the right side of the entry bar
+            MarginLayoutParams rightEdgeParams = (MarginLayoutParams) mAwesomeBarRightEdge.getLayoutParams();
+            rightEdgeParams.rightMargin = itemBarParams.rightMargin + mActionItemBar.getWidth() - 100;
+            mAwesomeBarRightEdge.requestLayout();
+        }
+
+        // Make the right edge visible to start the animation
+        mAwesomeBarRightEdge.setVisibility(View.VISIBLE);
+
+        return translation;
+    }
+
     public void fromAwesomeBarSearch() {
         if (mActivity.hasTabsSideBar() || Build.VERSION.SDK_INT < 11) {
             return;
         }
 
+        AnimatorProxy proxy = null;
+
+        // If the awesomebar entry is not selected at this point, this means that
+        // we had to reinflate the toolbar layout for some reason (device rotation
+        // while in awesome screen, activity was killed in background, etc). In this
+        // case, we have to ensure the toolbar is in the correct initial state to
+        // shrink back.
+        if (!mAwesomeBar.isSelected()) {
+            int translation = prepareAwesomeBarAnimation();
+
+            proxy = AnimatorProxy.create(mAwesomeBarRightEdge);
+            proxy.setTranslationX(translation);
+            proxy = AnimatorProxy.create(mTabs);
+            proxy.setTranslationX(translation);
+            proxy = AnimatorProxy.create(mTabsCount);
+            proxy.setTranslationX(translation);
+            proxy = AnimatorProxy.create(mMenu);
+            proxy.setTranslationX(translation);
+            proxy = AnimatorProxy.create(mActionItemBar);
+            proxy.setTranslationX(translation);
+        }
+
         // Restore opacity of content elements in the toolbar immediatelly
         // so that the response is immediate from user interaction in the
         // awesome screen.
-        AnimatorProxy proxy = AnimatorProxy.create(mFavicon);
+        proxy = AnimatorProxy.create(mFavicon);
         proxy.setAlpha(1);
         proxy = AnimatorProxy.create(mSiteSecurity);
         proxy.setAlpha(1);
         proxy = AnimatorProxy.create(mTitle);
         proxy.setAlpha(1);
         proxy = AnimatorProxy.create(mForward);
         proxy.setAlpha(1);
         proxy = AnimatorProxy.create(mBack);
@@ -484,17 +555,17 @@ public class BrowserToolbar implements V
                 barParams.rightMargin = mAddressBarBgRightMargin;
                 mAddressBarBg.setCurveTowards(mAddressBarBgCurveTowards);
                 mAddressBarBg.requestLayout();
 
                 // If there are action bar items in the toolbar, we have to restore the
                 // alignment of the entry in relation to them. mAwesomeBarParams might
                 // be null if the activity holding the toolbar is killed before returning
                 // from awesome screen (e.g. "Don't keep activities" is on)
-                if (mActionItemBar.getVisibility() == View.VISIBLE && mAwesomeBarParams != null)
+                if (mActionItemBar.getVisibility() == View.VISIBLE)
                     ((View) mAwesomeBar.getParent()).setLayoutParams(mAwesomeBarParams);
 
                 // Hide fake right edge, we only use for the animation
                 mAwesomeBarRightEdge.setVisibility(View.INVISIBLE);
 
                 PropertyAnimator buttonsAnimator = new PropertyAnimator(150);
 
                 // Fade toolbar buttons (reader, stop) after the entry
@@ -521,71 +592,30 @@ public class BrowserToolbar implements V
         // This animation doesn't make much sense in a sidebar UI
         if (mActivity.hasTabsSideBar() || Build.VERSION.SDK_INT < 11) {
             mActivity.onSearchRequested();
             return;
         }
 
         final PropertyAnimator contentAnimator = new PropertyAnimator(250);
 
-        // Keep the entry highlighted during the animation
-        mAwesomeBar.setSelected(true);
-
-        // Expand the entry to fill all the horizontal space available during the
-        // animation. The fake right edge will slide on top of it to give the effect
-        // of expanding the entry.
-        MarginLayoutParams entryParams = (MarginLayoutParams) mAwesomeBarEntry.getLayoutParams();
-        mAwesomeBarEntryRightMargin = entryParams.rightMargin;
-        entryParams.rightMargin = 0;
-        mAwesomeBarEntry.requestLayout();
-
-        // Remove any curves from the toolbar background and expand it to fill all
-        // the horizontal space.
-        MarginLayoutParams barParams = (MarginLayoutParams) mAddressBarBg.getLayoutParams();
-        mAddressBarBgRightMargin = barParams.rightMargin;
-        barParams.rightMargin = 0;
-        mAddressBarBgCurveTowards = mAddressBarBg.getCurveTowards();
-        mAddressBarBg.setCurveTowards(BrowserToolbarBackground.CurveTowards.NONE);
-        mAddressBarBg.requestLayout();
-
-        // If we don't have any menu_items, then we simply slide all elements on the
-        // rigth side of the toolbar out of screen.
-        int translation = mAwesomeBarEntryRightMargin;
+        int translation = prepareAwesomeBarAnimation();
 
         if (mActionItemBar.getVisibility() == View.VISIBLE) {
-            // If the toolbar has action items (e.g. on the tablet UI), the translation will
-            // be in relation to the left side of their container (i.e. mActionItemBar).
-            MarginLayoutParams itemBarParams = (MarginLayoutParams) mActionItemBar.getLayoutParams();
-            translation = itemBarParams.rightMargin + mActionItemBar.getWidth() - entryParams.leftMargin;
-
-            // Expand the whole entry container to fill all the horizontal space available
-            View awesomeBarParent = (View) mAwesomeBar.getParent();
-            mAwesomeBarParams = (LayoutParams) awesomeBarParent.getLayoutParams();
-            awesomeBarParent.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
-                                                              ViewGroup.LayoutParams.MATCH_PARENT));
-
-            // Align the fake right edge to the right side of the entry bar
-            MarginLayoutParams rightEdgeParams = (MarginLayoutParams) mAwesomeBarRightEdge.getLayoutParams();
-            rightEdgeParams.rightMargin = itemBarParams.rightMargin + mActionItemBar.getWidth() - 100;
-            mAwesomeBarRightEdge.requestLayout();
-
             contentAnimator.attach(mFavicon,
                                    PropertyAnimator.Property.ALPHA,
                                    0);
             contentAnimator.attach(mSiteSecurity,
                                    PropertyAnimator.Property.ALPHA,
                                    0);
             contentAnimator.attach(mTitle,
                                    PropertyAnimator.Property.ALPHA,
                                    0);
         }
 
-        // Make the right edge visible to start the animation
-        mAwesomeBarRightEdge.setVisibility(View.VISIBLE);
-
         // Fade out all controls inside the toolbar
         contentAnimator.attach(mForward,
                                PropertyAnimator.Property.ALPHA,
                                0);
         contentAnimator.attach(mBack,
                                PropertyAnimator.Property.ALPHA,
                                0);
         contentAnimator.attach(mReader,