diff --git a/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java b/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java index 014d2c64fa..0635f91ad8 100644 --- a/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java +++ b/app/src/main/java/androidx/recyclerview/selection/DefaultSelectionTracker.java @@ -348,7 +348,7 @@ public class DefaultSelectionTracker extends SelectionTracker { } @Override - AdapterDataObserver getAdapterDataObserver() { + protected AdapterDataObserver getAdapterDataObserver() { return mAdapterObserver; } diff --git a/app/src/main/java/androidx/recyclerview/selection/GridModel.java b/app/src/main/java/androidx/recyclerview/selection/GridModel.java index 406ae618ff..8704d451b7 100644 --- a/app/src/main/java/androidx/recyclerview/selection/GridModel.java +++ b/app/src/main/java/androidx/recyclerview/selection/GridModel.java @@ -259,7 +259,7 @@ final class GridModel { private void updateModel() { RelativePoint old = mRelPointer; mRelPointer = createRelativePoint(mPointer); - if (old != null && mRelPointer.equals(old)) { + if (mRelPointer.equals(old)) { return; } diff --git a/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java b/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java index 9cb6d34551..d032e2b2a9 100644 --- a/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java +++ b/app/src/main/java/androidx/recyclerview/selection/ItemDetailsLookup.java @@ -16,10 +16,13 @@ package androidx.recyclerview.selection; +import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; + import android.view.MotionEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; import androidx.recyclerview.widget.RecyclerView; /** @@ -67,8 +70,10 @@ public abstract class ItemDetailsLookup { /** * @return true if there is an item w/ a stable ID at the event coordinates. + * @hide */ - final boolean overItemWithSelectionKey(@NonNull MotionEvent e) { + @RestrictTo(LIBRARY_GROUP) + protected boolean overItemWithSelectionKey(@NonNull MotionEvent e) { return overItem(e) && hasSelectionKey(getItemDetails(e)); } diff --git a/app/src/main/java/androidx/recyclerview/selection/MotionEvents.java b/app/src/main/java/androidx/recyclerview/selection/MotionEvents.java index bc47a76ccf..fbc4014b37 100644 --- a/app/src/main/java/androidx/recyclerview/selection/MotionEvents.java +++ b/app/src/main/java/androidx/recyclerview/selection/MotionEvents.java @@ -33,18 +33,10 @@ final class MotionEvents { return e.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE; } - static boolean isTouchEvent(@NonNull MotionEvent e) { - return e.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER; - } - static boolean isActionMove(@NonNull MotionEvent e) { return e.getActionMasked() == MotionEvent.ACTION_MOVE; } - static boolean isActionDown(@NonNull MotionEvent e) { - return e.getActionMasked() == MotionEvent.ACTION_DOWN; - } - static boolean isActionUp(@NonNull MotionEvent e) { return e.getActionMasked() == MotionEvent.ACTION_UP; } diff --git a/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java b/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java index f59bd9b692..294fceff89 100644 --- a/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java +++ b/app/src/main/java/androidx/recyclerview/selection/SelectionTracker.java @@ -16,6 +16,7 @@ package androidx.recyclerview.selection; +import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; import static androidx.core.util.Preconditions.checkArgument; import android.content.Context; @@ -28,6 +29,7 @@ import android.view.MotionEvent; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver; import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener; @@ -177,7 +179,9 @@ public abstract class SelectionTracker { */ public abstract boolean deselect(@NonNull K key); - abstract AdapterDataObserver getAdapterDataObserver(); + /** @hide */ + @RestrictTo(LIBRARY_GROUP) + protected abstract AdapterDataObserver getAdapterDataObserver(); /** * Attempts to establish a range selection at {@code position}, selecting the item @@ -186,8 +190,10 @@ public abstract class SelectionTracker { * @param position The "anchor" position for the range. Subsequent range operations * (primarily keyboard and mouse based operations like SHIFT + click) * work with the established anchor point to define selection ranges. + * @hide */ - abstract void startRange(int position); + @RestrictTo(LIBRARY_GROUP) + public abstract void startRange(int position); /** * Sets the end point for the active range selection. @@ -200,20 +206,26 @@ public abstract class SelectionTracker { * @param position The new end position for the selection range. * @throws IllegalStateException if a range selection is not active. Range selection * must have been started by a call to {@link #startRange(int)}. + * @hide */ - abstract void extendRange(int position); + @RestrictTo(LIBRARY_GROUP) + public abstract void extendRange(int position); /** * Clears an in-progress range selection. Provisional range selection established * using {@link #extendProvisionalRange(int)} will be cleared (unless * {@link #mergeProvisionalSelection()} is called first.) + * @hide */ - abstract void endRange(); + @RestrictTo(LIBRARY_GROUP) + public abstract void endRange(); /** * @return Whether or not there is a current range selection active. + * @hide */ - abstract boolean isRangeActive(); + @RestrictTo(LIBRARY_GROUP) + public abstract boolean isRangeActive(); /** * Establishes the "anchor" at which a selection range begins. This "anchor" is consulted @@ -223,32 +235,42 @@ public abstract class SelectionTracker { * TODO: Reconcile this with startRange. Maybe just docs need to be updated. * * @param position the anchor position. Must already be selected. + * @hide */ - abstract void anchorRange(int position); + @RestrictTo(LIBRARY_GROUP) + public abstract void anchorRange(int position); /** * Creates a provisional selection from anchor to {@code position}. * * @param position the end point. + * @hide */ - abstract void extendProvisionalRange(int position); + @RestrictTo(LIBRARY_GROUP) + protected abstract void extendProvisionalRange(int position); /** * Sets the provisional selection, replacing any existing selection. * @param newSelection + * @hide */ - abstract void setProvisionalSelection(@NonNull Set newSelection); + @RestrictTo(LIBRARY_GROUP) + protected abstract void setProvisionalSelection(@NonNull Set newSelection); /** * Clears any existing provisional selection + * @hide */ - abstract void clearProvisionalSelection(); + @RestrictTo(LIBRARY_GROUP) + protected abstract void clearProvisionalSelection(); /** * Converts the provisional selection into primary selection, then clears * provisional selection. + * @hide */ - abstract void mergeProvisionalSelection(); + @RestrictTo(LIBRARY_GROUP) + protected abstract void mergeProvisionalSelection(); /** * Preserves selection, if any. Call this method from Activity#onSaveInstanceState diff --git a/app/src/main/java/androidx/recyclerview/selection/StableIdKeyProvider.java b/app/src/main/java/androidx/recyclerview/selection/StableIdKeyProvider.java index b6c9a36a88..bd529594e1 100644 --- a/app/src/main/java/androidx/recyclerview/selection/StableIdKeyProvider.java +++ b/app/src/main/java/androidx/recyclerview/selection/StableIdKeyProvider.java @@ -21,12 +21,10 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.collection.LongSparseArray; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListener; -import java.util.HashMap; -import java.util.Map; - /** * An {@link ItemKeyProvider} that provides stable ids by way of cached * {@link RecyclerView.Adapter} stable ids. Items enter the cache as they are laid out by @@ -40,7 +38,7 @@ import java.util.Map; public final class StableIdKeyProvider extends ItemKeyProvider { private final SparseArray mPositionToKey = new SparseArray<>(); - private final Map mKeyToPosition = new HashMap(); + private final LongSparseArray mKeyToPosition = new LongSparseArray<>(); private final RecyclerView mRecyclerView; /** @@ -102,9 +100,6 @@ public final class StableIdKeyProvider extends ItemKeyProvider { @Override public int getPosition(@NonNull Long key) { - if (mKeyToPosition.containsKey(key)) { - return mKeyToPosition.get(key); - } - return RecyclerView.NO_POSITION; + return mKeyToPosition.get(key, RecyclerView.NO_POSITION); } } diff --git a/app/src/main/java/androidx/recyclerview/selection/package-info.java b/app/src/main/java/androidx/recyclerview/selection/package-info.java index a3386ab9e2..f344ba227c 100644 --- a/app/src/main/java/androidx/recyclerview/selection/package-info.java +++ b/app/src/main/java/androidx/recyclerview/selection/package-info.java @@ -116,9 +116,9 @@ * Include Selection in Activity lifecycle events * *

- * In order to preserve state the author must the selection library in handling - * of Activity lifecycle events. See SelectionTracker#onSaveInstanceState - * and SelectionTracker#onRestoreInstanceState. + * In order to preserve state, the author must include the selection library in the handling + * of Activity lifecycle events. See SelectionTracker#onSaveInstanceState and + * SelectionTracker#onRestoreInstanceState. * *

A unique selection id must be supplied to * {@link androidx.recyclerview.selection.SelectionTracker.Builder SelectionTracker.Builder}