summaryrefslogtreecommitdiff
path: root/androidx/recyclerview/selection/SelectionTracker.java
diff options
context:
space:
mode:
Diffstat (limited to 'androidx/recyclerview/selection/SelectionTracker.java')
-rw-r--r--androidx/recyclerview/selection/SelectionTracker.java31
1 files changed, 20 insertions, 11 deletions
diff --git a/androidx/recyclerview/selection/SelectionTracker.java b/androidx/recyclerview/selection/SelectionTracker.java
index 2b35f5d7..283426f6 100644
--- a/androidx/recyclerview/selection/SelectionTracker.java
+++ b/androidx/recyclerview/selection/SelectionTracker.java
@@ -29,6 +29,8 @@ import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
+import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
import java.util.Set;
@@ -119,7 +121,7 @@ public abstract class SelectionTracker<K> {
* of the selection that will not reflect future changes
* to selection.
*/
- public abstract Selection getSelection();
+ public abstract Selection<K> getSelection();
/**
* Updates {@code dest} to reflect the current selection.
@@ -175,7 +177,7 @@ public abstract class SelectionTracker<K> {
*/
public abstract boolean deselect(@NonNull K key);
- abstract void onDataSetChanged();
+ abstract AdapterDataObserver getAdapterDataObserver();
/**
* Attempts to establish a range selection at {@code position}, selecting the item
@@ -471,7 +473,7 @@ public abstract class SelectionTracker<K> {
MotionEvent.TOOL_TYPE_UNKNOWN
};
- private int[] mBandToolTypes = new int[] {
+ private int[] mPointerToolTypes = new int[] {
MotionEvent.TOOL_TYPE_MOUSE
};
@@ -637,14 +639,16 @@ public abstract class SelectionTracker<K> {
}
/**
- * Replaces default band selection tool-types. Defaults are:
+ * Replaces default pointer tool-types. Pointer tools
+ * are associated with band selection, and certain
+ * drag and drop behaviors. Defaults are:
* {@link MotionEvent#TOOL_TYPE_MOUSE}.
*
* @param toolTypes the tool types to be used
* @return this
*/
- public Builder<K> withBandTooltypes(int... toolTypes) {
- mBandToolTypes = toolTypes;
+ public Builder<K> withPointerTooltypes(int... toolTypes) {
+ mPointerToolTypes = toolTypes;
return this;
}
@@ -769,10 +773,12 @@ public abstract class SelectionTracker<K> {
mOnItemActivatedListener,
mFocusDelegate);
- for (int toolType : mBandToolTypes) {
+ for (int toolType : mPointerToolTypes) {
gestureRouter.register(toolType, mouseHandler);
}
+ @Nullable BandSelectionHelper bandHelper = null;
+
// Band selection not supported in single select mode, or when key access
// is limited to anything less than the entire corpus.
if (mKeyProvider.hasAccess(ItemKeyProvider.SCOPE_MAPPED)
@@ -782,7 +788,7 @@ public abstract class SelectionTracker<K> {
// necessarily models and caches list/grid information as the user's pointer
// interacts with the item in the RecyclerView. Selectable items that intersect
// with the band, both on and off screen, are selected.
- BandSelectionHelper bandHelper = BandSelectionHelper.create(
+ bandHelper = BandSelectionHelper.create(
mRecyclerView,
scroller,
mBandOverlayId,
@@ -792,10 +798,13 @@ public abstract class SelectionTracker<K> {
mBandPredicate,
mFocusDelegate,
mMonitor);
+ }
+
+ OnItemTouchListener pointerEventHandler = new PointerDragEventInterceptor(
+ mDetailsLookup, mOnDragInitiatedListener, bandHelper);
- for (int toolType : mBandToolTypes) {
- eventRouter.register(toolType, bandHelper);
- }
+ for (int toolType : mPointerToolTypes) {
+ eventRouter.register(toolType, pointerEventHandler);
}
return tracker;