From b1777447d9b9700b48f8060f8b318f2363c43e8d Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 16 Jun 2015 13:35:04 -0700 Subject: Refactoring fast scroller. - Fixing issue with fast scroller not fitting name width. - Refactoring fast scrolling/scroll bar code out of base recycler view - Adding animations to fast scroller to match design - Smooth scrolling when jumping between app rows - Fixing issue with fast scroller jumping when you first pick it up - Fixing issue with wrong background paddings being used Bug: 21874346 Bug: 22031923 Change-Id: I9f011b1f375751f437604b900e95a2942d3f4601 --- .../launcher3/widget/WidgetsRecyclerView.java | 65 ++++++++++------------ 1 file changed, 30 insertions(+), 35 deletions(-) (limited to 'src/com/android/launcher3/widget/WidgetsRecyclerView.java') diff --git a/src/com/android/launcher3/widget/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/WidgetsRecyclerView.java index fa7e2f0a2..3101f3327 100644 --- a/src/com/android/launcher3/widget/WidgetsRecyclerView.java +++ b/src/com/android/launcher3/widget/WidgetsRecyclerView.java @@ -17,14 +17,14 @@ package com.android.launcher3.widget; import android.content.Context; -import android.graphics.Rect; +import android.graphics.Color; import android.support.v7.widget.LinearLayoutManager; import android.util.AttributeSet; import android.view.View; import com.android.launcher3.BaseRecyclerView; -import com.android.launcher3.Utilities; -import com.android.launcher3.model.WidgetsModel; +import com.android.launcher3.R; import com.android.launcher3.model.PackageItemInfo; +import com.android.launcher3.model.WidgetsModel; /** * The widgets recycler view. @@ -33,6 +33,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView { private static final String TAG = "WidgetsRecyclerView"; private WidgetsModel mWidgets; + private ScrollPositionState mScrollPosState = new ScrollPositionState(); public WidgetsRecyclerView(Context context) { this(context, null); @@ -58,6 +59,14 @@ public class WidgetsRecyclerView extends BaseRecyclerView { addOnItemTouchListener(this); } + public int getFastScrollerTrackColor(int defaultTrackColor) { + return Color.WHITE; + } + + public int getFastScrollerThumbInactiveColor(int defaultInactiveThumbColor) { + return getResources().getColor(R.color.widgets_view_fastscroll_thumb_inactive_color); + } + /** * Sets the widget model in this view, used to determine the fast scroll position. */ @@ -70,15 +79,21 @@ public class WidgetsRecyclerView extends BaseRecyclerView { */ @Override public String scrollToPositionAtProgress(float touchFraction) { - float pos = mWidgets.getPackageSize() * touchFraction; + int rowCount = mWidgets.getPackageSize(); + if (rowCount == 0) { + return ""; + } - int posInt = (int) pos; + // Stop the scroller if it is scrolling + stopScroll(); + + getCurScrollState(mScrollPosState); + float pos = rowCount * touchFraction; + int availableScrollHeight = getAvailableScrollHeight(rowCount, mScrollPosState.rowHeight, 0); LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager()); - getCurScrollState(scrollPosState); - layoutManager.scrollToPositionWithOffset((int) pos, - (int) (scrollPosState.rowHeight * ((float) posInt - pos))); + layoutManager.scrollToPositionWithOffset(0, (int) -(availableScrollHeight * touchFraction)); - posInt = (int) ((touchFraction == 1)? pos -1 : pos); + int posInt = (int) ((touchFraction == 1)? pos -1 : pos); PackageItemInfo p = mWidgets.getPackageItemInfo(posInt); return p.titleSectionName; } @@ -87,43 +102,23 @@ public class WidgetsRecyclerView extends BaseRecyclerView { * Updates the bounds for the scrollbar. */ @Override - public void updateVerticalScrollbarBounds() { + public void onUpdateScrollbar() { int rowCount = mWidgets.getPackageSize(); - verticalScrollbarBounds.setEmpty(); // Skip early if, there are no items. if (rowCount == 0) { + mScrollbar.setScrollbarThumbOffset(-1, -1); return; } // Skip early if, there no child laid out in the container. - getCurScrollState(scrollPosState); - if (scrollPosState.rowIndex < 0) { + getCurScrollState(mScrollPosState); + if (mScrollPosState.rowIndex < 0) { + mScrollbar.setScrollbarThumbOffset(-1, -1); return; } - int actualHeight = getHeight() - getPaddingTop() - getPaddingBottom(); - int totalScrollHeight = rowCount * scrollPosState.rowHeight; - // Skip early if the height of all the rows are actually less than the container height. - if (totalScrollHeight < actualHeight) { - verticalScrollbarBounds.setEmpty(); - return; - } - - int scrollbarHeight = (int) (actualHeight / ((float) totalScrollHeight / actualHeight)); - int availableY = totalScrollHeight - actualHeight; - int availableScrollY = actualHeight - scrollbarHeight; - int y = (scrollPosState.rowIndex * scrollPosState.rowHeight) - - scrollPosState.rowTopOffset; - y = getPaddingTop() + - (int) (((float) (getPaddingTop() + y) / availableY) * availableScrollY); - - // Calculate the position and size of the scroll bar. - int x = getWidth() - getScrollbarWidth() - mBackgroundPadding.right; - if (Utilities.isRtl(getResources())) { - x = mBackgroundPadding.left; - } - verticalScrollbarBounds.set(x, y, x + getScrollbarWidth(), y + scrollbarHeight); + synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, rowCount, 0); } /** -- cgit v1.2.3