Bug 889621 - Cross-fade URL bar content when entering editing mode (r=sriram)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 26 Jul 2013 12:46:29 +0100
changeset 143452 423ebd7660dc3b858f9ff9bf4a7221fc18155f64
parent 143451 d910238981baa6e447ad07efdde7493c0ebfedba
child 143453 7136d73be7a32490a76238c3bde5d121d4f1be2e
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs889621
milestone25.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 889621 - Cross-fade URL bar content when entering editing mode (r=sriram)
mobile/android/base/BrowserToolbar.java
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -1184,25 +1184,78 @@ public class BrowserToolbar extends Geck
 
     private void showSoftInput() {
         InputMethodManager imm =
                (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.showSoftInput(mUrlEditText, InputMethodManager.SHOW_IMPLICIT);
     }
 
     private void showUrlEditContainer() {
-        mUrlDisplayContainer.setVisibility(View.GONE);
-        mUrlEditContainer.setVisibility(View.VISIBLE);
-        mUrlEditText.requestFocus();
-        showSoftInput();
+        setUrlEditContainerVisibility(true, null);
+    }
+
+    private void showUrlEditContainer(PropertyAnimator animator) {
+        setUrlEditContainerVisibility(true, animator);
     }
 
     private void hideUrlEditContainer() {
-        mUrlDisplayContainer.setVisibility(View.VISIBLE);
-        mUrlEditContainer.setVisibility(View.GONE);
+        setUrlEditContainerVisibility(false, null);
+    }
+
+    private void hideUrlEditContainer(PropertyAnimator animator) {
+        setUrlEditContainerVisibility(false, animator);
+    }
+
+    private void setUrlEditContainerVisibility(final boolean visible, PropertyAnimator animator) {
+        final View viewToShow = (visible ? mUrlEditContainer : mUrlDisplayContainer);
+        final View viewToHide = (visible ? mUrlDisplayContainer : mUrlEditContainer);
+
+        if (animator == null) {
+            viewToHide.setVisibility(View.GONE);
+            viewToShow.setVisibility(View.VISIBLE);
+
+            if (visible) {
+                mUrlEditText.requestFocus();
+                showSoftInput();
+            }
+
+            return;
+        }
+
+        ViewHelper.setAlpha(viewToShow, 0.0f);
+        animator.attach(viewToShow,
+                        PropertyAnimator.Property.ALPHA,
+                        1.0f);
+
+        animator.attach(viewToHide,
+                        PropertyAnimator.Property.ALPHA,
+                        0.0f);
+
+        animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
+            @Override
+            public void onPropertyAnimationStart() {
+                viewToShow.setVisibility(View.VISIBLE);
+
+                if (visible) {
+                    ViewHelper.setAlpha(mGo, 0.0f);
+                    mUrlEditText.requestFocus();
+                }
+            }
+
+            @Override
+            public void onPropertyAnimationEnd() {
+                ViewHelper.setAlpha(viewToHide, 1.0f);
+                viewToHide.setVisibility(View.GONE);
+
+                if (visible) {
+                    ViewHelper.setAlpha(mGo, 1.0f);
+                    showSoftInput();
+                }
+            }
+        });
     }
 
     public boolean isEditing() {
         return isSelected();
     }
 
     public void startEditing(String url, PropertyAnimator animator) {
         if (isEditing()) {
@@ -1254,24 +1307,25 @@ public class BrowserToolbar extends Geck
                             PropertyAnimator.Property.TRANSLATION_X,
                             curveTranslation);
 
             animator.attach(mMenuIcon,
                             PropertyAnimator.Property.TRANSLATION_X,
                             curveTranslation);
         }
 
+        showUrlEditContainer(animator);
+
         animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
             @Override
             public void onPropertyAnimationStart() {
             }
 
             @Override
             public void onPropertyAnimationEnd() {
-                showUrlEditContainer();
                 mAnimatingEntry = false;
             }
         });
 
         mAnimatingEntry = true;
     }
 
     /**
@@ -1297,20 +1351,19 @@ public class BrowserToolbar extends Geck
     }
 
     private String stopEditing() {
         final String url = mUrlEditText.getText().toString();
         if (!isEditing()) {
             return url;
         }
 
-        hideUrlEditContainer();
-
         if (HardwareUtils.isTablet()) {
             setSelected(false);
+            hideUrlEditContainer();
             updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
             return url;
         }
 
         final PropertyAnimator contentAnimator = new PropertyAnimator(250);
         contentAnimator.setUseHardwareLayer(false);
 
         // Shrink the urlbar entry back to its original size
@@ -1336,16 +1389,18 @@ public class BrowserToolbar extends Geck
                                    PropertyAnimator.Property.TRANSLATION_X,
                                    0);
 
             contentAnimator.attach(mMenuIcon,
                                    PropertyAnimator.Property.TRANSLATION_X,
                                    0);
         }
 
+        hideUrlEditContainer(contentAnimator);
+
         contentAnimator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
             @Override
             public void onPropertyAnimationStart() {
             }
 
             @Override
             public void onPropertyAnimationEnd() {
                 // Turn off selected state on the entry