summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/BaseRecyclerView.java
diff options
context:
space:
mode:
authorWinson <winsonc@google.com>2015-08-21 11:16:27 -0700
committerWinson <winsonc@google.com>2015-09-28 17:32:19 -0700
commitc088049113c261331b5685e64050d14a31cd72df (patch)
tree404a01d25361b6df9b754ec29ff3e4d053fe6bb8 /src/com/android/launcher3/BaseRecyclerView.java
parent5189454083640c81bf3a171422b3ef114f150a77 (diff)
downloadandroid_packages_apps_Trebuchet-c088049113c261331b5685e64050d14a31cd72df.tar.gz
android_packages_apps_Trebuchet-c088049113c261331b5685e64050d14a31cd72df.tar.bz2
android_packages_apps_Trebuchet-c088049113c261331b5685e64050d14a31cd72df.zip
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
Diffstat (limited to 'src/com/android/launcher3/BaseRecyclerView.java')
-rw-r--r--src/com/android/launcher3/BaseRecyclerView.java67
1 files changed, 47 insertions, 20 deletions
diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java
index 9d713e338..f8ef1e156 100644
--- a/src/com/android/launcher3/BaseRecyclerView.java
+++ b/src/com/android/launcher3/BaseRecyclerView.java
@@ -52,8 +52,8 @@ public abstract class BaseRecyclerView extends RecyclerView
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 @@ public abstract class BaseRecyclerView extends RecyclerView
}
/**
+ * 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 @@ public abstract class BaseRecyclerView extends RecyclerView
* 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 @@ public abstract class BaseRecyclerView extends RecyclerView
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 @@ public abstract class BaseRecyclerView extends RecyclerView
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 @@ public abstract class BaseRecyclerView extends RecyclerView
// 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 @@ public abstract class BaseRecyclerView extends RecyclerView
}
/**
- * 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 @@ public abstract class BaseRecyclerView extends RecyclerView
/**
* 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;
+ }
/**
- * Updates the bounds for the scrollbar.
+ * 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.
*/
- public abstract void onUpdateScrollbar(int dy);
+ protected abstract String scrollToPositionAtProgress(float touchFraction);
/**
+ * Updates the bounds for the scrollbar.
* <p>Override in each subclass of this base class.
*/
- public void onFastScrollCompleted() {}
+ protected abstract void onUpdateScrollbar(int dy);
/**
- * Returns information about the item that the recycler view is currently scrolled to.
+ * <p>Override in each subclass of this base class.
*/
- protected abstract void getCurScrollState(ScrollPositionState stateOut);
+ protected void onFastScrollCompleted() {}
} \ No newline at end of file