Bug 935473 - Factor out method to animate forward button's visibility (r=wesj, a=lsblakk)
authorLucas Rocha <lucasr@lucasr.org>
Thu, 05 Dec 2013 16:26:35 +0000
changeset 167854 499a6bcb6da9ed3f659c4489536dd1800d535556
parent 167853 b57e3944342ae56eda58f5750144b4c0b8880fce
child 167855 ea3d6f1fcaaf051ed0db29a587d490195a44c074
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj, lsblakk
bugs935473
milestone27.0
Bug 935473 - Factor out method to animate forward button's visibility (r=wesj, a=lsblakk)
mobile/android/base/BrowserToolbar.java
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -1666,43 +1666,36 @@ public class BrowserToolbar extends Geck
 
         button.setEnabled(enabled);
     }
 
     public void updateBackButton(boolean enabled) {
         setButtonEnabled(mBack, enabled);
     }
 
-    public void updateForwardButton(final boolean enabled) {
-        if (mForward.isEnabled() == enabled)
-            return;
-
-        // Save the state on the forward button so that we can skip animations
-        // when there's nothing to change
-        setButtonEnabled(mForward, enabled);
-
+    private void animateForwardButton(final boolean visible) {
         if (mForward.getVisibility() != View.VISIBLE)
             return;
 
         // if the forward button's margin is non-zero, this means it has already
         // been animated to be visibleΒΈ and vice-versa.
         MarginLayoutParams fwdParams = (MarginLayoutParams) mForward.getLayoutParams();
-        if ((fwdParams.leftMargin > mDefaultForwardMargin && enabled) ||
-            (fwdParams.leftMargin == mDefaultForwardMargin && !enabled)) {
+        if ((fwdParams.leftMargin > mDefaultForwardMargin && visible) ||
+            (fwdParams.leftMargin == mDefaultForwardMargin && !visible)) {
             return;
         }
 
         // We want the forward button to show immediately when switching tabs
         mForwardAnim = new PropertyAnimator(mSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION);
         final int width = mForward.getWidth() / 2;
 
         mForwardAnim.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
             @Override
             public void onPropertyAnimationStart() {
-                if (!enabled) {
+                if (!visible) {
                     // Set the margin before the transition when hiding the forward button. We
                     // have to do this so that the favicon isn't clipped during the transition
                     MarginLayoutParams layoutParams =
                         (MarginLayoutParams) mUrlDisplayContainer.getLayoutParams();
                     layoutParams.leftMargin = 0;
 
                     // Do the same on the URL edit container
                     layoutParams = (MarginLayoutParams)mUrlEditContainer.getLayoutParams();
@@ -1712,42 +1705,52 @@ public class BrowserToolbar extends Geck
                     // Note, we already translated the favicon, site security, and text field
                     // in prepareForwardAnimation, so they should appear to have not moved at
                     // all at this point.
                 }
             }
 
             @Override
             public void onPropertyAnimationEnd() {
-                if (enabled) {
+                if (visible) {
                     MarginLayoutParams layoutParams =
                         (MarginLayoutParams) mUrlDisplayContainer.getLayoutParams();
                     layoutParams.leftMargin = mUrlBarViewOffset;
 
                     layoutParams = (MarginLayoutParams)mUrlEditContainer.getLayoutParams();
                     layoutParams.leftMargin = mUrlBarViewOffset;
 
                     ViewHelper.setTranslationX(mTitle, 0);
                     ViewHelper.setTranslationX(mFavicon, 0);
                     ViewHelper.setTranslationX(mSiteSecurity, 0);
                 }
 
                 MarginLayoutParams layoutParams = (MarginLayoutParams) mForward.getLayoutParams();
-                layoutParams.leftMargin = mDefaultForwardMargin + (mForward.isEnabled() ? width : 0);
+                layoutParams.leftMargin = mDefaultForwardMargin + (visible ? width : 0);
                 ViewHelper.setTranslationX(mForward, 0);
 
                 requestLayout();
                 mForwardAnim = null;
             }
         });
 
-        prepareForwardAnimation(mForwardAnim, enabled, width);
+        prepareForwardAnimation(mForwardAnim, visible, width);
         mForwardAnim.start();
     }
 
+    public void updateForwardButton(boolean enabled) {
+        if (mForward.isEnabled() == enabled)
+            return;
+
+        // Save the state on the forward button so that we can skip animations
+        // when there's nothing to change
+        setButtonEnabled(mForward, enabled);
+        animateForwardButton(enabled);
+    }
+
     private void prepareForwardAnimation(PropertyAnimator anim, boolean enabled, int width) {
         if (!enabled) {
             anim.attach(mForward,
                       PropertyAnimator.Property.TRANSLATION_X,
                       -width);
             anim.attach(mForward,
                       PropertyAnimator.Property.ALPHA,
                       0);