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.
This commit is contained in:
Chris Lord 2013-03-12 17:38:24 +00:00
parent c53cfadb7f
commit aac83ddc5a
2 changed files with 25 additions and 3 deletions

View File

@ -279,9 +279,10 @@ abstract public class BrowserApp extends GeckoApp
} 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);
}
}

View File

@ -532,6 +532,27 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
}
}
/**
* 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) {