Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Handler;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -36,7 +36,10 @@ public static interface OnPositionChangedListener {
private Animation mInAnimation = null;
private Animation mOutAnimation = null;

private final Handler mHandler = new Handler();
//edit: removed handler. We don't need an extra Handler, we can use View.postDelayed() directly

//keep last position of the panel, so we won't need to calculate it again in onOverScrolled()
private int lastLeft, lastTop, lastRight, lastBottom;

private final Runnable mScrollBarPanelFadeRunnable = new Runnable() {

Expand Down Expand Up @@ -115,6 +118,15 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}

@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
if (null != mScrollBarPanel) {
mScrollBarPanel.layout(lastLeft, lastTop + scrollY, lastRight, lastBottom + scrollY);
}
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}


@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (null != mPositionChangedListener && null != mScrollBarPanel) {
Expand Down Expand Up @@ -170,8 +182,18 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
*/
mScrollBarPanelPosition = thumbOffset - mScrollBarPanel.getMeasuredHeight() / 2;
final int x = getMeasuredWidth() - mScrollBarPanel.getMeasuredWidth() - getVerticalScrollbarWidth();
mScrollBarPanel.layout(x, mScrollBarPanelPosition, x + mScrollBarPanel.getMeasuredWidth(),
mScrollBarPanelPosition + mScrollBarPanel.getMeasuredHeight());


//make sure panel always stays visible
mScrollBarPanelPosition = Math.max(1, mScrollBarPanelPosition);
mScrollBarPanelPosition = Math.min(getMeasuredHeight() - mScrollBarPanel.getMeasuredHeight() - 1, mScrollBarPanelPosition);

lastLeft = x;
lastTop = mScrollBarPanelPosition;
lastRight = x + mScrollBarPanel.getMeasuredWidth();
lastBottom = mScrollBarPanelPosition + mScrollBarPanel.getMeasuredHeight();

mScrollBarPanel.layout(lastLeft, lastTop, lastRight, lastBottom);
}
}

Expand Down Expand Up @@ -215,8 +237,9 @@ protected boolean awakenScrollBars(int startDelay, boolean invalidate) {
}
}

mHandler.removeCallbacks(mScrollBarPanelFadeRunnable);
mHandler.postAtTime(mScrollBarPanelFadeRunnable, AnimationUtils.currentAnimationTimeMillis() + startDelay);
//Handler is not needed
this.removeCallbacks(mScrollBarPanelFadeRunnable);
this.postDelayed(mScrollBarPanelFadeRunnable, AnimationUtils.currentAnimationTimeMillis() + startDelay - SystemClock.uptimeMillis());
}

return isAnimationPlayed;
Expand Down Expand Up @@ -257,6 +280,6 @@ protected void dispatchDraw(Canvas canvas) {
public void onDetachedFromWindow() {
super.onDetachedFromWindow();

mHandler.removeCallbacks(mScrollBarPanelFadeRunnable);
this.removeCallbacks(mScrollBarPanelFadeRunnable);
}
}