Loading src/com/android/documentsui/dirlist/DirectoryFragment.java +2 −2 Original line number Diff line number Diff line Loading @@ -335,8 +335,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On mSelectionMgr.addObserver(mSelectionMetadata); mDetailsLookup = new DocsItemDetailsLookup(mRecView); GestureSelectionHelper gestureHelper = GestureSelectionHelper.create(mSelectionMgr, mRecView, mContentLock); GestureSelectionHelper gestureHelper = GestureSelectionHelper.create( mSelectionMgr, mRecView, mContentLock, mDetailsLookup); if (mState.allowMultiple) { mBandSelector = new BandSelectionHelper( Loading src/com/android/documentsui/dirlist/DocsItemDetailsLookup.java +15 −3 Original line number Diff line number Diff line Loading @@ -41,17 +41,29 @@ final class DocsItemDetailsLookup extends ItemDetailsLookup { @Override public boolean overStableItem(MotionEvent e) { return overItem(e) && getItemDetails(e).hasStableId(); if (!overItem(e)) { return false; } ItemDetails details = getItemDetails(e); return details != null && details.hasStableId(); } @Override public boolean inItemDragRegion(MotionEvent e) { return overItem(e) && getItemDetails(e).inDragRegion(e); if (!overItem(e)) { return false; } ItemDetails details = getItemDetails(e); return details != null && details.inDragRegion(e); } @Override public boolean inItemSelectRegion(MotionEvent e) { return overItem(e) && getItemDetails(e).inSelectionHotspot(e); if (!overItem(e)) { return false; } ItemDetails details = getItemDetails(e); return details != null && details.inSelectionHotspot(e); } @Override Loading src/com/android/documentsui/dirlist/DocumentHolder.java +4 −1 Original line number Diff line number Diff line Loading @@ -94,7 +94,10 @@ public abstract class DocumentHolder @Override public boolean onKey(View v, int keyCode, KeyEvent event) { assert(mKeyEventListener != null); return mKeyEventListener.onKey(getItemDetails(), keyCode, event); ItemDetails details = getItemDetails(); return (details == null) ? false : mKeyEventListener.onKey(getItemDetails(), keyCode, event); } /** Loading src/com/android/documentsui/dirlist/MessageHolder.java +4 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.documentsui.dirlist; import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails; import android.content.Context; import android.view.MotionEvent; import android.view.ViewGroup; Loading @@ -34,7 +36,7 @@ abstract class MessageHolder extends DocumentHolder { } @Override public boolean inDragRegion(MotionEvent event) { return false; public ItemDetails getItemDetails() { return null; } } src/com/android/documentsui/selection/GestureSelectionHelper.java +26 −12 Original line number Diff line number Diff line Loading @@ -45,8 +45,9 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo private final Runnable mScroller; private final ViewDelegate mView; private final ContentLock mLock; private final ItemDetailsLookup mItemLookup; private int mLastStartedItemPos = -1; private int mLastTouchedItemPosition = -1; private boolean mStarted = false; private Point mLastInterceptedPoint; Loading @@ -58,15 +59,18 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo GestureSelectionHelper( SelectionHelper selectionHelper, ViewDelegate view, ContentLock lock) { ContentLock lock, ItemDetailsLookup itemLookup) { checkArgument(selectionHelper != null); checkArgument(view != null); checkArgument(lock != null); checkArgument(itemLookup != null); mSelectionMgr = selectionHelper; mView = view; mLock = lock; mItemLookup = itemLookup; mScroller = new ViewAutoScroller(this, mView); } Loading @@ -81,7 +85,7 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo // See: b/70518185. It appears start() is being called via onLongPress // even though we never received an intial handleInterceptedDownEvent // where we would usually initialize mLastStartedItemPos. if (mLastStartedItemPos < 0){ if (mLastTouchedItemPosition < 0){ Log.w(TAG, "Illegal state. Can't start without valid mLastStartedItemPos."); return; } Loading Loading @@ -142,11 +146,17 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {} // Called when an ACTION_DOWN event is intercepted. // Called when an ACTION_DOWN event is intercepted. See onInterceptTouchEvent // for additional notes. // If down event happens on an item, we mark that item's position as last started. private boolean handleInterceptedDownEvent(MotionEvent e) { mLastStartedItemPos = mView.getItemUnder(e); return mLastStartedItemPos != RecyclerView.NO_POSITION; // Ignore events where details provider doesn't return details. // These objects don't participate in selection. if (mItemLookup.getItemDetails(e) == null) { return false; } mLastTouchedItemPosition = mView.getItemUnder(e); return mLastTouchedItemPosition != RecyclerView.NO_POSITION; } // Called when ACTION_UP event is to be handled. Loading @@ -155,8 +165,8 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo private void handleUpEvent(MotionEvent e) { mSelectionMgr.mergeProvisionalSelection(); endSelection(); if (mLastStartedItemPos > -1) { mSelectionMgr.startRange(mLastStartedItemPos); if (mLastTouchedItemPosition > -1) { mSelectionMgr.startRange(mLastTouchedItemPosition); } } Loading @@ -171,7 +181,7 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo private void endSelection() { checkState(mStarted); mLastStartedItemPos = -1; mLastTouchedItemPosition = -1; mStarted = false; mLock.unblock(); } Loading Loading @@ -227,13 +237,17 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo } /** * Returns a new instance of GestureSelectionHelper. * Returns a new instance of GestureSelectionHelper, wrapping the * RecyclerView in a test friendly wrapper. */ public static GestureSelectionHelper create( SelectionHelper selectionMgr, RecyclerView recycler, ContentLock lock) { SelectionHelper selectionMgr, RecyclerView recycler, ContentLock lock, ItemDetailsLookup itemLookup) { return new GestureSelectionHelper( selectionMgr, new RecyclerViewDelegate(recycler), lock); selectionMgr, new RecyclerViewDelegate(recycler), lock, itemLookup); } @VisibleForTesting Loading Loading
src/com/android/documentsui/dirlist/DirectoryFragment.java +2 −2 Original line number Diff line number Diff line Loading @@ -335,8 +335,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On mSelectionMgr.addObserver(mSelectionMetadata); mDetailsLookup = new DocsItemDetailsLookup(mRecView); GestureSelectionHelper gestureHelper = GestureSelectionHelper.create(mSelectionMgr, mRecView, mContentLock); GestureSelectionHelper gestureHelper = GestureSelectionHelper.create( mSelectionMgr, mRecView, mContentLock, mDetailsLookup); if (mState.allowMultiple) { mBandSelector = new BandSelectionHelper( Loading
src/com/android/documentsui/dirlist/DocsItemDetailsLookup.java +15 −3 Original line number Diff line number Diff line Loading @@ -41,17 +41,29 @@ final class DocsItemDetailsLookup extends ItemDetailsLookup { @Override public boolean overStableItem(MotionEvent e) { return overItem(e) && getItemDetails(e).hasStableId(); if (!overItem(e)) { return false; } ItemDetails details = getItemDetails(e); return details != null && details.hasStableId(); } @Override public boolean inItemDragRegion(MotionEvent e) { return overItem(e) && getItemDetails(e).inDragRegion(e); if (!overItem(e)) { return false; } ItemDetails details = getItemDetails(e); return details != null && details.inDragRegion(e); } @Override public boolean inItemSelectRegion(MotionEvent e) { return overItem(e) && getItemDetails(e).inSelectionHotspot(e); if (!overItem(e)) { return false; } ItemDetails details = getItemDetails(e); return details != null && details.inSelectionHotspot(e); } @Override Loading
src/com/android/documentsui/dirlist/DocumentHolder.java +4 −1 Original line number Diff line number Diff line Loading @@ -94,7 +94,10 @@ public abstract class DocumentHolder @Override public boolean onKey(View v, int keyCode, KeyEvent event) { assert(mKeyEventListener != null); return mKeyEventListener.onKey(getItemDetails(), keyCode, event); ItemDetails details = getItemDetails(); return (details == null) ? false : mKeyEventListener.onKey(getItemDetails(), keyCode, event); } /** Loading
src/com/android/documentsui/dirlist/MessageHolder.java +4 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.documentsui.dirlist; import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails; import android.content.Context; import android.view.MotionEvent; import android.view.ViewGroup; Loading @@ -34,7 +36,7 @@ abstract class MessageHolder extends DocumentHolder { } @Override public boolean inDragRegion(MotionEvent event) { return false; public ItemDetails getItemDetails() { return null; } }
src/com/android/documentsui/selection/GestureSelectionHelper.java +26 −12 Original line number Diff line number Diff line Loading @@ -45,8 +45,9 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo private final Runnable mScroller; private final ViewDelegate mView; private final ContentLock mLock; private final ItemDetailsLookup mItemLookup; private int mLastStartedItemPos = -1; private int mLastTouchedItemPosition = -1; private boolean mStarted = false; private Point mLastInterceptedPoint; Loading @@ -58,15 +59,18 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo GestureSelectionHelper( SelectionHelper selectionHelper, ViewDelegate view, ContentLock lock) { ContentLock lock, ItemDetailsLookup itemLookup) { checkArgument(selectionHelper != null); checkArgument(view != null); checkArgument(lock != null); checkArgument(itemLookup != null); mSelectionMgr = selectionHelper; mView = view; mLock = lock; mItemLookup = itemLookup; mScroller = new ViewAutoScroller(this, mView); } Loading @@ -81,7 +85,7 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo // See: b/70518185. It appears start() is being called via onLongPress // even though we never received an intial handleInterceptedDownEvent // where we would usually initialize mLastStartedItemPos. if (mLastStartedItemPos < 0){ if (mLastTouchedItemPosition < 0){ Log.w(TAG, "Illegal state. Can't start without valid mLastStartedItemPos."); return; } Loading Loading @@ -142,11 +146,17 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {} // Called when an ACTION_DOWN event is intercepted. // Called when an ACTION_DOWN event is intercepted. See onInterceptTouchEvent // for additional notes. // If down event happens on an item, we mark that item's position as last started. private boolean handleInterceptedDownEvent(MotionEvent e) { mLastStartedItemPos = mView.getItemUnder(e); return mLastStartedItemPos != RecyclerView.NO_POSITION; // Ignore events where details provider doesn't return details. // These objects don't participate in selection. if (mItemLookup.getItemDetails(e) == null) { return false; } mLastTouchedItemPosition = mView.getItemUnder(e); return mLastTouchedItemPosition != RecyclerView.NO_POSITION; } // Called when ACTION_UP event is to be handled. Loading @@ -155,8 +165,8 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo private void handleUpEvent(MotionEvent e) { mSelectionMgr.mergeProvisionalSelection(); endSelection(); if (mLastStartedItemPos > -1) { mSelectionMgr.startRange(mLastStartedItemPos); if (mLastTouchedItemPosition > -1) { mSelectionMgr.startRange(mLastTouchedItemPosition); } } Loading @@ -171,7 +181,7 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo private void endSelection() { checkState(mStarted); mLastStartedItemPos = -1; mLastTouchedItemPosition = -1; mStarted = false; mLock.unblock(); } Loading Loading @@ -227,13 +237,17 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo } /** * Returns a new instance of GestureSelectionHelper. * Returns a new instance of GestureSelectionHelper, wrapping the * RecyclerView in a test friendly wrapper. */ public static GestureSelectionHelper create( SelectionHelper selectionMgr, RecyclerView recycler, ContentLock lock) { SelectionHelper selectionMgr, RecyclerView recycler, ContentLock lock, ItemDetailsLookup itemLookup) { return new GestureSelectionHelper( selectionMgr, new RecyclerViewDelegate(recycler), lock); selectionMgr, new RecyclerViewDelegate(recycler), lock, itemLookup); } @VisibleForTesting Loading