OSDN Git Service

Eleven: Fix perf for rearranging a very long list
authorlinus_lee <llee@cyngn.com>
Fri, 31 Oct 2014 20:16:37 +0000 (13:16 -0700)
committerlinus_lee <llee@cyngn.com>
Thu, 20 Nov 2014 20:51:36 +0000 (12:51 -0800)
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

index 86a2ddc..1e7acc1 100644 (file)
@@ -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;