diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java index 8bd5eba000..401b699f14 100644 --- a/src/com/android/launcher3/BaseRecyclerView.java +++ b/src/com/android/launcher3/BaseRecyclerView.java @@ -246,13 +246,18 @@ public abstract class BaseRecyclerView extends RecyclerView (int) (((float) scrollY / availableScrollHeight) * availableScrollBarHeight); // Calculate the position and size of the scroll bar - int scrollBarX; + mScrollbar.setThumbOffset(getScrollBarX(), scrollBarY); + } + + /** + * @return the x position for the scrollbar thumb + */ + protected int getScrollBarX() { if (Utilities.isRtl(getResources())) { - scrollBarX = mBackgroundPadding.left; + return mBackgroundPadding.left; } else { - scrollBarX = getWidth() - mBackgroundPadding.right - mScrollbar.getThumbWidth(); + return getWidth() - mBackgroundPadding.right - mScrollbar.getThumbWidth(); } - mScrollbar.setThumbOffset(scrollBarX, scrollBarY); } /** diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java index 4ab0ea34b4..89f7286d11 100644 --- a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java +++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java @@ -156,10 +156,6 @@ public class BaseRecyclerViewFastScrollBar { return mThumbMaxWidth; } - public float getLastTouchY() { - return mLastTouchY; - } - public boolean isDraggingThumb() { return mIsDragging; } @@ -210,6 +206,7 @@ public class BaseRecyclerViewFastScrollBar { mPopup.animateVisibility(!sectionName.isEmpty()); mRv.invalidate(mPopup.updateFastScrollerBounds(lastY)); mLastTouchY = boundedY; + setThumbOffset(mRv.getScrollBarX(), (int) mLastTouchY); } break; case MotionEvent.ACTION_UP: diff --git a/src/com/android/launcher3/allapps/AllAppsFastScrollHelper.java b/src/com/android/launcher3/allapps/AllAppsFastScrollHelper.java index 6d9094f783..76934af7dd 100644 --- a/src/com/android/launcher3/allapps/AllAppsFastScrollHelper.java +++ b/src/com/android/launcher3/allapps/AllAppsFastScrollHelper.java @@ -23,6 +23,7 @@ import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.util.Thunk; import java.util.HashSet; +import java.util.List; public class AllAppsFastScrollHelper implements AllAppsGridAdapter.BindViewCallback { @@ -142,13 +143,22 @@ public class AllAppsFastScrollHelper implements AllAppsGridAdapter.BindViewCallb } // Calculate the full animation from the current scroll position to the final scroll - // position, and then run the animation for the duration. + // position, and then run the animation for the duration. If we are scrolling to the + // first fast scroll section, then just scroll to the top of the list itself. + List fastScrollSections = + mApps.getFastScrollerSections(); int newPosition = info.fastScrollToItem.position; - int newScrollY = Math.min(availableScrollHeight, mRv.getCurrentScrollY(newPosition, 0)); + int newScrollY = fastScrollSections.size() > 0 && fastScrollSections.get(0) == info + ? 0 + : Math.min(availableScrollHeight, mRv.getCurrentScrollY(newPosition, 0)); int numFrames = mFastScrollFrames.length; + int deltaY = newScrollY - scrollY; + float ySign = Math.signum(deltaY); + int step = (int) (ySign * Math.ceil((float) Math.abs(deltaY) / numFrames)); for (int i = 0; i < numFrames; i++) { // TODO(winsonc): We can interpolate this as well. - mFastScrollFrames[i] = (newScrollY - scrollY) / numFrames; + mFastScrollFrames[i] = (int) (ySign * Math.min(Math.abs(step), Math.abs(deltaY))); + deltaY -= step; } mFastScrollFrameIndex = 0; mRv.postOnAnimation(mSmoothSnapNextFrameRunnable); diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index 2680197727..0f0c333f4a 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -377,10 +377,6 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter 0f) {