Bug 849246 - Follow the scroll velocity for the dynamic toolbar. r=kats
authorChris Lord <chrislord.net@gmail.com>
Tue, 12 Mar 2013 17:38:24 +0000
changeset 124521 1343cc74ff21b266e51e00b08c63096622be35be
parent 124520 a9e5d4379740e3b4a606f7a0e14277173c61aaaf
child 124522 dd3df1d9ac0032cbf8397d40a8aee0c110c56431
push id24427
push useremorley@mozilla.com
push dateWed, 13 Mar 2013 12:28:55 +0000
treeherdermozilla-central@072b936973fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs849246
milestone22.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 849246 - Follow the scroll velocity for the dynamic toolbar. r=kats In the rare situation that you cause a fast fling with a very short motion, it's possible that the toolbar won't hide/show as you expect. Fix this by saying that any swipe that's faster than the default animation speed dictates the direction in which the toolbar moves.
mobile/android/base/BrowserApp.java
mobile/android/base/BrowserToolbar.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -274,19 +274,20 @@ abstract public class BrowserApp extends
 
                 // Reset tracking when the toolbar is fully visible or hidden.
                 if (newToolbarY == 0 || newToolbarY == toolbarHeight) {
                     mLastTouchY = eventY;
                 }
             } else if (action == MotionEvent.ACTION_UP ||
                        action == MotionEvent.ACTION_CANCEL) {
                 // Animate the toolbar to fully on or off, depending on how much
-                // of it is hidden.
-                mBrowserToolbar.animateVisibility(
-                    toolbarView.getScrollY() > toolbarHeight / 2 ? false : true, 0);
+                // of it is hidden and the current swipe velocity.
+                mBrowserToolbar.animateVisibilityWithVelocityBias(
+                    toolbarView.getScrollY() > toolbarHeight / 2 ? false : true,
+                    mLayerView.getPanZoomController().getVelocityVector().y);
             }
         }
 
         // Update the last recorded y position.
         mLastTouchY = eventY;
 
         return super.onInterceptTouchEvent(view, event);
     }
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -527,16 +527,37 @@ public class BrowserToolbar implements V
                 }
             };
             mLayout.postDelayed(mDelayedVisibilityTask, delay);
         } else {
             startVisibilityAnimation();
         }
     }
 
+    /**
+     * Animate the visibility of the toolbar, but take into account the
+     * velocity of what's moving underneath the toolbar. If that velocity
+     * is greater than the default animation velocity, it will determine
+     * the direction of the toolbar animation. Velocity is specified in
+     * pixels per 1/60 seconds (a 60Hz frame).
+     */
+    public void animateVisibilityWithVelocityBias(boolean show, float velocity) {
+        // Work out the default animation velocity. This assumes a linear
+        // animation which is incorrect, but the animation is short enough that
+        // there's very little difference.
+        float defaultVelocity =
+            mLayout.getHeight() / ((VISIBILITY_ANIMATION_DURATION / 1000.0f) * 60);
+
+        if (Math.abs(velocity) > defaultVelocity) {
+            show = (velocity > 0) ? false : true;
+        }
+
+        animateVisibility(show, 0);
+    }
+
     public void cancelVisibilityAnimation() {
         mVisibility = ToolbarVisibility.INCONSISTENT;
         if (mDelayedVisibilityTask != null) {
             mLayout.removeCallbacks(mDelayedVisibilityTask);
             mDelayedVisibilityTask = null;
         }
         if (mVisibilityAnimator != null) {
             mVisibilityAnimator.stop(false);