Enable smooth scrolling again.

captchafix
Florens Douwes 11 years ago
parent 8b8d22b2e6
commit 0c89ee92db
  1. 26
      Clover/src/org/floens/chan/ui/ScrollerRunnable.java

@ -22,6 +22,8 @@ import android.view.ViewConfiguration;
import android.widget.ListView; import android.widget.ListView;
public class ScrollerRunnable implements Runnable { public class ScrollerRunnable implements Runnable {
private static final int SCROLL_DURATION = 300;
private static final int MOVE_DOWN_POS = 1; private static final int MOVE_DOWN_POS = 1;
private static final int MOVE_UP_POS = 2; private static final int MOVE_UP_POS = 2;
@ -30,6 +32,7 @@ public class ScrollerRunnable implements Runnable {
private int mMode; private int mMode;
private int mTargetPos; private int mTargetPos;
private int mLastSeenPos; private int mLastSeenPos;
private int mScrollDuration;
private final int mExtraScroll; private final int mExtraScroll;
public ScrollerRunnable(ListView listView) { public ScrollerRunnable(ListView listView) {
@ -43,18 +46,23 @@ public class ScrollerRunnable implements Runnable {
final int firstPos = mList.getFirstVisiblePosition(); final int firstPos = mList.getFirstVisiblePosition();
final int lastPos = firstPos + mList.getChildCount() - 1; final int lastPos = firstPos + mList.getChildCount() - 1;
// int viewTravelCount = 0; int viewTravelCount = 0;
if (position <= firstPos) { if (position <= firstPos) {
// viewTravelCount = firstPos - position + 1; viewTravelCount = firstPos - position + 1;
mMode = MOVE_UP_POS; mMode = MOVE_UP_POS;
} else if (position >= lastPos) { } else if (position >= lastPos) {
// viewTravelCount = position - lastPos + 1; viewTravelCount = position - lastPos + 1;
mMode = MOVE_DOWN_POS; mMode = MOVE_DOWN_POS;
} else { } else {
// Already on screen, nothing to do // Already on screen, nothing to do
return; return;
} }
if (viewTravelCount > 0) {
mScrollDuration = SCROLL_DURATION / viewTravelCount;
} else {
mScrollDuration = SCROLL_DURATION;
}
mTargetPos = position; mTargetPos = position;
mLastSeenPos = ListView.INVALID_POSITION; mLastSeenPos = ListView.INVALID_POSITION;
@ -81,8 +89,8 @@ public class ScrollerRunnable implements Runnable {
if (lastPos == mLastSeenPos) { if (lastPos == mLastSeenPos) {
// No new views, let things keep going. // No new views, let things keep going.
// mList.post(this); mList.post(this);
// return; return;
} }
final View lastView = mList.getChildAt(lastViewIndex); final View lastView = mList.getChildAt(lastViewIndex);
@ -91,7 +99,7 @@ public class ScrollerRunnable implements Runnable {
final int lastViewPixelsShowing = listHeight - lastViewTop; final int lastViewPixelsShowing = listHeight - lastViewTop;
final int extraScroll = lastPos < mList.getCount() - 1 ? mExtraScroll : mList.getPaddingBottom(); final int extraScroll = lastPos < mList.getCount() - 1 ? mExtraScroll : mList.getPaddingBottom();
mList.smoothScrollBy(lastViewHeight - lastViewPixelsShowing + extraScroll, 0); mList.smoothScrollBy(lastViewHeight - lastViewPixelsShowing + extraScroll, mScrollDuration);
mLastSeenPos = lastPos; mLastSeenPos = lastPos;
if (lastPos < mTargetPos) { if (lastPos < mTargetPos) {
@ -103,8 +111,8 @@ public class ScrollerRunnable implements Runnable {
case MOVE_UP_POS: { case MOVE_UP_POS: {
if (firstPos == mLastSeenPos) { if (firstPos == mLastSeenPos) {
// No new views, let things keep going. // No new views, let things keep going.
// mList.post(this); mList.post(this);
// return; return;
} }
final View firstView = mList.getChildAt(0); final View firstView = mList.getChildAt(0);
@ -114,7 +122,7 @@ public class ScrollerRunnable implements Runnable {
final int firstViewTop = firstView.getTop(); final int firstViewTop = firstView.getTop();
final int extraScroll = firstPos > 0 ? mExtraScroll : mList.getPaddingTop(); final int extraScroll = firstPos > 0 ? mExtraScroll : mList.getPaddingTop();
mList.smoothScrollBy(firstViewTop - extraScroll, 0); mList.smoothScrollBy(firstViewTop - extraScroll, mScrollDuration);
mLastSeenPos = firstPos; mLastSeenPos = firstPos;

Loading…
Cancel
Save