Fixing fast scroller invalidation on pre-L devices.
Change-Id: Ie776eff314db4b392ede70be1a332b0d80e0647c
diff --git a/src/com/android/launcher3/AppsContainerRecyclerView.java b/src/com/android/launcher3/AppsContainerRecyclerView.java
index 95da48f..16efb70 100644
--- a/src/com/android/launcher3/AppsContainerRecyclerView.java
+++ b/src/com/android/launcher3/AppsContainerRecyclerView.java
@@ -61,6 +61,8 @@
private Drawable mScrollbar;
private Drawable mFastScrollerBg;
+ private Rect mTmpFastScrollerInvalidateRect = new Rect();
+ private Rect mFastScrollerBounds = new Rect();
private Rect mVerticalScrollbarBounds = new Rect();
private boolean mDraggingFastScroller;
private String mFastScrollSectionName;
@@ -162,7 +164,7 @@
*/
public void setFastScrollerAlpha(float alpha) {
mFastScrollAlpha = alpha;
- invalidateFastScroller();
+ invalidateFastScroller(mFastScrollerBounds);
}
/**
@@ -252,7 +254,13 @@
float boundedY = (float) Math.max(top, Math.min(bottom, y));
mFastScrollSectionName = scrollToPositionAtProgress((boundedY - top) /
(bottom - top));
- invalidateFastScroller();
+
+ // Combine the old and new fast scroller bounds to create the full invalidate
+ // rect
+ mTmpFastScrollerInvalidateRect.set(mFastScrollerBounds);
+ updateFastScrollerBounds();
+ mTmpFastScrollerInvalidateRect.union(mFastScrollerBounds);
+ invalidateFastScroller(mTmpFastScrollerInvalidateRect);
}
break;
case MotionEvent.ACTION_UP:
@@ -288,24 +296,9 @@
*/
private void drawFastScrollerPopup(Canvas canvas) {
if (mFastScrollAlpha > 0f && !mFastScrollSectionName.isEmpty()) {
- int x;
- int y;
- boolean isRtl = Utilities.isRtl(getResources());
-
- // Calculate the position for the fast scroller popup
- Rect bgBounds = mFastScrollerBg.getBounds();
- if (isRtl) {
- x = mBackgroundPadding.left + getScrollBarSize();
- } else {
- x = getWidth() - getPaddingRight() - getScrollBarSize() - bgBounds.width();
- }
- y = mLastY - (int) (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * bgBounds.height());
- y = Math.max(getPaddingTop(), Math.min(y, getHeight() - getPaddingBottom() -
- bgBounds.height()));
-
// Draw the fast scroller popup
int restoreCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
- canvas.translate(x, y);
+ canvas.translate(mFastScrollerBounds.left, mFastScrollerBounds.top);
mFastScrollerBg.setAlpha((int) (mFastScrollAlpha * 255));
mFastScrollerBg.draw(canvas);
mFastScrollTextPaint.setAlpha((int) (mFastScrollAlpha * 255));
@@ -313,8 +306,9 @@
mFastScrollSectionName.length(), mFastScrollTextBounds);
float textWidth = mFastScrollTextPaint.measureText(mFastScrollSectionName);
canvas.drawText(mFastScrollSectionName,
- (bgBounds.width() - textWidth) / 2,
- bgBounds.height() - (bgBounds.height() - mFastScrollTextBounds.height()) / 2,
+ (mFastScrollerBounds.width() - textWidth) / 2,
+ mFastScrollerBounds.height() -
+ (mFastScrollerBounds.height() - mFastScrollTextBounds.height()) / 2,
mFastScrollTextPaint);
canvas.restoreToCount(restoreCount);
}
@@ -337,9 +331,8 @@
/**
* Invalidates the fast scroller popup.
*/
- private void invalidateFastScroller() {
- invalidate(getWidth() - mBackgroundPadding.right - getScrollBarSize() -
- mFastScrollerBg.getIntrinsicWidth(), 0, getWidth(), getHeight());
+ private void invalidateFastScroller(Rect bounds) {
+ invalidate(bounds.left, bounds.top, bounds.right, bounds.bottom);
}
/**
@@ -394,7 +387,7 @@
}
/**
- * Returns the bounds for the scrollbar.
+ * Updates the bounds for the scrollbar.
*/
private void updateVerticalScrollbarBounds() {
List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
@@ -442,6 +435,31 @@
}
/**
+ * Updates the bounds for the fast scroller.
+ */
+ private void updateFastScrollerBounds() {
+ if (mFastScrollAlpha > 0f && !mFastScrollSectionName.isEmpty()) {
+ int x;
+ int y;
+ boolean isRtl = Utilities.isRtl(getResources());
+
+ // Calculate the position for the fast scroller popup
+ Rect bgBounds = mFastScrollerBg.getBounds();
+ if (isRtl) {
+ x = mBackgroundPadding.left + getScrollBarSize();
+ } else {
+ x = getWidth() - getPaddingRight() - getScrollBarSize() - bgBounds.width();
+ }
+ y = mLastY - (int) (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * bgBounds.height());
+ y = Math.max(getPaddingTop(), Math.min(y, getHeight() - getPaddingBottom() -
+ bgBounds.height()));
+ mFastScrollerBounds.set(x, y, x + bgBounds.width(), y + bgBounds.height());
+ } else {
+ mFastScrollerBounds.setEmpty();
+ }
+ }
+
+ /**
* Returns the row index for a app index in the list.
*/
private int findRowForAppIndex(int index) {