From 9dcf86bfdb01bca31a241f236f2b86dd582d3599 Mon Sep 17 00:00:00 2001 From: linus_lee Date: Fri, 31 Oct 2014 13:16:37 -0700 Subject: [PATCH] Eleven: Fix perf for rearranging a very long list The scroller would want to scroll through the list too quickly and the logic would execute too much logic during the layout phase - for now just cap the max scroll speed https://cyanogen.atlassian.net/browse/MUSIC-174 Change-Id: I61ac30feb43afe672a8a38637b97ee622e332268 --- src/com/cyngn/eleven/dragdrop/DragSortListView.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/com/cyngn/eleven/dragdrop/DragSortListView.java b/src/com/cyngn/eleven/dragdrop/DragSortListView.java index 86a2ddc..1e7acc1 100644 --- a/src/com/cyngn/eleven/dragdrop/DragSortListView.java +++ b/src/com/cyngn/eleven/dragdrop/DragSortListView.java @@ -1448,6 +1448,7 @@ public class DragSortListView extends ListView { } } mWidthMeasureSpec = widthMeasureSpec; + mDragScroller.setListHeight(getHeight()); } /** @@ -1888,6 +1889,8 @@ public class DragSortListView extends ListView { private boolean mScrolling = false; + private int mMaxScrollSpeed; + public boolean isScrolling() { return mScrolling; } @@ -1921,6 +1924,11 @@ public class DragSortListView extends ListView { } + public void setListHeight(final int height) { + // cap the max scroll speed per frame to be 1/5 of the list height + mMaxScrollSpeed = height / 5; + } + /** * {@inheritDoc} */ @@ -1976,6 +1984,9 @@ public class DragSortListView extends ListView { dy = Math.round(mScrollSpeed * dt); mScrollY += dy; + // cap the scroll speed + mScrollY = Math.max(Math.min(mScrollY, mMaxScrollSpeed), -mMaxScrollSpeed); + requestLayout(); mPrevTime += dt; -- 2.11.0