Highlighting sectioned apps on fast-scroll.
- This CL fixes an old assumption we had about the height
of rows in AllApps, and ensures that we account for the
difference in height between the predictive icons and the
normal icons.
- In addition, we refactor FastBitmapDrawable to have multiple
states, which it manages in drawing itself, including the
press state and fast scroll focus states. And we also refactor
some of the fast scroll logic in the all apps recycler view
out to its own class.
Change-Id: I1988159b2767df733bbbfc7dc601859cde6c9943
diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java
index 9d713e3..f8ef1e1 100644
--- a/src/com/android/launcher3/BaseRecyclerView.java
+++ b/src/com/android/launcher3/BaseRecyclerView.java
@@ -52,8 +52,8 @@
public int rowIndex;
// The offset of the first visible row
public int rowTopOffset;
- // The height of a given row (they are currently all the same height)
- public int rowHeight;
+ // The adapter position of the first visible item
+ public int itemPos;
}
protected BaseRecyclerViewFastScrollBar mScrollbar;
@@ -187,15 +187,21 @@
}
/**
+ * Returns the visible height of the recycler view:
+ * VisibleHeight = View height - top padding - bottom padding
+ */
+ protected int getVisibleHeight() {
+ int visibleHeight = getHeight() - mBackgroundPadding.top - mBackgroundPadding.bottom;
+ return visibleHeight;
+ }
+
+ /**
* Returns the available scroll height:
* AvailableScrollHeight = Total height of the all items - last page height
- *
- * This assumes that all rows are the same height.
*/
- protected int getAvailableScrollHeight(int rowCount, int rowHeight) {
- int visibleHeight = getHeight() - mBackgroundPadding.top - mBackgroundPadding.bottom;
- int scrollHeight = getPaddingTop() + rowCount * rowHeight + getPaddingBottom();
- int availableScrollHeight = scrollHeight - visibleHeight;
+ protected int getAvailableScrollHeight(int rowCount) {
+ int totalHeight = getPaddingTop() + getTop(rowCount) + getPaddingBottom();
+ int availableScrollHeight = totalHeight - getVisibleHeight();
return availableScrollHeight;
}
@@ -204,8 +210,7 @@
* AvailableScrollBarHeight = Total height of the visible view - thumb height
*/
protected int getAvailableScrollBarHeight() {
- int visibleHeight = getHeight() - mBackgroundPadding.top - mBackgroundPadding.bottom;
- int availableScrollBarHeight = visibleHeight - mScrollbar.getThumbHeight();
+ int availableScrollBarHeight = getVisibleHeight() - mScrollbar.getThumbHeight();
return availableScrollBarHeight;
}
@@ -223,6 +228,13 @@
return defaultInactiveThumbColor;
}
+ /**
+ * Returns the scrollbar for this recycler view.
+ */
+ public BaseRecyclerViewFastScrollBar getScrollBar() {
+ return mScrollbar;
+ }
+
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
@@ -243,7 +255,7 @@
int rowCount) {
// Only show the scrollbar if there is height to be scrolled
int availableScrollBarHeight = getAvailableScrollBarHeight();
- int availableScrollHeight = getAvailableScrollHeight(rowCount, scrollPosState.rowHeight);
+ int availableScrollHeight = getAvailableScrollHeight(rowCount);
if (availableScrollHeight <= 0) {
mScrollbar.setThumbOffset(-1, -1);
return;
@@ -252,8 +264,7 @@
// Calculate the current scroll position, the scrollY of the recycler view accounts for the
// view padding, while the scrollBarY is drawn right up to the background padding (ignoring
// padding)
- int scrollY = getPaddingTop() +
- (scrollPosState.rowIndex * scrollPosState.rowHeight) - scrollPosState.rowTopOffset;
+ int scrollY = getScrollTop(scrollPosState);
int scrollBarY = mBackgroundPadding.top +
(int) (((float) scrollY / availableScrollHeight) * availableScrollBarHeight);
@@ -268,7 +279,7 @@
}
/**
- * Returns whether fast scrolling is supported in the current state.
+ * @return whether fast scrolling is supported in the current state.
*/
protected boolean supportsFastScrolling() {
return true;
@@ -277,22 +288,38 @@
/**
* Maps the touch (from 0..1) to the adapter position that should be visible.
* <p>Override in each subclass of this base class.
+ *
+ * @return the scroll top of this recycler view.
*/
- public abstract String scrollToPositionAtProgress(float touchFraction);
+ protected int getScrollTop(ScrollPositionState scrollPosState) {
+ return getPaddingTop() + getTop(scrollPosState.rowIndex) -
+ scrollPosState.rowTopOffset;
+ }
+
+ /**
+ * Returns information about the item that the recycler view is currently scrolled to.
+ */
+ protected abstract void getCurScrollState(ScrollPositionState stateOut, int viewTypeMask);
+
+ /**
+ * Returns the top (or y position) of the row at the specified index.
+ */
+ protected abstract int getTop(int rowIndex);
+
+ /**
+ * Maps the touch (from 0..1) to the adapter position that should be visible.
+ * <p>Override in each subclass of this base class.
+ */
+ protected abstract String scrollToPositionAtProgress(float touchFraction);
/**
* Updates the bounds for the scrollbar.
* <p>Override in each subclass of this base class.
*/
- public abstract void onUpdateScrollbar(int dy);
+ protected abstract void onUpdateScrollbar(int dy);
/**
* <p>Override in each subclass of this base class.
*/
- public void onFastScrollCompleted() {}
-
- /**
- * Returns information about the item that the recycler view is currently scrolled to.
- */
- protected abstract void getCurScrollState(ScrollPositionState stateOut);
+ protected void onFastScrollCompleted() {}
}
\ No newline at end of file