Merge changes from topic "am-d3d9c24b-dbc9-40e6-b12a-d4f1ff034e1e" into ub-launcher3-master
* changes:
[automerger] Settling scrolls over clear-all button. am: a9283beebc
Settling scrolls over clear-all button.
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 8311ab9..87ee076 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1171,11 +1171,19 @@
mNextPage = getPageNearestToCenterOfScreen(unscaledScrollX);
int firstPageScroll = getScrollForPage(!mIsRtl ? 0 : getPageCount() - 1);
int lastPageScroll = getScrollForPage(!mIsRtl ? getPageCount() - 1 : 0);
- if (mSettleOnPageInFreeScroll && unscaledScrollX > firstPageScroll
- && unscaledScrollX < lastPageScroll) {
- // Make sure we land directly on a page. If flinging past one of the ends,
- // don't change the velocity as it will get stopped at the end anyway.
- mScroller.setFinalX((int) (getScrollForPage(mNextPage) * getScaleX()));
+ if (mSettleOnPageInFreeScroll && unscaledScrollX > 0
+ && unscaledScrollX < mMaxScrollX) {
+ // If scrolling ends in the half of the added space that is closer to the
+ // end, settle to the end. Otherwise snap to the nearest page.
+ // If flinging past one of the ends, don't change the velocity as it will
+ // get stopped at the end anyway.
+ final int finalX = unscaledScrollX < firstPageScroll / 2 ?
+ 0 :
+ unscaledScrollX > (lastPageScroll + mMaxScrollX) / 2 ?
+ mMaxScrollX :
+ getScrollForPage(mNextPage);
+
+ mScroller.setFinalX((int) (finalX * getScaleX()));
// Ensure the scroll/snap doesn't happen too fast;
int extraScrollDuration = OVERSCROLL_PAGE_SNAP_ANIMATION_DURATION
- mScroller.getDuration();