Bug 965548 - Part 6: Improve readability for BrowserToolbar.start/stopEditing methods. r=lucasr
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 17 Apr 2014 13:34:12 -0700
changeset 179088 9a5586190013a870fcf0b2b2eb64039fdcd24db4
parent 179087 440224cc83d9162ce2b0f963315902d9bc95f2ae
child 179089 d46231f4d4ae9e73a5c41c637ca4ac8e1a9eab0d
push id26606
push userryanvm@gmail.com
push dateFri, 18 Apr 2014 02:20:00 +0000
treeherdermozilla-central@ec728bfdbb79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs965548
milestone31.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 965548 - Part 6: Improve readability for BrowserToolbar.start/stopEditing methods. r=lucasr
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -979,48 +979,55 @@ public class BrowserToolbar extends Them
 
         if (urlBarTranslatingEdge != null) {
             urlBarTranslatingEdge.setVisibility(View.VISIBLE);
             if (shouldShrinkURLBar) {
                 mUrlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams);
             }
         }
 
-        // This animation doesn't make much sense in a sidebar UI
-        if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
+        if (Build.VERSION.SDK_INT < 11) {
+            showEditingWithoutAnimation(entryTranslation, curveTranslation);
+        } else if (HardwareUtils.isTablet()) {
+            // No animation.
             showUrlEditLayout();
-
-            if (!HardwareUtils.isTablet()) {
-                if (urlBarTranslatingEdge != null) {
-                    ViewHelper.setTranslationX(urlBarTranslatingEdge, entryTranslation);
-                }
+        } else {
+            showEditingWithPhoneAnimation(animator, entryTranslation, curveTranslation);
+        }
+    }
 
-                ViewHelper.setTranslationX(mTabs, curveTranslation);
-                ViewHelper.setTranslationX(mTabsCounter, curveTranslation);
-                ViewHelper.setTranslationX(mActionItemBar, curveTranslation);
+    private void showEditingWithoutAnimation(final int entryTranslation,
+            final int curveTranslation) {
+        showUrlEditLayout();
 
-                if (mHasSoftMenuButton) {
-                    ViewHelper.setTranslationX(mMenu, curveTranslation);
-                    ViewHelper.setTranslationX(mMenuIcon, curveTranslation);
-                }
-            }
-
-            return;
+        if (urlBarTranslatingEdge != null) {
+            ViewHelper.setTranslationX(urlBarTranslatingEdge, entryTranslation);
         }
 
+        ViewHelper.setTranslationX(mTabs, curveTranslation);
+        ViewHelper.setTranslationX(mTabsCounter, curveTranslation);
+        ViewHelper.setTranslationX(mActionItemBar, curveTranslation);
+
+        if (mHasSoftMenuButton) {
+            ViewHelper.setTranslationX(mMenu, curveTranslation);
+            ViewHelper.setTranslationX(mMenuIcon, curveTranslation);
+        }
+    }
+
+    private void showEditingWithPhoneAnimation(final PropertyAnimator animator,
+            final int entryTranslation, final int curveTranslation) {
         if (mAnimatingEntry)
             return;
 
         // Highlight the toolbar from the start of the animation.
         setSelected(true);
 
         mUrlDisplayLayout.prepareStartEditingAnimation();
 
-        // Slide the right side elements of the toolbar
-
+        // Slide toolbar elements.
         if (urlBarTranslatingEdge != null) {
             animator.attach(urlBarTranslatingEdge,
                             PropertyAnimator.Property.TRANSLATION_X,
                             entryTranslation);
         }
 
         animator.attach(mTabs,
                         PropertyAnimator.Property.TRANSLATION_X,
@@ -1090,48 +1097,56 @@ public class BrowserToolbar extends Them
         updateChildrenForEditing();
 
         if (mStopEditingListener != null) {
             mStopEditingListener.onStopEditing();
         }
 
         updateProgressVisibility();
 
-        if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
+        if (Build.VERSION.SDK_INT < 11) {
+            stopEditingWithoutAnimation();
+        } else if (HardwareUtils.isTablet()) {
+            // No animation.
             hideUrlEditLayout();
-
-            if (!HardwareUtils.isTablet()) {
-                updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
-
-                if (urlBarTranslatingEdge != null) {
-                    urlBarTranslatingEdge.setVisibility(View.INVISIBLE);
-                    ViewHelper.setTranslationX(urlBarTranslatingEdge, 0);
-                    if (shouldShrinkURLBar) {
-                        mUrlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams);
-                    }
-                }
-
-                ViewHelper.setTranslationX(mTabs, 0);
-                ViewHelper.setTranslationX(mTabsCounter, 0);
-                ViewHelper.setTranslationX(mActionItemBar, 0);
-
-                if (mHasSoftMenuButton) {
-                    ViewHelper.setTranslationX(mMenu, 0);
-                    ViewHelper.setTranslationX(mMenuIcon, 0);
-                }
-            }
-
-            return url;
+        } else {
+            stopEditingWithPhoneAnimation();
         }
 
+        return url;
+    }
+
+    private void stopEditingWithoutAnimation() {
+        hideUrlEditLayout();
+
+        updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
+
+        if (urlBarTranslatingEdge != null) {
+            urlBarTranslatingEdge.setVisibility(View.INVISIBLE);
+            ViewHelper.setTranslationX(urlBarTranslatingEdge, 0);
+            if (shouldShrinkURLBar) {
+                mUrlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams);
+            }
+        }
+
+        ViewHelper.setTranslationX(mTabs, 0);
+        ViewHelper.setTranslationX(mTabsCounter, 0);
+        ViewHelper.setTranslationX(mActionItemBar, 0);
+
+        if (mHasSoftMenuButton) {
+            ViewHelper.setTranslationX(mMenu, 0);
+            ViewHelper.setTranslationX(mMenuIcon, 0);
+        }
+    }
+
+    private void stopEditingWithPhoneAnimation() {
         final PropertyAnimator contentAnimator = new PropertyAnimator(250);
         contentAnimator.setUseHardwareLayer(false);
 
-        // Shrink the urlbar entry back to its original size
-
+        // Slide the toolbar back to its original size.
         if (urlBarTranslatingEdge != null) {
             contentAnimator.attach(urlBarTranslatingEdge,
                                    PropertyAnimator.Property.TRANSLATION_X,
                                    0);
         }
 
         contentAnimator.attach(mTabs,
                                PropertyAnimator.Property.TRANSLATION_X,
@@ -1178,18 +1193,16 @@ public class BrowserToolbar extends Them
                 // Trigger animation to update the tabs counter once the
                 // tabs button is back on screen.
                 updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
             }
         });
 
         mAnimatingEntry = true;
         contentAnimator.start();
-
-        return url;
     }
 
     public void setButtonEnabled(ImageButton button, boolean enabled) {
         final Drawable drawable = button.getDrawable();
         if (drawable != null) {
             // This alpha value has to be in sync with the one used
             // in updateChildrenForEditing().
             drawable.setAlpha(enabled ? 255 : 61);