mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 03:08:19 +00:00
Simplifying fast scroller logic
> Using a separate view for drawing the popup. This allows us to use elevation property instead of drawing the shadow as bitmap. > During the thumb animation, invalidating the full track width, instead of invalidating the track and thumb separately. > The thumb path is calculated at 0,0 and drawn using canvas.translate(). This avoids recalculating the path on every scroll. Change-Id: I48741e5b4432df0d939016db284d7aaf52cc2aa6
This commit is contained in:
@@ -22,6 +22,8 @@ import android.graphics.Rect;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.launcher3.util.Thunk;
|
||||
|
||||
|
||||
@@ -41,7 +43,7 @@ public abstract class BaseRecyclerView extends RecyclerView
|
||||
@Thunk int mDy = 0;
|
||||
private float mDeltaThreshold;
|
||||
|
||||
protected BaseRecyclerViewFastScrollBar mScrollbar;
|
||||
protected final BaseRecyclerViewFastScrollBar mScrollbar;
|
||||
|
||||
private int mDownX;
|
||||
private int mDownY;
|
||||
@@ -92,6 +94,12 @@ public abstract class BaseRecyclerView extends RecyclerView
|
||||
addOnItemTouchListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mScrollbar.setPopupView(((ViewGroup) getParent()).findViewById(R.id.fast_scroller_popup));
|
||||
}
|
||||
|
||||
/**
|
||||
* We intercept the touch handling only to support fast scrolling when initiated from the
|
||||
* scroll bar. Otherwise, we fall back to the default RecyclerView touch handling.
|
||||
@@ -235,7 +243,7 @@ public abstract class BaseRecyclerView extends RecyclerView
|
||||
// Only show the scrollbar if there is height to be scrolled
|
||||
int availableScrollBarHeight = getAvailableScrollBarHeight();
|
||||
if (availableScrollHeight <= 0) {
|
||||
mScrollbar.setThumbOffset(-1, -1);
|
||||
mScrollbar.setThumbOffsetY(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -246,18 +254,7 @@ public abstract class BaseRecyclerView extends RecyclerView
|
||||
(int) (((float) scrollY / availableScrollHeight) * availableScrollBarHeight);
|
||||
|
||||
// Calculate the position and size of the scroll bar
|
||||
mScrollbar.setThumbOffset(getScrollBarX(), scrollBarY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x position for the scrollbar thumb
|
||||
*/
|
||||
protected int getScrollBarX() {
|
||||
if (Utilities.isRtl(getResources())) {
|
||||
return mBackgroundPadding.left;
|
||||
} else {
|
||||
return getWidth() - mBackgroundPadding.right - mScrollbar.getThumbWidth();
|
||||
}
|
||||
mScrollbar.setThumbOffsetY(scrollBarY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user