From ea910a15c289dd4ff7704e922a5d4d9c9f6caa82 Mon Sep 17 00:00:00 2001 From: Kyle Horimoto Date: Tue, 25 Aug 2015 17:12:42 -0700 Subject: Fix band select UI issue. The issue was that scrolling past the top or bottom of the view caused the band select rectangle to grow in the wrong direction. This was caused by adjusting the origin of the band select rectangle based on the calculated number of pixels to scroll instead of the actual number of pixels scrolled. There can be a discrepancy when the calculated value is higher than the maximum that can be scrolled (when the view is already scroll almost to the top or bottom of the view). Bug: 23081362 Change-Id: I343cdec89260ab0571a792009d0c08585ed41199 --- .../android/documentsui/MultiSelectManager.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/MultiSelectManager.java b/packages/DocumentsUI/src/com/android/documentsui/MultiSelectManager.java index e53168d04b6f..3a367a1ffae6 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/MultiSelectManager.java +++ b/packages/DocumentsUI/src/com/android/documentsui/MultiSelectManager.java @@ -879,6 +879,7 @@ public final class MultiSelectManager { */ interface BandManagerHelper { void drawBand(Rect rect); + void addOnScrollListener(RecyclerView.OnScrollListener listener); int findEventPosition(MotionEvent e); int getHeight(); void hideBand(); @@ -1164,7 +1165,8 @@ public final class MultiSelectManager { * and {@link MultiSelectManager}. This class is responsible for rendering the band select * overlay and selecting overlaid items via MultiSelectManager. */ - public class BandSelectManager implements BandSelectModel.OnSelectionChangedListener { + public class BandSelectManager extends RecyclerView.OnScrollListener + implements BandSelectModel.OnSelectionChangedListener { private static final int NOT_SET = -1; @@ -1184,6 +1186,7 @@ public final class MultiSelectManager { public BandSelectManager(T helper) { mHelper = helper; + mHelper.addOnScrollListener(this); mModel = new BandSelectModel(helper); mModel.addOnSelectionChangedListener(this); } @@ -1316,11 +1319,6 @@ public final class MultiSelectManager { pixelsPastView, System.currentTimeMillis() - mScrollStartTime); mHelper.scrollBy(numPixels); - // Adjust the y-coordinate of the origin the opposite number of pixels so that the - // origin remains in the same place relative to the view's items. - mOrigin.y -= numPixels; - resizeBandSelectRectangle(); - mHelper.removeCallback(mViewScroller); mHelper.postRunnable(this); } @@ -1386,6 +1384,18 @@ public final class MultiSelectManager { return (float) Math.pow(ratio, 5); } }; + + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + if (!mIsActive) { + return; + } + + // Adjust the y-coordinate of the origin the opposite number of pixels so that the + // origin remains in the same place relative to the view's items. + mOrigin.y -= dy; + resizeBandSelectRectangle(); + } } /** -- cgit v1.2.3-59-g8ed1b