summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steve McKay <smckay@google.com> 2017-08-31 10:27:08 -0700
committer Steve McKay <smckay@google.com> 2017-09-11 11:47:06 -0700
commit365e3cb1e103bff2303aa98fc8699e5e2eab1eb5 (patch)
treeeb0d2a95f98eae6a2caedae1b4d0a19753c2cb98
parent755b788160df31af457d32b66aa69169596d9dbf (diff)
Cleanup of Selection APIs.
Improved consistency in naming, updated some docs... baby steps, much more documentation is needed. Replace "Manager" noun w/ "Helper" noun for better consistency with RecycleView naming standards. Cleanup idiosyncracies in usage is DocumentsUI. Make SelectionManager responsible for notifying RecyclerView of selection changes allowing all notifications to be isolated in the listener interface. This also eliminates a requirement that Adapter implementations add plumbing to dispatch item change notifications to RecyclerView. Bug: 64847011 Test: Increased coverage. Change-Id: Icdf3815f2f4bbce8751d740d362228a204666f35
-rw-r--r--src/com/android/documentsui/AbstractActionHandler.java4
-rw-r--r--src/com/android/documentsui/ActionModeController.java47
-rw-r--r--src/com/android/documentsui/DocsSelectionHelper.java (renamed from src/com/android/documentsui/DocsSelectionManager.java)71
-rw-r--r--src/com/android/documentsui/FocusManager.java6
-rw-r--r--src/com/android/documentsui/Injector.java16
-rw-r--r--src/com/android/documentsui/SharedInputHandler.java6
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryAddonsAdapter.java6
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryFragment.java48
-rw-r--r--src/com/android/documentsui/dirlist/DocumentsAdapter.java9
-rw-r--r--src/com/android/documentsui/dirlist/DragHost.java6
-rw-r--r--src/com/android/documentsui/dirlist/DragStartListener.java17
-rw-r--r--src/com/android/documentsui/dirlist/ListeningGestureDetector.java12
-rw-r--r--src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java17
-rw-r--r--src/com/android/documentsui/dirlist/SelectionMetadata.java16
-rw-r--r--src/com/android/documentsui/dirlist/UserInputHandler.java48
-rw-r--r--src/com/android/documentsui/files/FilesActivity.java4
-rw-r--r--src/com/android/documentsui/files/MenuManager.java6
-rw-r--r--src/com/android/documentsui/picker/PickActivity.java6
-rw-r--r--src/com/android/documentsui/selection/DefaultSelectionHelper.java (renamed from src/com/android/documentsui/selection/DefaultSelectionManager.java)330
-rw-r--r--src/com/android/documentsui/selection/MutableSelection.java4
-rw-r--r--src/com/android/documentsui/selection/Range.java28
-rw-r--r--src/com/android/documentsui/selection/Selection.java59
-rw-r--r--src/com/android/documentsui/selection/SelectionHelper.java (renamed from src/com/android/documentsui/selection/SelectionManager.java)126
-rw-r--r--src/com/android/documentsui/selection/addons/BandSelectionHelper.java (renamed from src/com/android/documentsui/selection/addons/BandSelector.java)79
-rw-r--r--src/com/android/documentsui/selection/addons/ContentLock.java6
-rw-r--r--src/com/android/documentsui/selection/addons/GestureSelectionHelper.java (renamed from src/com/android/documentsui/selection/addons/GestureSelector.java)20
-rw-r--r--src/com/android/documentsui/selection/addons/GridModel.java40
-rw-r--r--tests/common/com/android/documentsui/dirlist/TestDocumentsAdapter.java54
-rw-r--r--tests/common/com/android/documentsui/selection/SelectionProbe.java20
-rw-r--r--tests/common/com/android/documentsui/selection/TestSelectionObserver.java (renamed from tests/common/com/android/documentsui/selection/TestSelectionEventListener.java)11
-rw-r--r--tests/common/com/android/documentsui/testing/SelectionHelpers.java (renamed from tests/common/com/android/documentsui/testing/SelectionManagers.java)28
-rw-r--r--tests/common/com/android/documentsui/testing/TestEnv.java6
-rw-r--r--tests/common/com/android/documentsui/testing/TestModel.java1
-rw-r--r--tests/unit/com/android/documentsui/DocsSelectionHelperTest.java (renamed from tests/unit/com/android/documentsui/DocsSelectionManagerTest.java)43
-rw-r--r--tests/unit/com/android/documentsui/FocusManagerTest.java12
-rw-r--r--tests/unit/com/android/documentsui/SharedInputHandlerTest.java18
-rw-r--r--tests/unit/com/android/documentsui/dirlist/DirectoryAddonsAdapterTest.java14
-rw-r--r--tests/unit/com/android/documentsui/dirlist/DragHostTest.java8
-rw-r--r--tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java18
-rw-r--r--tests/unit/com/android/documentsui/dirlist/UserInputHandler_KeyboardTest.java6
-rw-r--r--tests/unit/com/android/documentsui/dirlist/UserInputHandler_MouseTest.java10
-rw-r--r--tests/unit/com/android/documentsui/dirlist/UserInputHandler_RangeTest.java6
-rw-r--r--tests/unit/com/android/documentsui/dirlist/UserInputHandler_TouchTest.java22
-rw-r--r--tests/unit/com/android/documentsui/files/MenuManagerTest.java10
-rw-r--r--tests/unit/com/android/documentsui/picker/ActionHandlerTest.java2
-rw-r--r--tests/unit/com/android/documentsui/selection/DefaultSelectionHelperTest.java (renamed from tests/unit/com/android/documentsui/selection/DefaultSelectionManagerTest.java)145
-rw-r--r--tests/unit/com/android/documentsui/selection/DefaultSelectionHelper_SingleSelectTest.java (renamed from tests/unit/com/android/documentsui/selection/DefaultSelectionManager_SingleSelectTest.java)24
-rw-r--r--tests/unit/com/android/documentsui/selection/addons/BandSelectionHelperTest.java (renamed from tests/unit/com/android/documentsui/selection/addons/BandSelectorTest.java)22
-rw-r--r--tests/unit/com/android/documentsui/selection/addons/ContentLockTest.java2
-rw-r--r--tests/unit/com/android/documentsui/selection/addons/GestureSelectionHelperTest.java (renamed from tests/unit/com/android/documentsui/selection/addons/GestureSelectorTest.java)4
-rw-r--r--tests/unit/com/android/documentsui/selection/addons/GridModelTest.java6
-rw-r--r--tests/unit/com/android/documentsui/selection/addons/ViewAutoScrollerTest.java1
52 files changed, 826 insertions, 704 deletions
diff --git a/src/com/android/documentsui/AbstractActionHandler.java b/src/com/android/documentsui/AbstractActionHandler.java
index 62b144a66..3dc7b2c89 100644
--- a/src/com/android/documentsui/AbstractActionHandler.java
+++ b/src/com/android/documentsui/AbstractActionHandler.java
@@ -59,7 +59,7 @@ import com.android.documentsui.roots.GetRootDocumentTask;
import com.android.documentsui.roots.LoadRootTask;
import com.android.documentsui.roots.ProvidersAccess;
import com.android.documentsui.selection.MutableSelection;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.addons.ContentLock;
import com.android.documentsui.sidebar.EjectRootTask;
import com.android.documentsui.ui.Snackbars;
@@ -93,7 +93,7 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
protected final ProvidersAccess mProviders;
protected final DocumentsAccess mDocs;
protected final FocusHandler mFocusHandler;
- protected final SelectionManager mSelectionMgr;
+ protected final SelectionHelper mSelectionMgr;
protected final SearchViewManager mSearchMgr;
protected final Lookup<String, Executor> mExecutors;
protected final Injector<?> mInjector;
diff --git a/src/com/android/documentsui/ActionModeController.java b/src/com/android/documentsui/ActionModeController.java
index 607b927fe..bb7db8921 100644
--- a/src/com/android/documentsui/ActionModeController.java
+++ b/src/com/android/documentsui/ActionModeController.java
@@ -24,7 +24,6 @@ import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;
import android.view.ActionMode;
-import android.view.HapticFeedbackConstants;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -35,22 +34,20 @@ import com.android.documentsui.base.ConfirmationCallback.Result;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Menus;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
+import com.android.documentsui.selection.SelectionHelper.StubSelectionObserver;
import com.android.documentsui.ui.MessageBuilder;
-import java.util.function.Consumer;
-import java.util.function.IntConsumer;
-
/**
* A controller that listens to selection changes and manages life cycles of action modes.
*/
-public class ActionModeController
- implements SelectionManager.EventListener, ActionMode.Callback, ActionModeAddons {
+public class ActionModeController extends StubSelectionObserver
+ implements ActionMode.Callback, ActionModeAddons {
private static final String TAG = "ActionModeController";
private final Activity mActivity;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final MenuManager mMenuManager;
private final MessageBuilder mMessages;
@@ -62,7 +59,7 @@ public class ActionModeController
public ActionModeController(
Activity activity,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
MenuManager menuManager,
MessageBuilder messages) {
@@ -99,37 +96,7 @@ public class ActionModeController
@Override
public void onSelectionRestored() {
- mSelectionMgr.copySelection(mSelected);
- if (mSelected.size() > 0) {
- if (mActionMode == null) {
- if (DEBUG) Log.d(TAG, "Starting action mode.");
- mActionMode = mActivity.startActionMode(this);
- }
- updateActionMenu();
- } else {
- if (mActionMode != null) {
- if (DEBUG) Log.d(TAG, "Finishing action mode.");
- mActionMode.finish();
- }
- }
-
- if (mActionMode != null) {
- assert(!mSelected.isEmpty());
- final String title = mMessages.getQuantityString(
- R.plurals.elements_selected, mSelected.size());
- mActionMode.setTitle(title);
- mActivity.getWindow().setTitle(title);
- }
- }
-
- @Override
- public void onItemStateChanged(String id, boolean selected) {
- // Not utilized.
- }
-
- @Override
- public void onSelectionReset() {
- // Not utilized.
+ onSelectionChanged();
}
// Called when the user exits the action mode
diff --git a/src/com/android/documentsui/DocsSelectionManager.java b/src/com/android/documentsui/DocsSelectionHelper.java
index 90680bc6b..1f24a75b9 100644
--- a/src/com/android/documentsui/DocsSelectionManager.java
+++ b/src/com/android/documentsui/DocsSelectionHelper.java
@@ -19,10 +19,10 @@ package com.android.documentsui;
import android.support.annotation.VisibleForTesting;
import android.support.v7.widget.RecyclerView;
-import com.android.documentsui.selection.DefaultSelectionManager;
-import com.android.documentsui.selection.DefaultSelectionManager.SelectionMode;
+import com.android.documentsui.selection.DefaultSelectionHelper;
+import com.android.documentsui.selection.DefaultSelectionHelper.SelectionMode;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import java.util.Set;
@@ -32,20 +32,20 @@ import javax.annotation.Nullable;
* DocumentsUI SelectManager implementation that creates delegate instances
* each time reset is called.
*/
-public final class DocsSelectionManager implements SelectionManager {
+public final class DocsSelectionHelper implements SelectionHelper {
private final DelegateFactory mFactory;
private final @SelectionMode int mSelectionMode;
- private @Nullable SelectionManager mDelegate;
+ private @Nullable SelectionHelper mDelegate;
@VisibleForTesting
- DocsSelectionManager(DelegateFactory factory, @SelectionMode int mode) {
+ DocsSelectionHelper(DelegateFactory factory, @SelectionMode int mode) {
mFactory = factory;
mSelectionMode = mode;
}
- public SelectionManager reset(
+ public SelectionHelper reset(
RecyclerView.Adapter<?> adapter,
StableIdProvider stableIds,
SelectionPredicate canSetState) {
@@ -59,8 +59,8 @@ public final class DocsSelectionManager implements SelectionManager {
}
@Override
- public void addEventListener(EventListener listener) {
- mDelegate.addEventListener(listener);
+ public void addObserver(SelectionObserver listener) {
+ mDelegate.addObserver(listener);
}
@Override
@@ -78,6 +78,11 @@ public final class DocsSelectionManager implements SelectionManager {
mDelegate.copySelection(dest);
}
+ @Override
+ public boolean isSelected(String id) {
+ return mDelegate.isSelected(id);
+ }
+
@VisibleForTesting
public void replaceSelection(Iterable<String> ids) {
mDelegate.clearSelection();
@@ -100,28 +105,28 @@ public final class DocsSelectionManager implements SelectionManager {
}
@Override
- public void toggleSelection(String modelId) {
- mDelegate.toggleSelection(modelId);
+ public boolean select(String modelId) {
+ return mDelegate.select(modelId);
}
@Override
- public void startRangeSelection(int pos) {
- mDelegate.startRangeSelection(pos);
+ public boolean deselect(String modelId) {
+ return mDelegate.deselect(modelId);
}
@Override
- public void snapRangeSelection(int pos) {
- mDelegate.snapRangeSelection(pos);
+ public void startRange(int pos) {
+ mDelegate.startRange(pos);
}
@Override
- public void formNewSelectionRange(int startPos, int endPos) {
- mDelegate.formNewSelectionRange(startPos, endPos);
+ public void extendRange(int pos) {
+ mDelegate.extendRange(pos);
}
@Override
- public void snapProvisionalRangeSelection(int pos) {
- mDelegate.snapProvisionalRangeSelection(pos);
+ public void extendProvisionalRange(int pos) {
+ mDelegate.extendProvisionalRange(pos);
}
@Override
@@ -140,30 +145,30 @@ public final class DocsSelectionManager implements SelectionManager {
}
@Override
- public void endRangeSelection() {
- mDelegate.endRangeSelection();
+ public void endRange() {
+ mDelegate.endRange();
}
@Override
- public boolean isRangeSelectionActive() {
- return mDelegate.isRangeSelectionActive();
+ public boolean isRangeActive() {
+ return mDelegate.isRangeActive();
}
@Override
- public void setSelectionRangeBegin(int position) {
- mDelegate.setSelectionRangeBegin(position);
+ public void anchorRange(int position) {
+ mDelegate.anchorRange(position);
}
- public static DocsSelectionManager createMultiSelect() {
- return new DocsSelectionManager(
+ public static DocsSelectionHelper createMultiSelect() {
+ return new DocsSelectionHelper(
DelegateFactory.INSTANCE,
- DefaultSelectionManager.MODE_MULTIPLE);
+ DefaultSelectionHelper.MODE_MULTIPLE);
}
- public static DocsSelectionManager createSingleSelect() {
- return new DocsSelectionManager(
+ public static DocsSelectionHelper createSingleSelect() {
+ return new DocsSelectionHelper(
DelegateFactory.INSTANCE,
- DefaultSelectionManager.MODE_SINGLE);
+ DefaultSelectionHelper.MODE_SINGLE);
}
/**
@@ -174,13 +179,13 @@ public final class DocsSelectionManager implements SelectionManager {
static class DelegateFactory {
static final DelegateFactory INSTANCE = new DelegateFactory();
- SelectionManager create(
+ SelectionHelper create(
@SelectionMode int mode,
RecyclerView.Adapter<?> adapter,
StableIdProvider stableIds,
SelectionPredicate canSetState) {
- return new DefaultSelectionManager(mode, adapter, stableIds, canSetState);
+ return new DefaultSelectionHelper(mode, adapter, stableIds, canSetState);
}
}
}
diff --git a/src/com/android/documentsui/FocusManager.java b/src/com/android/documentsui/FocusManager.java
index dfedcd912..8f3795cad 100644
--- a/src/com/android/documentsui/FocusManager.java
+++ b/src/com/android/documentsui/FocusManager.java
@@ -47,7 +47,7 @@ import com.android.documentsui.base.Procedure;
import com.android.documentsui.dirlist.DocumentHolder;
import com.android.documentsui.dirlist.DocumentsAdapter;
import com.android.documentsui.dirlist.FocusHandler;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.Model.Update;
import java.util.ArrayList;
@@ -61,7 +61,7 @@ public final class FocusManager implements FocusHandler {
private final ContentScope mScope = new ContentScope();
private final Features mFeatures;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final DrawerController mDrawer;
private final Procedure mRootsFocuser;
private final TitleSearchHelper mSearchHelper;
@@ -70,7 +70,7 @@ public final class FocusManager implements FocusHandler {
public FocusManager(
Features features,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
DrawerController drawer,
Procedure rootsFocuser,
@ColorRes int color) {
diff --git a/src/com/android/documentsui/Injector.java b/src/com/android/documentsui/Injector.java
index 46c88641f..afeb90842 100644
--- a/src/com/android/documentsui/Injector.java
+++ b/src/com/android/documentsui/Injector.java
@@ -31,7 +31,7 @@ import com.android.documentsui.base.RootInfo;
import com.android.documentsui.dirlist.DocumentsAdapter;
import com.android.documentsui.prefs.ScopedPreferences;
import com.android.documentsui.queries.SearchViewManager;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.addons.ContentLock;
import com.android.documentsui.ui.DialogController;
import com.android.documentsui.ui.MessageBuilder;
@@ -70,7 +70,7 @@ public class Injector<T extends ActionHandler> {
public FocusManager focusManager;
@ContentScoped
- public DocsSelectionManager selectionMgr;
+ public DocsSelectionHelper selectionMgr;
private final Model mModel;
@@ -119,8 +119,8 @@ public class Injector<T extends ActionHandler> {
return focusManager.reset(view, model);
}
- public SelectionManager getSelectionManager(
- DocumentsAdapter adapter, SelectionManager.SelectionPredicate canSetState) {
+ public SelectionHelper getSelectionManager(
+ DocumentsAdapter adapter, SelectionHelper.SelectionPredicate canSetState) {
return selectionMgr.reset(adapter, adapter, canSetState);
}
@@ -133,10 +133,10 @@ public class Injector<T extends ActionHandler> {
* Obtains action handler and resets it if necessary.
*
* @param contentLock the lock held by
- * {@link com.android.documentsui.selection.addons.BandSelector} and
- * {@link com.android.documentsui.selection.addons.GestureSelector} to prevent loader
- * from updating result during band/gesture selection. May be {@code null} if called
- * from {@link com.android.documentsui.sidebar.RootsFragment}.
+ * {@link com.android.documentsui.selection.addons.BandSelectionHelper} and
+ * {@link com.android.documentsui.selection.addons.GestureSelectionHelper} to prevent
+ * loader from updating result during band/gesture selection. May be {@code null} if
+ * called from {@link com.android.documentsui.sidebar.RootsFragment}.
* @return the action handler
*/
public T getActionHandler(@Nullable ContentLock contentLock) {
diff --git a/src/com/android/documentsui/SharedInputHandler.java b/src/com/android/documentsui/SharedInputHandler.java
index f3f26419d..68772abbc 100644
--- a/src/com/android/documentsui/SharedInputHandler.java
+++ b/src/com/android/documentsui/SharedInputHandler.java
@@ -24,7 +24,7 @@ import com.android.documentsui.base.Events;
import com.android.documentsui.base.Features;
import com.android.documentsui.base.Procedure;
import com.android.documentsui.dirlist.FocusHandler;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
public class SharedInputHandler {
@@ -34,11 +34,11 @@ public class SharedInputHandler {
private final Procedure mSearchCanceler;
private final Procedure mDirPopper;
private final Features mFeatures;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
public SharedInputHandler(
FocusHandler focusHandler,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
Procedure searchCanceler,
Procedure dirPopper,
Features features) {
diff --git a/src/com/android/documentsui/dirlist/DirectoryAddonsAdapter.java b/src/com/android/documentsui/dirlist/DirectoryAddonsAdapter.java
index 58e339c54..2af38509c 100644
--- a/src/com/android/documentsui/dirlist/DirectoryAddonsAdapter.java
+++ b/src/com/android/documentsui/dirlist/DirectoryAddonsAdapter.java
@@ -21,10 +21,10 @@ import android.support.v7.widget.RecyclerView.AdapterDataObserver;
import android.view.ViewGroup;
import com.android.documentsui.Model;
+import com.android.documentsui.Model.Update;
import com.android.documentsui.base.EventListener;
import com.android.documentsui.dirlist.Message.HeaderMessage;
import com.android.documentsui.dirlist.Message.InflateMessage;
-import com.android.documentsui.Model.Update;
import java.util.List;
@@ -265,8 +265,8 @@ final class DirectoryAddonsAdapter extends DocumentsAdapter {
}
@Override
- public void onSelectionStateChanged(String id) {
- mDelegate.onSelectionStateChanged(id);
+ public int getPosition(String id) {
+ return toViewPosition(mDelegate.getPosition(id));
}
// Listener we add to our delegate. This allows us to relay events published
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 191acb507..2e492b873 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -89,13 +89,13 @@ import com.android.documentsui.clipping.UrisSupplier;
import com.android.documentsui.dirlist.AnimationView.AnimationType;
import com.android.documentsui.picker.PickActivity;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.selection.SelectionManager;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
-import com.android.documentsui.selection.addons.BandSelector;
-import com.android.documentsui.selection.addons.BandSelector.BandPredicate;
-import com.android.documentsui.selection.addons.BandSelector.SelectionHost;
+import com.android.documentsui.selection.SelectionHelper;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
+import com.android.documentsui.selection.addons.BandSelectionHelper;
+import com.android.documentsui.selection.addons.BandSelectionHelper.BandPredicate;
+import com.android.documentsui.selection.addons.BandSelectionHelper.SelectionHost;
import com.android.documentsui.selection.addons.ContentLock;
-import com.android.documentsui.selection.addons.GestureSelector;
+import com.android.documentsui.selection.addons.GestureSelectionHelper;
import com.android.documentsui.services.FileOperation;
import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
@@ -144,7 +144,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
@Injected
@ContentScoped
- private SelectionManager mSelectionMgr;
+ private SelectionHelper mSelectionMgr;
@Injected
@ContentScoped
@@ -161,7 +161,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
private EventDetailsLookup mDetailsLookup;
private SelectionMetadata mSelectionMetadata;
private UserInputHandler mInputHandler;
- private @Nullable BandSelector mBandController;
+ private @Nullable BandSelectionHelper mBandSelector;
private @Nullable DragHoverListener mDragHoverListener;
private IconHelper mIconHelper;
private SwipeRefreshLayout mRefreshLayout;
@@ -182,7 +182,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
// Blocks loading/reloading of content while user is actively making selection.
private ContentLock mContentLock = new ContentLock();
- private Runnable mBandSelectStarted;
+ private Runnable mBandSelectStartedCallback;
// Note, we use !null to indicate that selection was restored (from rotation).
// So don't fiddle with this field unless you've got the bigger picture in mind.
@@ -265,8 +265,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
mModel.removeUpdateListener(mModelUpdateListener);
mModel.removeUpdateListener(mAdapter.getModelUpdateListener());
- if (mBandController != null) {
- mBandController.removeBandSelectStartedListener(mBandSelectStarted);
+ if (mBandSelector != null) {
+ mBandSelector.removeOnBandStartedListener(mBandSelectStartedCallback);
}
super.onDestroyView();
@@ -354,11 +354,11 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
new AccessibilityEventRouter(mRecView,
(View child) -> onAccessibilityClick(child)));
mSelectionMetadata = new SelectionMetadata(mModel::getItem);
- mSelectionMgr.addEventListener(mSelectionMetadata);
+ mSelectionMgr.addObserver(mSelectionMetadata);
mDetailsLookup = new RuntimeEventDetailsLookup(mRecView);
- GestureSelector gestureSel =
- GestureSelector.create(mSelectionMgr, mRecView, mContentLock);
+ GestureSelectionHelper gestureSel =
+ GestureSelectionHelper.create(mSelectionMgr, mRecView, mContentLock);
if (mState.allowMultiple) {
BandPredicate bandPredicate = new BandPredicate() {
@@ -372,18 +372,18 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
}
};
- SelectionHost host = BandSelector.createHost(
+ SelectionHost host = BandSelectionHelper.createHost(
mRecView, R.drawable.band_select_overlay, bandPredicate);
- mBandController = new BandSelector(
+ mBandSelector = new BandSelectionHelper(
host,
- mAdapter,
+ mAdapter, // recycler view adapter.
mAdapter, // stableIds provider.
mSelectionMgr,
selectionPredicate,
mContentLock);
- mBandSelectStarted = mFocusManager::clearFocus;
- mBandController.addBandSelectStartedListener(mBandSelectStarted);
+ mBandSelectStartedCallback = mFocusManager::clearFocus;
+ mBandSelector.addOnBandStartedListener(mBandSelectStartedCallback);
}
DragStartListener mDragStartListener = mInjector.config.dragAndDropEnabled()
@@ -427,14 +427,14 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
mRefreshLayout::setEnabled,
gestureSel,
mInputHandler,
- mBandController,
+ mBandSelector,
this::scaleLayout);
mActionModeController = mInjector.getActionModeController(
mSelectionMetadata,
this::handleMenuItemClick);
- mSelectionMgr.addEventListener(mActionModeController);
+ mSelectionMgr.addObserver(mActionModeController);
final ActivityManager am = (ActivityManager) mActivity.getSystemService(
Context.ACTIVITY_SERVICE);
@@ -579,8 +579,8 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
int pad = getDirectoryPadding(mode);
mRecView.setPadding(pad, pad, pad, pad);
mRecView.requestLayout();
- if (mBandController != null) {
- mBandController.handleLayoutChanged();
+ if (mBandSelector != null) {
+ mBandSelector.onLayoutChanged();
}
mIconHelper.setViewMode(mode);
}
@@ -1210,7 +1210,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
@Override
public boolean isSelected(String id) {
- return mSelectionMgr.getSelection().contains(id);
+ return mSelectionMgr.isSelected(id);
}
@Override
diff --git a/src/com/android/documentsui/dirlist/DocumentsAdapter.java b/src/com/android/documentsui/dirlist/DocumentsAdapter.java
index 7ba8ef842..63cf3d817 100644
--- a/src/com/android/documentsui/dirlist/DocumentsAdapter.java
+++ b/src/com/android/documentsui/dirlist/DocumentsAdapter.java
@@ -29,9 +29,7 @@ import com.android.documentsui.Model;
import com.android.documentsui.base.EventListener;
import com.android.documentsui.base.Features;
import com.android.documentsui.base.State;
-import com.android.documentsui.selection.SelectionManager;
-
-import java.util.List;
+import com.android.documentsui.selection.SelectionHelper;
/**
* DocumentsAdapter provides glue between a directory Model, and RecyclerView. We've
@@ -43,7 +41,7 @@ import java.util.List;
* @see DirectoryAddonsAdapter
*/
public abstract class DocumentsAdapter
- extends RecyclerView.Adapter<DocumentHolder> implements SelectionManager.StableIdProvider {
+ extends RecyclerView.Adapter<DocumentHolder> implements SelectionHelper.StableIdProvider {
// Item types used by ModelBackedDocumentsAdapter
public static final int ITEM_TYPE_DOCUMENT = 1;
public static final int ITEM_TYPE_DIRECTORY = 2;
@@ -52,9 +50,6 @@ public abstract class DocumentsAdapter
public static final int ITEM_TYPE_HEADER_MESSAGE = Integer.MAX_VALUE - 1;
public static final int ITEM_TYPE_INFLATED_MESSAGE = Integer.MAX_VALUE - 2;
- // Payloads for notifyItemChange to distinguish between selection and other events.
- static final String SELECTION_CHANGED_MARKER = "Selection-Changed";
-
public abstract int getAdapterPosition(String modelId);
abstract EventListener<Model.Update> getModelUpdateListener();
diff --git a/src/com/android/documentsui/dirlist/DragHost.java b/src/com/android/documentsui/dirlist/DragHost.java
index 987303a82..787431cd8 100644
--- a/src/com/android/documentsui/dirlist/DragHost.java
+++ b/src/com/android/documentsui/dirlist/DragHost.java
@@ -32,7 +32,7 @@ import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.Lookup;
import com.android.documentsui.base.State;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.ui.DialogController;
import java.util.function.Predicate;
@@ -45,7 +45,7 @@ class DragHost<T extends Activity & AbstractActionHandler.CommonAddons> extends
private static final String TAG = "dirlist.DragHost";
private final T mActivity;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final ActionHandler mActions;
private final State mState;
private final DialogController mDialogs;
@@ -56,7 +56,7 @@ class DragHost<T extends Activity & AbstractActionHandler.CommonAddons> extends
DragHost(
T activity,
DragAndDropManager dragAndDropManager,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
ActionHandler actions,
State state,
DialogController dialogs,
diff --git a/src/com/android/documentsui/dirlist/DragStartListener.java b/src/com/android/documentsui/dirlist/DragStartListener.java
index 31afcd4cc..1d42526fe 100644
--- a/src/com/android/documentsui/dirlist/DragStartListener.java
+++ b/src/com/android/documentsui/dirlist/DragStartListener.java
@@ -34,7 +34,7 @@ import com.android.documentsui.base.Events;
import com.android.documentsui.base.State;
import com.android.documentsui.selection.MutableSelection;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import java.util.ArrayList;
import java.util.List;
@@ -71,7 +71,7 @@ interface DragStartListener {
private final IconHelper mIconHelper;
private final State mState;
private final EventDetailsLookup mDetailsLookup;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final SelectionDetails mSelectionDetails;
private final ViewFinder mViewFinder;
private final Function<View, String> mIdFinder;
@@ -85,7 +85,7 @@ interface DragStartListener {
IconHelper iconHelper,
State state,
EventDetailsLookup detailsLookup,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
SelectionDetails selectionDetails,
ViewFinder viewFinder,
Function<View, String> idFinder,
@@ -162,12 +162,13 @@ interface DragStartListener {
MutableSelection selection = new MutableSelection();
// If CTRL-key is held down and there's other existing selection, add item to
// selection (if not already selected)
- if (Events.isCtrlKeyPressed(event) && !mSelectionMgr.getSelection().contains(modelId)
- && mSelectionMgr.hasSelection()) {
- mSelectionMgr.toggleSelection(modelId);
+ if (Events.isCtrlKeyPressed(event)
+ && mSelectionMgr.hasSelection()
+ && !mSelectionMgr.isSelected(modelId)) {
+ mSelectionMgr.select(modelId);
}
- if (mSelectionMgr.getSelection().contains(modelId)) {
+ if (mSelectionMgr.isSelected(modelId)) {
mSelectionMgr.copySelection(selection);
} else {
selection.add(modelId);
@@ -180,7 +181,7 @@ interface DragStartListener {
static DragStartListener create(
IconHelper iconHelper,
Model model,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
SelectionDetails selectionDetails,
State state,
EventDetailsLookup detailsLookup,
diff --git a/src/com/android/documentsui/dirlist/ListeningGestureDetector.java b/src/com/android/documentsui/dirlist/ListeningGestureDetector.java
index 7db970013..deae96c6f 100644
--- a/src/com/android/documentsui/dirlist/ListeningGestureDetector.java
+++ b/src/com/android/documentsui/dirlist/ListeningGestureDetector.java
@@ -33,8 +33,8 @@ import com.android.documentsui.base.EventDetailsLookup;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Events;
import com.android.documentsui.base.Features;
-import com.android.documentsui.selection.addons.BandSelector;
-import com.android.documentsui.selection.addons.GestureSelector;
+import com.android.documentsui.selection.addons.BandSelectionHelper;
+import com.android.documentsui.selection.addons.GestureSelectionHelper;
import java.util.function.Consumer;
@@ -46,10 +46,10 @@ final class ListeningGestureDetector extends GestureDetector implements OnItemTo
private static final String TAG = "ListeningGestureDetector";
private final Features mFeatures;
- private final GestureSelector mGestureSelector;
+ private final GestureSelectionHelper mGestureSelector;
private final EventHandler<MotionEvent> mMouseDragListener;
private final BooleanConsumer mRefreshLayoutEnabler;
- private final BandSelector mBandController;
+ private final BandSelectionHelper mBandController;
private final EventDetailsLookup mDocEventBinder;
private final MouseDelegate mMouseDelegate = new MouseDelegate();
@@ -65,9 +65,9 @@ final class ListeningGestureDetector extends GestureDetector implements OnItemTo
RecyclerView recView,
EventHandler<MotionEvent> mouseDragListener,
BooleanConsumer refreshLayoutEnabler,
- GestureSelector gestureSelector,
+ GestureSelectionHelper gestureSelector,
UserInputHandler handler,
- @Nullable BandSelector bandController,
+ @Nullable BandSelectionHelper bandController,
Consumer<Float> scaleHandler) {
super(context, handler);
diff --git a/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java b/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
index 00c607633..d16f05ca7 100644
--- a/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
+++ b/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
@@ -23,14 +23,16 @@ import static com.android.documentsui.base.State.MODE_LIST;
import android.database.Cursor;
import android.provider.DocumentsContract.Document;
+import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.ViewGroup;
import com.android.documentsui.Model;
+import com.android.documentsui.Model.Update;
import com.android.documentsui.base.EventListener;
import com.android.documentsui.base.Lookup;
import com.android.documentsui.base.State;
-import com.android.documentsui.Model.Update;
+import com.android.documentsui.selection.SelectionHelper;
import java.util.ArrayList;
import java.util.List;
@@ -109,7 +111,7 @@ final class ModelBackedDocumentsAdapter extends DocumentsAdapter {
@Override
public void onBindViewHolder(DocumentHolder holder, int position, List<Object> payload) {
- if (payload.contains(SELECTION_CHANGED_MARKER)) {
+ if (payload.contains(SelectionHelper.SELECTION_CHANGED_MARKER)) {
final boolean selected = mEnv.isSelected(mModelIds.get(position));
holder.setSelected(selected, true);
} else {
@@ -191,13 +193,10 @@ final class ModelBackedDocumentsAdapter extends DocumentsAdapter {
}
@Override
- public void onSelectionStateChanged(String id) {
+ public int getPosition(String id) {
int position = mModelIds.indexOf(id);
-
- if (position >= 0) {
- notifyItemChanged(position, SELECTION_CHANGED_MARKER);
- } else {
- Log.w(TAG, "Item change notification received for unknown item: " + id);
- }
+ return position >= 0
+ ? position
+ : RecyclerView.NO_POSITION;
}
}
diff --git a/src/com/android/documentsui/dirlist/SelectionMetadata.java b/src/com/android/documentsui/dirlist/SelectionMetadata.java
index 1030ac334..d70b1f184 100644
--- a/src/com/android/documentsui/dirlist/SelectionMetadata.java
+++ b/src/com/android/documentsui/dirlist/SelectionMetadata.java
@@ -27,15 +27,15 @@ import com.android.documentsui.MenuManager;
import com.android.documentsui.archives.ArchivesProvider;
import com.android.documentsui.base.MimeTypes;
import com.android.documentsui.roots.RootCursorWrapper;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper.StubSelectionObserver;
import java.util.function.Function;
/**
* A class that holds metadata
*/
-public class SelectionMetadata
- implements MenuManager.SelectionDetails, SelectionManager.EventListener {
+public class SelectionMetadata extends StubSelectionObserver
+ implements MenuManager.SelectionDetails {
private static final String TAG = "SelectionMetadata";
private final static int FLAG_CAN_DELETE =
@@ -103,16 +103,6 @@ public class SelectionMetadata
}
@Override
- public void onSelectionChanged() {
- // Not utilized.
- }
-
- @Override
- public void onSelectionRestored() {
- // Not utilized.
- }
-
- @Override
public void onSelectionReset() {
mFileCount = 0;
mDirectoryCount = 0;
diff --git a/src/com/android/documentsui/dirlist/UserInputHandler.java b/src/com/android/documentsui/dirlist/UserInputHandler.java
index efb743a98..5daf8e76b 100644
--- a/src/com/android/documentsui/dirlist/UserInputHandler.java
+++ b/src/com/android/documentsui/dirlist/UserInputHandler.java
@@ -16,6 +16,7 @@
package com.android.documentsui.dirlist;
+import static android.support.v4.util.Preconditions.checkArgument;
import static com.android.documentsui.base.Shared.DEBUG;
import static com.android.documentsui.base.Shared.VERBOSE;
@@ -28,7 +29,7 @@ import com.android.documentsui.ActionHandler;
import com.android.documentsui.base.EventDetailsLookup;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Events;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import java.util.function.Predicate;
@@ -45,7 +46,7 @@ public final class UserInputHandler
private ActionHandler mActions;
private final FocusHandler mFocusHandler;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final EventDetailsLookup mDetailsLookup;
private final Predicate<DocumentDetails> mSelectable;
private final EventHandler<MotionEvent> mContextMenuClickHandler;
@@ -61,7 +62,7 @@ public final class UserInputHandler
public UserInputHandler(
ActionHandler actions,
FocusHandler focusHandler,
- SelectionManager selectionMgr,
+ SelectionHelper selectionMgr,
EventDetailsLookup detailsLookup,
Predicate<DocumentDetails> selectable,
EventHandler<MotionEvent> contextMenuClickHandler,
@@ -142,10 +143,12 @@ public final class UserInputHandler
}
private boolean selectDocument(DocumentDetails doc) {
- assert doc != null;
- assert doc.hasModelId();
- mSelectionMgr.toggleSelection(doc.getModelId());
- mSelectionMgr.setSelectionRangeBegin(doc.getAdapterPosition());
+ checkArgument(doc != null);
+ checkArgument(doc.hasModelId());
+
+ if (mSelectionMgr.select(doc.getModelId())) {
+ mSelectionMgr.anchorRange(doc.getAdapterPosition());
+ }
// we set the focus on this doc so it will be the origin for keyboard events or shift+clicks
// if there is only a single item selected, otherwise clear focus
@@ -158,8 +161,8 @@ public final class UserInputHandler
}
private boolean focusDocument(DocumentDetails doc) {
- assert doc != null;
- assert doc.hasModelId();
+ checkArgument(doc != null);
+ checkArgument(doc.hasModelId());
mSelectionMgr.clearSelection();
mFocusHandler.focusDocument(doc.getModelId());
@@ -167,12 +170,12 @@ public final class UserInputHandler
}
private void extendSelectionRange(DocumentDetails doc) {
- mSelectionMgr.snapRangeSelection(doc.getAdapterPosition());
+ mSelectionMgr.extendRange(doc.getAdapterPosition());
mFocusHandler.focusDocument(doc.getModelId());
}
boolean isRangeExtension(MotionEvent e) {
- return Events.isShiftKeyPressed(e) && mSelectionMgr.isRangeSelectionActive();
+ return Events.isShiftKeyPressed(e) && mSelectionMgr.isRangeActive();
}
private boolean shouldClearSelection(MotionEvent e, DocumentDetails doc) {
@@ -202,8 +205,6 @@ public final class UserInputHandler
boolean onSingleTapUp(MotionEvent e) {
if (VERBOSE) Log.v(TTAG, "Delegated onSingleTapUp event.");
- // if (!event.isOverModelItem()) {
-
if (!mDetailsLookup.overModelItem(e)) {
if (DEBUG) Log.d(TTAG, "Tap not associated w/ model item. Clearing selection.");
mSelectionMgr.clearSelection();
@@ -214,8 +215,8 @@ public final class UserInputHandler
if (mSelectionMgr.hasSelection()) {
if (isRangeExtension(e)) {
extendSelectionRange(doc);
- } else if (mSelectionMgr.getSelection().contains(doc.getModelId())) {
- mSelectionMgr.toggleSelection(doc.getModelId());
+ } else if (mSelectionMgr.isSelected(doc.getModelId())) {
+ mSelectionMgr.deselect(doc.getModelId());
} else {
selectDocument(doc);
}
@@ -333,8 +334,9 @@ public final class UserInputHandler
mSelectionMgr.clearSelection();
}
if (isSelected(doc)) {
- mSelectionMgr.toggleSelection(doc.getModelId());
- mFocusHandler.clearFocus();
+ if (mSelectionMgr.deselect(doc.getModelId())) {
+ mFocusHandler.clearFocus();
+ }
} else {
selectOrFocusItem(e);
}
@@ -375,8 +377,8 @@ public final class UserInputHandler
}
if (mFocusHandler.hasFocusedItem() && Events.isShiftKeyPressed(e)) {
- mSelectionMgr.formNewSelectionRange(mFocusHandler.getFocusPosition(),
- doc.getAdapterPosition());
+ mSelectionMgr.startRange(mFocusHandler.getFocusPosition());
+ mSelectionMgr.extendRange(doc.getAdapterPosition());
} else {
selectOrFocusItem(e);
}
@@ -464,13 +466,13 @@ public final class UserInputHandler
// bounds of the in-progress range selection. Each time an unshifted navigation
// event is received, the range selection is restarted.
if (shouldExtendSelection(doc, event)) {
- if (!mSelectionMgr.isRangeSelectionActive()) {
+ if (!mSelectionMgr.isRangeActive()) {
// Start a range selection if one isn't active
- mSelectionMgr.startRangeSelection(doc.getAdapterPosition());
+ mSelectionMgr.startRange(doc.getAdapterPosition());
}
- mSelectionMgr.snapRangeSelection(mFocusHandler.getFocusPosition());
+ mSelectionMgr.extendRange(mFocusHandler.getFocusPosition());
} else {
- mSelectionMgr.endRangeSelection();
+ mSelectionMgr.endRange();
mSelectionMgr.clearSelection();
}
return true;
diff --git a/src/com/android/documentsui/files/FilesActivity.java b/src/com/android/documentsui/files/FilesActivity.java
index f5c9f23b3..a6efbb05a 100644
--- a/src/com/android/documentsui/files/FilesActivity.java
+++ b/src/com/android/documentsui/files/FilesActivity.java
@@ -38,7 +38,7 @@ import android.view.MenuItem;
import com.android.documentsui.ActionModeController;
import com.android.documentsui.BaseActivity;
-import com.android.documentsui.DocsSelectionManager;
+import com.android.documentsui.DocsSelectionHelper;
import com.android.documentsui.DocumentsApplication;
import com.android.documentsui.FocusManager;
import com.android.documentsui.Injector;
@@ -104,7 +104,7 @@ public class FilesActivity extends BaseActivity implements ActionHandler.Addons
super.onCreate(icicle);
DocumentClipper clipper = DocumentsApplication.getDocumentClipper(this);
- mInjector.selectionMgr = DocsSelectionManager.createMultiSelect();
+ mInjector.selectionMgr = DocsSelectionHelper.createMultiSelect();
mInjector.focusManager = new FocusManager(
mInjector.features,
diff --git a/src/com/android/documentsui/files/MenuManager.java b/src/com/android/documentsui/files/MenuManager.java
index 4a17c3ddf..60cf11b58 100644
--- a/src/com/android/documentsui/files/MenuManager.java
+++ b/src/com/android/documentsui/files/MenuManager.java
@@ -36,7 +36,7 @@ import com.android.documentsui.base.Lookup;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import com.android.documentsui.queries.SearchViewManager;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import java.util.List;
import java.util.function.IntFunction;
@@ -45,7 +45,7 @@ public final class MenuManager extends com.android.documentsui.MenuManager {
private final Features mFeatures;
private final Context mContext;
- private final SelectionManager mSelectionManager;
+ private final SelectionHelper mSelectionManager;
private final Lookup<String, Uri> mUriLookup;
private final Lookup<String, String> mAppNameLookup;
@@ -55,7 +55,7 @@ public final class MenuManager extends com.android.documentsui.MenuManager {
State displayState,
DirectoryDetails dirDetails,
Context context,
- SelectionManager selectionManager,
+ SelectionHelper selectionManager,
Lookup<String, String> appNameLookup,
Lookup<String, Uri> uriLookup) {
diff --git a/src/com/android/documentsui/picker/PickActivity.java b/src/com/android/documentsui/picker/PickActivity.java
index f3d261cde..94327b1ea 100644
--- a/src/com/android/documentsui/picker/PickActivity.java
+++ b/src/com/android/documentsui/picker/PickActivity.java
@@ -34,7 +34,7 @@ import android.view.Menu;
import com.android.documentsui.ActionModeController;
import com.android.documentsui.BaseActivity;
-import com.android.documentsui.DocsSelectionManager;
+import com.android.documentsui.DocsSelectionHelper;
import com.android.documentsui.DocumentsApplication;
import com.android.documentsui.FocusManager;
import com.android.documentsui.Injector;
@@ -95,8 +95,8 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
super.onCreate(icicle);
mInjector.selectionMgr = mState.allowMultiple
- ? DocsSelectionManager.createMultiSelect()
- : DocsSelectionManager.createSingleSelect();
+ ? DocsSelectionHelper.createMultiSelect()
+ : DocsSelectionHelper.createSingleSelect();
mInjector.focusManager = new FocusManager(
mInjector.features,
diff --git a/src/com/android/documentsui/selection/DefaultSelectionManager.java b/src/com/android/documentsui/selection/DefaultSelectionHelper.java
index f6941c886..a3372638a 100644
--- a/src/com/android/documentsui/selection/DefaultSelectionManager.java
+++ b/src/com/android/documentsui/selection/DefaultSelectionHelper.java
@@ -16,6 +16,8 @@
package com.android.documentsui.selection;
+import static android.support.v4.util.Preconditions.checkArgument;
+import static android.support.v4.util.Preconditions.checkState;
import static com.android.documentsui.selection.Shared.DEBUG;
import static com.android.documentsui.selection.Shared.TAG;
@@ -34,11 +36,13 @@ import java.util.Set;
import javax.annotation.Nullable;
/**
- * SelectManager providing support traditional multi-item selection support to RecyclerView.
- * Additionally it can be configured to restrict selection to a single element, @see
- * #setSelectMode.
+ * {@link SelectionHelper} providing support traditional multi-item selection on top
+ * of {@link RecyclerView}.
+ *
+ * <p>The class supports running in a single-select mode, which can be enabled
+ * by passing {@colde #MODE_SINGLE} to the constructor.
*/
-public final class DefaultSelectionManager implements SelectionManager {
+public final class DefaultSelectionHelper implements SelectionHelper {
public static final int MODE_MULTIPLE = 0;
public static final int MODE_SINGLE = 1;
@@ -59,7 +63,7 @@ public final class DefaultSelectionManager implements SelectionManager {
* items with the band. Provisionally selected items are considered to be selected in
* {@link Selection#contains(String)} and related methods. A provisional may be abandoned or
* applied by selection components (like
- * {@link com.android.documentsui.selection.addons.BandSelector}).
+ * {@link com.android.documentsui.selection.addons.BandSelectionHelper}).
*
* <p>A provisional selection may intersect the primary selection, however clearing the
* provisional selection will not affect the primary selection where the two may intersect.
@@ -73,7 +77,7 @@ public final class DefaultSelectionManager implements SelectionManager {
@interface RangeType {}
private final Selection mSelection = new Selection();
- private final List<EventListener> mEventListeners = new ArrayList<>(1);
+ private final List<SelectionObserver> mObservers = new ArrayList<>(1);
private final RecyclerView.Adapter<?> mAdapter;
private final StableIdProvider mStableIds;
private final SelectionPredicate mSelectionPredicate;
@@ -81,7 +85,7 @@ public final class DefaultSelectionManager implements SelectionManager {
private final boolean mSingleSelect;
- private @Nullable Range mRanger;
+ private @Nullable Range mRange;
/**
* Creates a new instance.
@@ -93,15 +97,15 @@ public final class DefaultSelectionManager implements SelectionManager {
* @param selectionPredicate A predicate allowing the client to disallow selection
* of individual elements.
*/
- public DefaultSelectionManager(
+ public DefaultSelectionHelper(
@SelectionMode int mode,
RecyclerView.Adapter<?> adapter,
StableIdProvider stableIds,
SelectionPredicate selectionPredicate) {
- assert adapter != null;
- assert stableIds != null;
- assert selectionPredicate != null;
+ checkArgument(adapter != null);
+ checkArgument(stableIds != null);
+ checkArgument(selectionPredicate != null);
mAdapter = adapter;
mStableIds = stableIds;
@@ -119,7 +123,7 @@ public final class DefaultSelectionManager implements SelectionManager {
mSelection.clearProvisionalSelection();
mSelection.intersect(mStableIds.getStableIds());
- notifyDataChanged();
+ onDataSetChanged();
}
@Override
@@ -135,8 +139,8 @@ public final class DefaultSelectionManager implements SelectionManager {
@Override
public void onItemRangeRemoved(int startPosition, int itemCount) {
- assert startPosition >= 0;
- assert itemCount > 0;
+ checkArgument(startPosition >= 0);
+ checkArgument(itemCount > 0);
mSelection.clearProvisionalSelection();
// Remove any disappeared IDs from the selection.
@@ -153,9 +157,10 @@ public final class DefaultSelectionManager implements SelectionManager {
}
@Override
- public void addEventListener(EventListener callback) {
- assert callback != null;
- mEventListeners.add(callback);
+ public void addObserver(SelectionObserver callback) {
+ checkArgument(callback != null);
+
+ mObservers.add(callback);
}
@Override
@@ -174,6 +179,11 @@ public final class DefaultSelectionManager implements SelectionManager {
}
@Override
+ public boolean isSelected(String id) {
+ return mSelection.contains(id);
+ }
+
+ @Override
public void restoreSelection(Selection other) {
setItemsSelectedQuietly(other.mSelection, true);
// NOTE: We intentionally don't restore provisional selection. It's provisional.
@@ -182,7 +192,7 @@ public final class DefaultSelectionManager implements SelectionManager {
@Override
public boolean setItemsSelected(Iterable<String> ids, boolean selected) {
- final boolean changed = setItemsSelectedQuietly(ids, selected);
+ boolean changed = setItemsSelectedQuietly(ids, selected);
notifySelectionChanged();
return changed;
}
@@ -190,7 +200,7 @@ public final class DefaultSelectionManager implements SelectionManager {
private boolean setItemsSelectedQuietly(Iterable<String> ids, boolean selected) {
boolean changed = false;
for (String id: ids) {
- final boolean itemChanged =
+ boolean itemChanged =
selected
? canSetState(id, true) && mSelection.add(id)
: canSetState(id, false) && mSelection.remove(id);
@@ -208,90 +218,125 @@ public final class DefaultSelectionManager implements SelectionManager {
return;
}
- clearSelectionQuietly();
+ Selection prev = clearSelectionQuietly();
+ notifySelectionCleared(prev);
notifySelectionChanged();
}
/**
- * Clears the selection, without notifying selection listeners. UI elements still need to be
- * notified about state changes so that they can update their appearance.
+ * Clears the selection, without notifying selection listeners.
+ * Returns items in previous selection. Callers are responsible for notifying
+ * listeners about changes.
*/
- private void clearSelectionQuietly() {
- mRanger = null;
+ private Selection clearSelectionQuietly() {
+ mRange = null;
- if (!hasSelection()) {
- return;
+ Selection prevSelection = new Selection();
+ if (hasSelection()) {
+ copySelection(prevSelection);
+ mSelection.clear();
}
- Selection oldSelection = new Selection();
- copySelection(oldSelection);
- mSelection.clear();
+ return prevSelection;
+ }
- for (String id: oldSelection.mSelection) {
- notifyItemStateChanged(id, false);
- }
- for (String id: oldSelection.mProvisionalSelection) {
- notifyItemStateChanged(id, false);
+ @Override
+ public boolean select(String id) {
+ checkArgument(id != null);
+
+ if (!mSelection.contains(id)) {
+ if (!canSetState(id, true)) {
+ if (DEBUG) Log.d(TAG, "Select cancelled by selection predicate test.");
+ return false;
+ }
+
+ // Enforce single selection policy.
+ if (mSingleSelect && hasSelection()) {
+ Selection prev = clearSelectionQuietly();
+ notifySelectionCleared(prev);
+ }
+
+ mSelection.add(id);
+ notifyItemStateChanged(id, true);
+ notifySelectionChanged();
+
+ return true;
}
+
+ return false;
}
@Override
- public void toggleSelection(String modelId) {
- assert modelId != null;
-
- final boolean changed = mSelection.contains(modelId)
- ? attemptDeselect(modelId)
- : attemptSelect(modelId);
+ public boolean deselect(String id) {
+ checkArgument(id != null);
- if (changed) {
+ if (mSelection.contains(id)) {
+ if (!canSetState(id, false)) {
+ if (DEBUG) Log.d(TAG, "Deselect cancelled by selection predicate test.");
+ return false;
+ }
+ mSelection.remove(id);
+ notifyItemStateChanged(id, false);
notifySelectionChanged();
+ if (mSelection.isEmpty() && isRangeActive()) {
+ // if there's nothing in the selection and there is an active ranger it results
+ // in unexpected behavior when the user tries to start range selection: the item
+ // which the ranger 'thinks' is the already selected anchor becomes unselectable
+ endRange();
+ }
+ return true;
}
+
+ return false;
}
@Override
- public void startRangeSelection(int pos) {
- attemptSelect(mStableIds.getStableId(pos));
- setSelectionRangeBegin(pos);
+ public void startRange(int pos) {
+ select(mStableIds.getStableId(pos));
+ anchorRange(pos);
}
@Override
- public void snapRangeSelection(int pos) {
- snapRangeSelection(pos, RANGE_REGULAR);
+ public void extendRange(int pos) {
+ extendRange(pos, RANGE_REGULAR);
}
@Override
- public void snapProvisionalRangeSelection(int pos) {
- snapRangeSelection(pos, RANGE_PROVISIONAL);
+ public void endRange() {
+ mRange = null;
+ // Clean up in case there was any leftover provisional selection
+ clearProvisionalSelection();
}
- /*
- * Starts and extends range selection in one go. This assumes item at startPos is not selected
- * beforehand.
- */
@Override
- public void formNewSelectionRange(int startPos, int endPos) {
- assert !mSelection.contains(mStableIds.getStableId(startPos));
- startRangeSelection(startPos);
- snapRangeSelection(endPos);
+ public void anchorRange(int position) {
+ checkArgument(position != RecyclerView.NO_POSITION);
+
+ if (mSelection.contains(mStableIds.getStableId(position))) {
+ mRange = new Range(this::updateForRange, position);
+ }
+ }
+
+ @Override
+ public void extendProvisionalRange(int pos) {
+ extendRange(pos, RANGE_PROVISIONAL);
}
/**
* Sets the end point for the current range selection, started by a call to
- * {@link #startRangeSelection(int)}. This function should only be called when a range selection
- * is active (see {@link #isRangeSelectionActive()}. Items in the range [anchor, end] will be
+ * {@link #startRange(int)}. This function should only be called when a range selection
+ * is active (see {@link #isRangeActive()}. Items in the range [anchor, end] will be
* selected or in provisional select, depending on the type supplied. Note that if the type is
* provisional selection, one should do {@link #mergeProvisionalSelection()} at some
- * point before calling on {@link #endRangeSelection()}.
+ * point before calling on {@link #endRange()}.
*
* @param pos The new end position for the selection range.
* @param type The type of selection the range should utilize.
*/
- private void snapRangeSelection(int pos, @RangeType int type) {
- if (!isRangeSelectionActive()) {
- throw new IllegalStateException("Range start point not set.");
- }
+ private void extendRange(int pos, @RangeType int type) {
+ checkState(isRangeActive(), "Range start point not set.");
- mRanger.snapSelection(pos, type);
+ mRange.extendSelection(pos, type);
// We're being lazy here notifying even when something might not have changed.
// To make this more correct, we'd need to update the Ranger class to return
@@ -300,19 +345,12 @@ public final class DefaultSelectionManager implements SelectionManager {
}
@Override
- public void clearProvisionalSelection() {
- for (String id : mSelection.mProvisionalSelection) {
- notifyItemStateChanged(id, false);
- }
- mSelection.clearProvisionalSelection();
- }
-
- @Override
public void setProvisionalSelection(Set<String> newSelection) {
Map<String, Boolean> delta = mSelection.setProvisionalSelection(newSelection);
for (Map.Entry<String, Boolean> entry: delta.entrySet()) {
notifyItemStateChanged(entry.getKey(), entry.getValue());
}
+
notifySelectionChanged();
}
@@ -322,99 +360,36 @@ public final class DefaultSelectionManager implements SelectionManager {
}
@Override
- public void endRangeSelection() {
- mRanger = null;
- // Clean up in case there was any leftover provisional selection
- clearProvisionalSelection();
- }
-
- @Override
- public boolean isRangeSelectionActive() {
- return mRanger != null;
- }
-
- @Override
- public void setSelectionRangeBegin(int position) {
- if (position == RecyclerView.NO_POSITION) {
- return;
- }
-
- if (mSelection.contains(mStableIds.getStableId(position))) {
- mRanger = new Range(this::updateForRange, position);
- }
- }
-
- /**
- * @param modelId
- * @return True if the update was applied.
- */
- private boolean selectAndNotify(String modelId) {
- boolean changed = mSelection.add(modelId);
- if (changed) {
- notifyItemStateChanged(modelId, true);
- }
- return changed;
- }
-
- /**
- * @param id
- * @return True if the update was applied.
- */
- private boolean attemptDeselect(String id) {
- assert id != null;
-
- if (!canSetState(id, false)) {
- if (DEBUG) Log.d(TAG, "Select cancelled by listener.");
- return false;
- }
-
- mSelection.remove(id);
- notifyItemStateChanged(id, false);
-
- // if there's nothing in the selection and there is an active ranger it results
- // in unexpected behavior when the user tries to start range selection: the item
- // which the ranger 'thinks' is the already selected anchor becomes unselectable
- if (mSelection.isEmpty() && isRangeSelectionActive()) {
- endRangeSelection();
+ public void clearProvisionalSelection() {
+ for (String id : mSelection.mProvisionalSelection) {
+ notifyItemStateChanged(id, false);
}
- if (DEBUG) Log.d(TAG, "Selection after deselect: " + mSelection);
- return true;
+ mSelection.clearProvisionalSelection();
}
- /**
- * @param id
- * @return True if the update was applied.
- */
- private boolean attemptSelect(String id) {
- assert id != null;
-
- if (!canSetState(id, true)) {
- return false;
- }
-
- if (mSingleSelect && hasSelection()) {
- clearSelectionQuietly();
- }
-
- selectAndNotify(id);
- return true;
+ @Override
+ public boolean isRangeActive() {
+ return mRange != null;
}
private boolean canSetState(String id, boolean nextState) {
return mSelectionPredicate.canSetStateForId(id, nextState);
}
- private void notifyDataChanged() {
+ private void onDataSetChanged() {
notifySelectionReset();
- final int lastListener = mEventListeners.size() - 1;
for (String id : mSelection) {
- // TODO: Why do we deselect in notify changed.
+ // If the underlying data set has changed, before restoring
+ // selection we must re-verify that it can be selected.
+ // Why? Because if the dataset has changed, then maybe the
+ // selectability of an item has changed.
if (!canSetState(id, true)) {
- attemptDeselect(id);
+ deselect(id);
} else {
+ int lastListener = mObservers.size() - 1;
for (int i = lastListener; i >= 0; i--) {
- mEventListeners.get(i).onItemStateChanged(id, true);
+ mObservers.get(i).onItemStateChanged(id, true);
}
}
}
@@ -425,12 +400,30 @@ public final class DefaultSelectionManager implements SelectionManager {
* (identified by {@code position}) changes.
*/
private void notifyItemStateChanged(String id, boolean selected) {
- assert id != null;
- int lastListenerIndex = mEventListeners.size() - 1;
+ checkArgument(id != null);
+
+ int lastListenerIndex = mObservers.size() - 1;
for (int i = lastListenerIndex; i >= 0; i--) {
- mEventListeners.get(i).onItemStateChanged(id, selected);
+ mObservers.get(i).onItemStateChanged(id, selected);
+ }
+
+ int position = mStableIds.getPosition(id);
+ if (DEBUG) Log.d(TAG, "ITEM " + id + " CHANGED at pos: " + position);
+
+ if (position >= 0) {
+ mAdapter.notifyItemChanged(position, SelectionHelper.SELECTION_CHANGED_MARKER);
+ } else {
+ Log.w(TAG, "Item change notification received for unknown item: " + id);
+ }
+ }
+
+ private void notifySelectionCleared(Selection selection) {
+ for (String id: selection.mSelection) {
+ notifyItemStateChanged(id, false);
+ }
+ for (String id: selection.mProvisionalSelection) {
+ notifyItemStateChanged(id, false);
}
- mStableIds.onSelectionStateChanged(id);
}
/**
@@ -440,23 +433,23 @@ public final class DefaultSelectionManager implements SelectionManager {
* selection from one item to another.
*/
private void notifySelectionChanged() {
- int lastListenerIndex = mEventListeners.size() - 1;
+ int lastListenerIndex = mObservers.size() - 1;
for (int i = lastListenerIndex; i >= 0; i--) {
- mEventListeners.get(i).onSelectionChanged();
+ mObservers.get(i).onSelectionChanged();
}
}
private void notifySelectionRestored() {
- int lastListenerIndex = mEventListeners.size() - 1;
+ int lastListenerIndex = mObservers.size() - 1;
for (int i = lastListenerIndex; i >= 0; i--) {
- mEventListeners.get(i).onSelectionRestored();
+ mObservers.get(i).onSelectionRestored();
}
}
private void notifySelectionReset() {
- int lastListenerIndex = mEventListeners.size() - 1;
+ int lastListenerIndex = mObservers.size() - 1;
for (int i = lastListenerIndex; i >= 0; i--) {
- mEventListeners.get(i).onSelectionReset();
+ mObservers.get(i).onSelectionReset();
}
}
@@ -474,7 +467,8 @@ public final class DefaultSelectionManager implements SelectionManager {
}
private void updateForRegularRange(int begin, int end, boolean selected) {
- assert end >= begin;
+ checkArgument(end >= begin);
+
for (int i = begin; i <= end; i++) {
String id = mStableIds.getStableId(i);
if (id == null) {
@@ -482,21 +476,16 @@ public final class DefaultSelectionManager implements SelectionManager {
}
if (selected) {
- boolean canSelect = canSetState(id, true);
- if (canSelect) {
- if (mSingleSelect && hasSelection()) {
- clearSelectionQuietly();
- }
- selectAndNotify(id);
- }
+ select(id);
} else {
- attemptDeselect(id);
+ deselect(id);
}
}
}
private void updateForProvisionalRange(int begin, int end, boolean selected) {
- assert end >= begin;
+ checkArgument(end >= begin);
+
for (int i = begin; i <= end; i++) {
String id = mStableIds.getStableId(i);
if (id == null) {
@@ -521,6 +510,7 @@ public final class DefaultSelectionManager implements SelectionManager {
notifyItemStateChanged(id, selected);
}
}
+
notifySelectionChanged();
}
}
diff --git a/src/com/android/documentsui/selection/MutableSelection.java b/src/com/android/documentsui/selection/MutableSelection.java
index 11404bd3f..7939e14ef 100644
--- a/src/com/android/documentsui/selection/MutableSelection.java
+++ b/src/com/android/documentsui/selection/MutableSelection.java
@@ -17,8 +17,8 @@ package com.android.documentsui.selection;
/**
* Subclass of Selection exposing public support for mutating the underlying selection data.
- * This is useful for clients of {@link SelectionManager} that wish to manipulate
- * a copy of selection data obtained via {@link SelectionManager#copySelection(Selection)}.
+ * This is useful for clients of {@link SelectionHelper} that wish to manipulate
+ * a copy of selection data obtained via {@link SelectionHelper#copySelection(Selection)}.
*/
public final class MutableSelection extends Selection {
diff --git a/src/com/android/documentsui/selection/Range.java b/src/com/android/documentsui/selection/Range.java
index 540518955..781e95b3d 100644
--- a/src/com/android/documentsui/selection/Range.java
+++ b/src/com/android/documentsui/selection/Range.java
@@ -15,24 +15,23 @@
*/
package com.android.documentsui.selection;
+import static android.support.v4.util.Preconditions.checkArgument;
+import static android.support.v7.widget.RecyclerView.NO_POSITION;
import static com.android.documentsui.selection.Shared.DEBUG;
import static com.android.documentsui.selection.Shared.TAG;
-import android.support.v7.widget.RecyclerView;
import android.util.Log;
-import com.android.documentsui.selection.DefaultSelectionManager.RangeType;
+import com.android.documentsui.selection.DefaultSelectionHelper.RangeType;
/**
* Class providing support for managing range selections.
*/
final class Range {
- private static final int UNDEFINED = -1;
-
private final Range.RangeUpdater mUpdater;
private final int mBegin;
- private int mEnd = UNDEFINED;
+ private int mEnd = NO_POSITION;
public Range(Range.RangeUpdater updater, int begin) {
if (DEBUG) Log.d(TAG, "New Ranger created beginning @ " + begin);
@@ -40,12 +39,12 @@ final class Range {
mBegin = begin;
}
- void snapSelection(int position, @RangeType int type) {
- assert(position != RecyclerView.NO_POSITION);
+ void extendSelection(int position, @RangeType int type) {
+ checkArgument(position != NO_POSITION, "Position cannot be NO_POSITION.");
- if (mEnd == UNDEFINED || mEnd == mBegin) {
+ if (mEnd == NO_POSITION || mEnd == mBegin) {
// Reset mEnd so it can be established in establishRange.
- mEnd = UNDEFINED;
+ mEnd = NO_POSITION;
establishRange(position, type);
} else {
reviseRange(position, type);
@@ -53,7 +52,7 @@ final class Range {
}
private void establishRange(int position, @RangeType int type) {
- assert(mEnd == UNDEFINED);
+ checkArgument(mEnd == NO_POSITION, "End has already been set.");
if (position == mBegin) {
mEnd = position;
@@ -69,8 +68,8 @@ final class Range {
}
private void reviseRange(int position, @RangeType int type) {
- assert(mEnd != UNDEFINED);
- assert(mBegin != mEnd);
+ checkArgument(mEnd != NO_POSITION, "End must already be set.");
+ checkArgument(mBegin != mEnd, "Beging and end point to same position.");
if (position == mEnd) {
if (DEBUG) Log.v(TAG, "Ignoring no-op revision for range: " + this);
@@ -87,7 +86,7 @@ final class Range {
}
/**
- * Updates an existing ascending seleciton.
+ * Updates an existing ascending selection.
* @param position
*/
private void reviseAscendingRange(int position, @RangeType int type) {
@@ -143,8 +142,7 @@ final class Range {
}
/*
- * @see {@link MultiSelectManager#updateForRegularRange(int, int , boolean)} and {@link
- * MultiSelectManager#updateForProvisionalRange(int, int, boolean)}
+ * @see {@link DefaultSelectionManager#updateForRange(int, int , boolean, int)}.
*/
@FunctionalInterface
interface RangeUpdater {
diff --git a/src/com/android/documentsui/selection/Selection.java b/src/com/android/documentsui/selection/Selection.java
index 72367e64a..6f6b5a0db 100644
--- a/src/com/android/documentsui/selection/Selection.java
+++ b/src/com/android/documentsui/selection/Selection.java
@@ -30,22 +30,29 @@ import java.util.Set;
import javax.annotation.Nullable;
/**
- * Object representing the current selection. Provides read only access
- * public access, and private write access.
+ * Object representing the current selection and provisional selection. Provides read only public
+ * access, and private write access.
+ * <p>
+ * This class tracks selected items by managing two sets:
+ *
+ * <li>primary selection
+ *
+ * Primary selection consists of items tapped by a user or by lassoed by band select operation.
+ *
+ * <li>provisional selection
+ *
+ * Provisional selections are selections which have been temporarily created
+ * by an in-progress band select or gesture selection. Once the user releases the mouse button
+ * or lifts their finger the corresponding provisional selection should be converted into
+ * primary selection.
+ *
+ * <p>The total selection is the combination of
+ * both the core selection and the provisional selection. Tracking both separately is necessary to
+ * ensure that items in the core selection are not "erased" from the core selection when they
+ * are temporarily included in a secondary selection (like band selection).
*/
public class Selection implements Iterable<String>, Parcelable {
- // This class tracks selected items by managing two sets: the saved selection, and the total
- // selection. Saved selections are those which have been completed by tapping an item or by
- // completing a band select operation. Provisional selections are selections which have been
- // temporarily created by an in-progress band select operation (once the user releases the
- // mouse button during a band select operation, the selected items become saved). The total
- // selection is the combination of both the saved selection and the provisional
- // selection. Tracking both separately is necessary to ensure that saved selections do not
- // become deselected when they are removed from the provisional selection; for example, if
- // item A is tapped (and selected), then an in-progress band select covers A then uncovers
- // A, A should still be selected as it has been saved. To ensure this behavior, the saved
- // selection must be tracked separately.
final Set<String> mSelection;
final Set<String> mProvisionalSelection;
@@ -101,14 +108,12 @@ public class Selection implements Iterable<String>, Parcelable {
* one (if it exists) is abandoned.
* @return Map of ids added or removed. Added ids have a value of true, removed are false.
*/
- // TODO: Make this private to selectionmanager. Even other selection classes like BandController
- // should not be reaching in and modify selection state.
Map<String, Boolean> setProvisionalSelection(Set<String> newSelection) {
Map<String, Boolean> delta = new HashMap<>();
for (String id: mProvisionalSelection) {
- // Mark each item that used to be in the selection but is unsaved and not in the new
- // provisional selection.
+ // Mark each item that used to be in the provisional selection
+ // but is not in the new provisional selection.
if (!newSelection.contains(id) && !mSelection.contains(id)) {
delta.put(id, false);
}
@@ -243,17 +248,19 @@ public class Selection implements Iterable<String>, Parcelable {
}
@Override
- public boolean equals(Object that) {
- if (this == that) {
- return true;
- }
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
- if (!(that instanceof Selection)) {
- return false;
- }
+ return other instanceof Selection
+ ? equals((Selection) other)
+ : false;
+ }
- return mSelection.equals(((Selection) that).mSelection) &&
- mProvisionalSelection.equals(((Selection) that).mProvisionalSelection);
+ private boolean equals(Selection other) {
+ return mSelection.equals(((Selection) other).mSelection) &&
+ mProvisionalSelection.equals(((Selection) other).mProvisionalSelection);
}
@Override
diff --git a/src/com/android/documentsui/selection/SelectionManager.java b/src/com/android/documentsui/selection/SelectionHelper.java
index 7096e06d6..3030ae5f6 100644
--- a/src/com/android/documentsui/selection/SelectionManager.java
+++ b/src/com/android/documentsui/selection/SelectionHelper.java
@@ -22,17 +22,24 @@ import java.util.Set;
/**
* SelectionManager provides support for managing selection within a RecyclerView instance.
*
- * @see DefaultSelectionManager for details on usage.
+ * @see DefaultSelectionHelper for details on instantiation.
*/
-public interface SelectionManager {
+public interface SelectionHelper {
/**
- * Adds {@code callback} such that it will be notified when {@code MultiSelectManager}
- * events occur.
+ * This value is included in the payload when SelectionHelper implementations
+ * notify RecyclerView of changes. Clients can look for this in
+ * {@code onBindViewHolder} to know if the bind event is occurring in response
+ * to a selection state change.
+ */
+ public static final String SELECTION_CHANGED_MARKER = "Selection-Changed";
+
+ /**
+ * Adds {@code observe} to be notified when changes to selection occur.
*
- * @param callback
+ * @param observer
*/
- void addEventListener(EventListener listener);
+ void addObserver(SelectionObserver observer);
boolean hasSelection();
@@ -54,6 +61,12 @@ public interface SelectionManager {
void copySelection(Selection dest);
/**
+ * @return true if the item specified by its id is selected. Shorthand for
+ * {@code getSelection().contains(String)}.
+ */
+ boolean isSelected(String id);
+
+ /**
* Restores the selected state of specified items. Used in cases such as restore the selection
* after rotation etc. Provisional selection, being provisional 'n all, isn't restored.
*/
@@ -75,11 +88,20 @@ public interface SelectionManager {
void clearSelection();
/**
- * Toggles selection on the item with the given model ID.
+ * Attempts to select an item.
+ *
+ * @return true if the item was selected. False if the item was not selected, or was
+ * was already selected prior to the method being called.
+ */
+ boolean select(String itemId);
+
+ /**
+ * Attempts to deselect an item.
*
- * @param modelId
+ * @return true if the item was deselected. False if the item was not deselected, or was
+ * was already deselected prior to the method being called.
*/
- void toggleSelection(String modelId);
+ boolean deselect(String itemId);
/**
* Starts a range selection. If a range selection is already active, this will start a new range
@@ -87,47 +109,49 @@ public interface SelectionManager {
*
* @param pos The anchor position for the selection range.
*/
- void startRangeSelection(int pos);
+ void startRange(int pos);
/**
* Sets the end point for the active range selection.
*
* <p>This function should only be called when a range selection is active
- * (see {@link #isRangeSelectionActive()}. Items in the range [anchor, end] will be
+ * (see {@link #isRangeActive()}. Items in the range [anchor, end] will be
* selected.
*
* @param pos The new end position for the selection range.
* @param type The type of selection the range should utilize.
*
* @throws IllegalStateException if a range selection is not active. Range selection
- * must have been started by a call to {@link #startRangeSelection(int)}.
+ * must have been started by a call to {@link #startRange(int)}.
*/
- void snapRangeSelection(int pos);
-
- /*
- * Creates a fully formed range selection in one go. This assumes item at
- * {@code startPos} is not selected beforehand.
- */
- void formNewSelectionRange(int startPos, int endPos);
+ void extendRange(int pos);
/**
* Stops an in-progress range selection. All selection done with
- * {@link #snapRangeSelection(int, int)} with type RANGE_PROVISIONAL will be lost if
+ * {@link #extendProvisionalRange(int)} will be lost if
* {@link Selection#mergeProvisionalSelection()} is not called beforehand.
*/
- void endRangeSelection();
+ void endRange();
/**
* @return Whether or not there is a current range selection active.
*/
- boolean isRangeSelectionActive();
+ boolean isRangeActive();
/**
* Sets the magic location at which a selection range begins (the selection anchor). This value
* is consulted when determining how to extend, and modify selection ranges. Calling this when a
* range selection is active will reset the range selection.
*/
- void setSelectionRangeBegin(int position);
+ void anchorRange(int position);
+
+ /**
+ * @param pos
+ */
+ // TODO: This is smelly. Maybe this type of logic needs to move into range selection,
+ // then selection manager can have a startProvisionalRange and startRange. Or
+ // maybe ranges always start life as provisional.
+ void extendProvisionalRange(int pos);
/**
* @param newSelection
@@ -139,20 +163,12 @@ public interface SelectionManager {
*/
void clearProvisionalSelection();
- /**
- * @param pos
- */
- // TODO: This is smelly. Maybe this type of logic needs to move into range selection,
- // then selection manager can have a startProvisionalRange and startRange. Or
- // maybe ranges always start life as provisional.
- void snapProvisionalRangeSelection(int pos);
-
void mergeProvisionalSelection();
/**
- * Interface allowing clients access to information about Selection state change.
+ * Observer interface providing access to information about Selection state changes.
*/
- interface EventListener {
+ interface SelectionObserver {
/**
* Called when state of an item has been changed.
@@ -160,22 +176,52 @@ public interface SelectionManager {
void onItemStateChanged(String id, boolean selected);
/**
- * Called when selection is reset (cleared).
+ * Called when the underlying data set has change. After this method is called
+ * the selection manager will attempt traverse the existing selection,
+ * calling {@link #onItemStateChanged(String, boolean)} for each selected item,
+ * and deselecting any items that cannot be selected given the updated dataset.
*/
void onSelectionReset();
/**
- * Called immediately after completion of any set of changes.
+ * Called immediately after completion of any set of changes, excluding
+ * those resulting in calls to {@link #onSelectionReset()} and
+ * {@link #onSelectionRestored()}.
*/
void onSelectionChanged();
/**
* Called immediately after selection is restored.
+ * {@link #onItemStateChanged(String, boolean)} will not be called
+ * for individual items in the selection.
*/
void onSelectionRestored();
}
/**
+ * Stub observer class that can be used either as a base class for observers
+ * that are interested only in a subset of events, or as a test stub.
+ */
+ static class StubSelectionObserver implements SelectionObserver {
+
+ @Override
+ public void onItemStateChanged(String id, boolean selected) {
+ }
+
+ @Override
+ public void onSelectionReset() {
+ }
+
+ @Override
+ public void onSelectionChanged() {
+ }
+
+ @Override
+ public void onSelectionRestored() {
+ }
+ }
+
+ /**
* Facilitates the use of stable ids.
*/
interface StableIdProvider {
@@ -185,16 +231,14 @@ public interface SelectionManager {
String getStableId(int position);
/**
- * Returns a list of model IDs of items currently in the adapter.
- *
- * @return A list of all known stable IDs.
+ * @return the position of a stable ID, or RecyclerView.NO_POSITION.
*/
- List<String> getStableIds();
+ int getPosition(String id);
/**
- * Triggers item-change notifications by stable ID (as opposed to position).
+ * @return A list of all known stable IDs.
*/
- void onSelectionStateChanged(String id);
+ List<String> getStableIds();
}
/**
diff --git a/src/com/android/documentsui/selection/addons/BandSelector.java b/src/com/android/documentsui/selection/addons/BandSelectionHelper.java
index ba2169ee9..0d38b9195 100644
--- a/src/com/android/documentsui/selection/addons/BandSelector.java
+++ b/src/com/android/documentsui/selection/addons/BandSelectionHelper.java
@@ -32,9 +32,9 @@ import android.view.MotionEvent;
import android.view.View;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.selection.SelectionManager;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
-import com.android.documentsui.selection.SelectionManager.StableIdProvider;
+import com.android.documentsui.selection.SelectionHelper;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
+import com.android.documentsui.selection.SelectionHelper.StableIdProvider;
import com.android.documentsui.selection.addons.ViewAutoScroller.Callbacks;
import com.android.documentsui.selection.addons.ViewAutoScroller.ScrollHost;
@@ -44,37 +44,39 @@ import java.util.Set;
/**
* Provides mouse driven band-selection support when used in conjunction with
- * a {@link RecyclerView} instance and a {@link SelectionManager}. This class is responsible
+ * a {@link RecyclerView} instance and a {@link SelectionHelper}. This class is responsible
* for rendering the band select overlay and selecting overlaid items via SelectionManager.
+ *
+ * <p>Usage:
+ *
+ * <p><pre>TODO</pre>
*/
-public class BandSelector {
+public class BandSelectionHelper {
static final boolean DEBUG = false;
static final String TAG = "BandController";
- private final Runnable mModelBuilder;
-
private final SelectionHost mHost;
private final StableIdProvider mStableIds;
private final RecyclerView.Adapter<?> mAdapter;
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final Selection mSelection;
private final SelectionPredicate mSelectionPredicate;
private final ContentLock mLock;
private final Runnable mViewScroller;
private final GridModel.OnSelectionChangedListener mGridListener;
- private final List<Runnable> mStartBandSelectListeners = new ArrayList<>();
+ private final List<Runnable> mBandStartedListeners = new ArrayList<>();
@Nullable private Rect mBounds;
@Nullable private Point mCurrentPosition;
@Nullable private Point mOrigin;
@Nullable private GridModel mModel;
- public BandSelector(
+ public BandSelectionHelper(
SelectionHost host,
RecyclerView.Adapter<?> adapter,
StableIdProvider stableIds,
- SelectionManager selectionManager,
+ SelectionHelper selectionManager,
SelectionPredicate selectionPredicate,
ContentLock lock) {
@@ -92,7 +94,7 @@ public class BandSelector {
new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
- BandSelector.this.onScrolled(recyclerView, dx, dy);
+ BandSelectionHelper.this.onScrolled(recyclerView, dx, dy);
}
});
@@ -110,7 +112,7 @@ public class BandSelector {
@Override
public boolean isActive() {
- return BandSelector.this.isActive();
+ return BandSelectionHelper.this.isActive();
}
},
host);
@@ -157,14 +159,15 @@ public class BandSelector {
mSelectionMgr.setProvisionalSelection(updatedSelection);
}
};
+ }
- mModelBuilder = new Runnable() {
- @Override
- public void run() {
- mModel = new GridModel(mHost, mStableIds, mSelectionPredicate);
- mModel.addOnSelectionChangedListener(mGridListener);
- }
- };
+ public void createModel() {
+ if (mModel != null) {
+ mModel.onDestroy();
+ }
+
+ mModel = new GridModel(mHost, mStableIds, mSelectionPredicate);
+ mModel.addOnSelectionChangedListener(mGridListener);
}
@VisibleForTesting
@@ -186,25 +189,27 @@ public class BandSelector {
return isActive();
}
- public void addBandSelectStartedListener(Runnable listener) {
- mStartBandSelectListeners.add(listener);
+ /**
+ * Adds a new listener to be notified when band is created.
+ */
+ public void addOnBandStartedListener(Runnable listener) {
+ mBandStartedListeners.add(listener);
}
- public void removeBandSelectStartedListener(Runnable listener) {
- mStartBandSelectListeners.remove(listener);
+ /**
+ * Removes listener. No-op if listener was not previously installed.
+ */
+ public void removeOnBandStartedListener(Runnable listener) {
+ mBandStartedListeners.remove(listener);
}
/**
- * Handle a change in layout by cleaning up and getting rid of the old model and creating
- * a new model which will track the new layout.
+ * Clients must call this when there are any material changes to the layout of items
+ * in RecyclerView.
*/
- public void handleLayoutChanged() {
+ public void onLayoutChanged() {
if (mModel != null) {
- mModel.removeOnSelectionChangedListener(mGridListener);
- mModel.stopListening();
-
- // build a new model, all fresh and happy.
- mModelBuilder.run();
+ createModel();
}
}
@@ -278,14 +283,14 @@ public class BandSelector {
if (DEBUG) Log.d(TAG, "Starting band select @ " + origin);
mLock.block();
- notifyBandSelectStartedListeners();
+ onBandStarted();
mOrigin = origin;
- mModelBuilder.run(); // Creates a new selection model.
+ createModel();
mModel.startSelection(mOrigin);
}
- private void notifyBandSelectStartedListeners() {
- for (Runnable listener : mStartBandSelectListeners) {
+ private void onBandStarted() {
+ for (Runnable listener : mBandStartedListeners) {
listener.run();
}
}
@@ -325,7 +330,7 @@ public class BandSelector {
if (mSelection.contains(mStableIds.getStableId(firstSelected))) {
// TODO: firstSelected should really be lastSelected, we want to anchor the item
// where the mouse-up occurred.
- mSelectionMgr.setSelectionRangeBegin(firstSelected);
+ mSelectionMgr.anchorRange(firstSelected);
} else {
// TODO: Check if this is really happening.
Log.w(TAG, "First selected by band is NOT in selection!");
diff --git a/src/com/android/documentsui/selection/addons/ContentLock.java b/src/com/android/documentsui/selection/addons/ContentLock.java
index 703b57b8c..2bf1e4ce7 100644
--- a/src/com/android/documentsui/selection/addons/ContentLock.java
+++ b/src/com/android/documentsui/selection/addons/ContentLock.java
@@ -16,7 +16,7 @@
package com.android.documentsui.selection.addons;
import static com.android.documentsui.selection.Shared.DEBUG;
-import static com.android.documentsui.selection.Shared.TAG ;
+import static com.android.documentsui.selection.Shared.TAG;
import android.annotation.MainThread;
import android.annotation.Nullable;
@@ -24,8 +24,8 @@ import android.os.Looper;
import android.util.Log;
/**
- * A lock used by {@link BandSelector} and {@link GestureSelector} to signal to clients when
- * selection is in-progress. While locked, clients should block changes to content.
+ * A lock used by {@link BandSelectionHelper} and {@link GestureSelectionHelper} to signal to
+ * clients when selection is in-progress. While locked, clients should block changes to content.
*/
public class ContentLock {
diff --git a/src/com/android/documentsui/selection/addons/GestureSelector.java b/src/com/android/documentsui/selection/addons/GestureSelectionHelper.java
index 6f5ba70d1..0bf33693d 100644
--- a/src/com/android/documentsui/selection/addons/GestureSelector.java
+++ b/src/com/android/documentsui/selection/addons/GestureSelectionHelper.java
@@ -23,7 +23,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.addons.ViewAutoScroller.Callbacks;
import com.android.documentsui.selection.addons.ViewAutoScroller.ScrollHost;
@@ -33,12 +33,12 @@ import javax.annotation.Nullable;
* Helper class used to intercept events that could cause a gesture multi-select, and keeps
* the interception going if necessary.
*/
-public final class GestureSelector {
+public final class GestureSelectionHelper {
private static final boolean DEBUG = false;
private final String TAG = "GestureSelector";
- private final SelectionManager mSelectionMgr;
+ private final SelectionHelper mSelectionMgr;
private final Runnable mDragScroller;
private final ViewDelegate mView;
private final ContentLock mLock;
@@ -47,8 +47,8 @@ public final class GestureSelector {
private boolean mStarted = false;
private Point mLastInterceptedPoint;
- GestureSelector(
- SelectionManager selectionMgr,
+ GestureSelectionHelper(
+ SelectionHelper selectionMgr,
ViewDelegate view,
Callbacks scrollCallbacks,
ContentLock lock) {
@@ -77,8 +77,8 @@ public final class GestureSelector {
mDragScroller = new ViewAutoScroller(host, scrollCallbacks);
}
- public static GestureSelector create(
- SelectionManager selectionMgr, RecyclerView scrollView, ContentLock lock) {
+ public static GestureSelectionHelper create(
+ SelectionHelper selectionMgr, RecyclerView scrollView, ContentLock lock) {
Callbacks callbacks = new Callbacks() {
@Override
@@ -97,7 +97,7 @@ public final class GestureSelector {
}
};
- GestureSelector helper = new GestureSelector(
+ GestureSelectionHelper helper = new GestureSelectionHelper(
selectionMgr,
new RecyclerViewDelegate(scrollView),
callbacks,
@@ -250,7 +250,7 @@ public final class GestureSelector {
private boolean handleInterceptedMoveEvent(MotionEvent e) {
mLastInterceptedPoint = MotionEvents.getOrigin(e);
if (mStarted) {
- mSelectionMgr.startRangeSelection(mLastStartedItemPos);
+ mSelectionMgr.startRange(mLastStartedItemPos);
// Gesture Selection about to start
mLock.block();
return true;
@@ -309,7 +309,7 @@ public final class GestureSelector {
* @param endPos The adapter position of the end item.
*/
private void doGestureMultiSelect(int endPos) {
- mSelectionMgr.snapProvisionalRangeSelection(endPos);
+ mSelectionMgr.extendProvisionalRange(endPos);
}
private void scrollIfNecessary() {
diff --git a/src/com/android/documentsui/selection/addons/GridModel.java b/src/com/android/documentsui/selection/addons/GridModel.java
index 7f3fac57f..5ea8f4dad 100644
--- a/src/com/android/documentsui/selection/addons/GridModel.java
+++ b/src/com/android/documentsui/selection/addons/GridModel.java
@@ -16,6 +16,8 @@
package com.android.documentsui.selection.addons;
+import static android.support.v4.util.Preconditions.checkArgument;
+
import android.graphics.Point;
import android.graphics.Rect;
import android.support.annotation.VisibleForTesting;
@@ -26,9 +28,9 @@ import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
-import com.android.documentsui.selection.SelectionManager.StableIdProvider;
-import com.android.documentsui.selection.addons.BandSelector.SelectionHost;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
+import com.android.documentsui.selection.SelectionHelper.StableIdProvider;
+import com.android.documentsui.selection.addons.BandSelectionHelper.SelectionHost;
import java.util.ArrayList;
import java.util.Collections;
@@ -290,7 +292,9 @@ final class GridModel {
private void updateSelection(Rect rect) {
int columnStart =
Collections.binarySearch(mColumnBounds, new Limits(rect.left, rect.left));
- assert(columnStart >= 0);
+
+ checkArgument(columnStart >= 0, "Rect doesn't intesect any known column.");
+
int columnEnd = columnStart;
for (int i = columnStart; i < mColumnBounds.size()
@@ -319,8 +323,12 @@ final class GridModel {
*/
private void updateSelection(
int columnStartIndex, int columnEndIndex, int rowStartIndex, int rowEndIndex) {
- if (BandSelector.DEBUG) Log.d(BandSelector.TAG, String.format("updateSelection: %d, %d, %d, %d",
- columnStartIndex, columnEndIndex, rowStartIndex, rowEndIndex));
+
+ if (BandSelectionHelper.DEBUG) {
+ Log.d(BandSelectionHelper.TAG, String.format(
+ "updateSelection: %d, %d, %d, %d",
+ columnStartIndex, columnEndIndex, rowStartIndex, rowEndIndex));
+ }
mSelection.clear();
for (int column = columnStartIndex; column <= columnEndIndex; column++) {
@@ -356,14 +364,9 @@ final class GridModel {
*/
private boolean canSelect(String id) {
// TODO: Simplify the logic, so the check whether we can select is done in one place.
- // Consider injecting ActivityConfig, or move the checks from MultiSelectManager to
+ // Consider injecting ActivityConfig, or move the checks from DefaultSelectionManager to
// Selection.
- for (OnSelectionChangedListener listener : mOnSelectionChangedListeners) {
- if (!mSelectionPredicate.canSetStateForId(id, true)) {
- return false;
- }
- }
- return true;
+ return mSelectionPredicate.canSetStateForId(id, true);
}
/**
@@ -404,8 +407,12 @@ final class GridModel {
mOnSelectionChangedListeners.add(listener);
}
- void removeOnSelectionChangedListener(OnSelectionChangedListener listener) {
- mOnSelectionChangedListeners.remove(listener);
+ /**
+ * Called when {@link BandSelectionHelper} is finished with a GridModel.
+ */
+ void onDestroy() {
+ mOnSelectionChangedListeners.clear();
+ stopListening();
}
/**
@@ -532,7 +539,8 @@ final class GridModel {
}
} else {
Limits limitsBeforeIndex = limitsList.get(~index - 1);
- if (limitsBeforeIndex.lowerLimit <= value && value <= limitsBeforeIndex.upperLimit) {
+ if (limitsBeforeIndex.lowerLimit <= value
+ && value <= limitsBeforeIndex.upperLimit) {
this.type = WITHIN_LIMITS;
this.limitsBeforeCoordinate = limitsList.get(~index - 1);
} else {
diff --git a/tests/common/com/android/documentsui/dirlist/TestDocumentsAdapter.java b/tests/common/com/android/documentsui/dirlist/TestDocumentsAdapter.java
index e8ff9dd76..e2160cf98 100644
--- a/tests/common/com/android/documentsui/dirlist/TestDocumentsAdapter.java
+++ b/tests/common/com/android/documentsui/dirlist/TestDocumentsAdapter.java
@@ -16,10 +16,15 @@
package com.android.documentsui.dirlist;
+import static org.junit.Assert.assertTrue;
+
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.RecyclerView.AdapterDataObserver;
import android.view.ViewGroup;
-import com.android.documentsui.base.EventListener;
import com.android.documentsui.Model.Update;
+import com.android.documentsui.base.EventListener;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.testing.TestEventListener;
import java.util.ArrayList;
@@ -30,11 +35,53 @@ import java.util.List;
*/
public class TestDocumentsAdapter extends DocumentsAdapter {
- List<String> mModelIds = new ArrayList<>();
final TestEventListener<Update> mModelListener = new TestEventListener<>();
+ List<String> mModelIds = new ArrayList<>();
+ private final AdapterDataObserver mAdapterObserver;
+ private final List<Integer> mSelectionChanged = new ArrayList<>();
public TestDocumentsAdapter(List<String> modelIds) {
mModelIds = modelIds;
+
+ mAdapterObserver = new RecyclerView.AdapterDataObserver() {
+
+ @Override
+ public void onChanged() {
+ }
+
+ @Override
+ public void onItemRangeChanged(int startPosition, int itemCount, Object payload) {
+ if (SelectionHelper.SELECTION_CHANGED_MARKER.equals(payload)) {
+ int last = startPosition + itemCount;
+ for (int i = startPosition; i < last; i++) {
+ mSelectionChanged.add(i);
+ }
+ }
+ }
+
+ @Override
+ public void onItemRangeInserted(int startPosition, int itemCount) {
+ }
+
+ @Override
+ public void onItemRangeRemoved(int startPosition, int itemCount) {
+ }
+
+ @Override
+ public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ registerAdapterDataObserver(mAdapterObserver);
+ }
+
+ public void resetSelectionChanged() {
+ mSelectionChanged.clear();
+ }
+
+ public void assertSelectionChanged(int position) {
+ assertTrue(mSelectionChanged.contains(position));
}
@Override
@@ -48,7 +95,8 @@ public class TestDocumentsAdapter extends DocumentsAdapter {
}
@Override
- public void onSelectionStateChanged(String id) {
+ public int getPosition(String id) {
+ return mModelIds.indexOf(id);
}
@Override
diff --git a/tests/common/com/android/documentsui/selection/SelectionProbe.java b/tests/common/com/android/documentsui/selection/SelectionProbe.java
index 108c0343e..799f5e93a 100644
--- a/tests/common/com/android/documentsui/selection/SelectionProbe.java
+++ b/tests/common/com/android/documentsui/selection/SelectionProbe.java
@@ -21,22 +21,22 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
- * Helper class for making assertions against the state of a {@link DefaultSelectionManager} instance and
- * the consistency of states between {@link DefaultSelectionManager} and
- * {@link DefaultSelectionManager.ItemEventCallback}.
+ * Helper class for making assertions against the state of a {@link DefaultSelectionHelper} instance
+ * and the consistency of states between {@link DefaultSelectionHelper} and
+ * {@link DefaultSelectionHelper.ItemEventCallback}.
*/
public final class SelectionProbe {
- private final SelectionManager mMgr;
- private final TestSelectionEventListener mSelectionListener;
+ private final SelectionHelper mMgr;
+ private final TestSelectionObserver mSelectionListener;
- public SelectionProbe(SelectionManager mgr) {
+ public SelectionProbe(SelectionHelper mgr) {
mMgr = mgr;
- mSelectionListener = new TestSelectionEventListener();
- mMgr.addEventListener(mSelectionListener);
+ mSelectionListener = new TestSelectionObserver();
+ mMgr.addObserver(mSelectionListener);
}
- public SelectionProbe(SelectionManager mgr, TestSelectionEventListener selectionListener) {
+ public SelectionProbe(SelectionHelper mgr, TestSelectionObserver selectionListener) {
mMgr = mgr;
mSelectionListener = selectionListener;
}
@@ -100,7 +100,7 @@ public final class SelectionProbe {
public void select(int...positions) {
for (int position : positions) {
- mMgr.toggleSelection(String.valueOf(position));
+ mMgr.select(String.valueOf(position));
}
}
}
diff --git a/tests/common/com/android/documentsui/selection/TestSelectionEventListener.java b/tests/common/com/android/documentsui/selection/TestSelectionObserver.java
index 9bc1625c7..4bcaeecf2 100644
--- a/tests/common/com/android/documentsui/selection/TestSelectionEventListener.java
+++ b/tests/common/com/android/documentsui/selection/TestSelectionObserver.java
@@ -23,11 +23,12 @@ import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Set;
-public class TestSelectionEventListener implements SelectionManager.EventListener {
+public class TestSelectionObserver implements SelectionHelper.SelectionObserver {
private final Set<String> mSelected = new HashSet<>();
private boolean mSelectionChanged = false;
private boolean mSelectionReset = false;
+ private boolean mSelectionRestored = false;
public void reset() {
mSelected.clear();
@@ -58,7 +59,9 @@ public class TestSelectionEventListener implements SelectionManager.EventListene
}
@Override
- public void onSelectionRestored() {}
+ public void onSelectionRestored() {
+ mSelectionRestored = true;
+ }
void assertNoSelection() {
assertTrue(mSelected.isEmpty());
@@ -87,4 +90,8 @@ public class TestSelectionEventListener implements SelectionManager.EventListene
public void assertSelectionReset() {
assertTrue(mSelectionReset);
}
+
+ public void assertSelectionRestored() {
+ assertTrue(mSelectionRestored);
+ }
}
diff --git a/tests/common/com/android/documentsui/testing/SelectionManagers.java b/tests/common/com/android/documentsui/testing/SelectionHelpers.java
index c94df40bd..a3c9b5794 100644
--- a/tests/common/com/android/documentsui/testing/SelectionManagers.java
+++ b/tests/common/com/android/documentsui/testing/SelectionHelpers.java
@@ -16,17 +16,17 @@
package com.android.documentsui.testing;
-import com.android.documentsui.DocsSelectionManager;
+import com.android.documentsui.DocsSelectionHelper;
import com.android.documentsui.dirlist.DocumentsAdapter;
import com.android.documentsui.dirlist.TestDocumentsAdapter;
-import com.android.documentsui.selection.DefaultSelectionManager;
-import com.android.documentsui.selection.DefaultSelectionManager.SelectionMode;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
+import com.android.documentsui.selection.DefaultSelectionHelper;
+import com.android.documentsui.selection.DefaultSelectionHelper.SelectionMode;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
import java.util.Collections;
import java.util.List;
-public class SelectionManagers {
+public class SelectionHelpers {
public static final SelectionPredicate CAN_SET_ANYTHING = new SelectionPredicate() {
@Override
@@ -40,26 +40,26 @@ public class SelectionManagers {
}
};
- private SelectionManagers() {}
+ private SelectionHelpers() {}
- public static DocsSelectionManager createTestInstance() {
+ public static DocsSelectionHelper createTestInstance() {
return createTestInstance(Collections.emptyList());
}
- public static DocsSelectionManager createTestInstance(List<String> docs) {
- return createTestInstance(docs, DefaultSelectionManager.MODE_MULTIPLE);
+ public static DocsSelectionHelper createTestInstance(List<String> docs) {
+ return createTestInstance(docs, DefaultSelectionHelper.MODE_MULTIPLE);
}
- public static DocsSelectionManager createTestInstance(
+ public static DocsSelectionHelper createTestInstance(
List<String> docs, @SelectionMode int mode) {
return createTestInstance(new TestDocumentsAdapter(docs), mode, CAN_SET_ANYTHING);
}
- public static DocsSelectionManager createTestInstance(
+ public static DocsSelectionHelper createTestInstance(
DocumentsAdapter adapter, @SelectionMode int mode, SelectionPredicate canSetState) {
- DocsSelectionManager manager = mode == DefaultSelectionManager.MODE_SINGLE
- ? DocsSelectionManager.createSingleSelect()
- : DocsSelectionManager.createMultiSelect();
+ DocsSelectionHelper manager = mode == DefaultSelectionHelper.MODE_SINGLE
+ ? DocsSelectionHelper.createSingleSelect()
+ : DocsSelectionHelper.createMultiSelect();
manager.reset(adapter, adapter, canSetState);
return manager;
diff --git a/tests/common/com/android/documentsui/testing/TestEnv.java b/tests/common/com/android/documentsui/testing/TestEnv.java
index 213912896..40b5e0aee 100644
--- a/tests/common/com/android/documentsui/testing/TestEnv.java
+++ b/tests/common/com/android/documentsui/testing/TestEnv.java
@@ -20,7 +20,7 @@ import android.provider.DocumentsContract.Document;
import android.support.test.InstrumentationRegistry;
import android.test.mock.MockContentResolver;
-import com.android.documentsui.DocsSelectionManager;
+import com.android.documentsui.DocsSelectionHelper;
import com.android.documentsui.FocusManager;
import com.android.documentsui.Injector;
import com.android.documentsui.archives.ArchivesProvider;
@@ -64,7 +64,7 @@ public class TestEnv {
public final TestDialogController dialogs = new TestDialogController();
public final TestModel model;
public final TestModel archiveModel;
- public final DocsSelectionManager selectionMgr;
+ public final DocsSelectionHelper selectionMgr;
public final TestSearchViewManager searchViewManager;
public final Injector<?> injector;
public final Features features;
@@ -78,7 +78,7 @@ public class TestEnv {
mExecutor = new TestScheduledExecutorService();
model = new TestModel(authority, features);
archiveModel = new TestModel(ArchivesProvider.AUTHORITY, features);
- selectionMgr = SelectionManagers.createTestInstance();
+ selectionMgr = SelectionHelpers.createTestInstance();
searchViewManager = new TestSearchViewManager();
injector = new Injector(
features,
diff --git a/tests/common/com/android/documentsui/testing/TestModel.java b/tests/common/com/android/documentsui/testing/TestModel.java
index 517b1f47f..0df9b3a1d 100644
--- a/tests/common/com/android/documentsui/testing/TestModel.java
+++ b/tests/common/com/android/documentsui/testing/TestModel.java
@@ -53,6 +53,7 @@ public class TestModel extends Model {
reset();
}
+ @Override
public void reset() {
mLastId = 0;
mCursor = new MatrixCursor(COLUMNS);
diff --git a/tests/unit/com/android/documentsui/DocsSelectionManagerTest.java b/tests/unit/com/android/documentsui/DocsSelectionHelperTest.java
index 85ea3738e..a1d877824 100644
--- a/tests/unit/com/android/documentsui/DocsSelectionManagerTest.java
+++ b/tests/unit/com/android/documentsui/DocsSelectionHelperTest.java
@@ -23,12 +23,12 @@ import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.v7.widget.RecyclerView.Adapter;
-import com.android.documentsui.DocsSelectionManager.DelegateFactory;
-import com.android.documentsui.selection.DefaultSelectionManager;
+import com.android.documentsui.DocsSelectionHelper.DelegateFactory;
+import com.android.documentsui.selection.DefaultSelectionHelper;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.selection.SelectionManager;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
-import com.android.documentsui.selection.SelectionManager.StableIdProvider;
+import com.android.documentsui.selection.SelectionHelper;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
+import com.android.documentsui.selection.SelectionHelper.StableIdProvider;
import org.junit.Before;
import org.junit.Test;
@@ -45,9 +45,9 @@ import java.util.Set;
*/
@RunWith(AndroidJUnit4.class)
@SmallTest
-public class DocsSelectionManagerTest {
+public class DocsSelectionHelperTest {
- private DocsSelectionManager mSelectionMgr;
+ private DocsSelectionHelper mSelectionMgr;
private List<TestSelectionManager> mCreated;
private DelegateFactory mFactory;
@@ -68,7 +68,7 @@ public class DocsSelectionManagerTest {
}
};
- mSelectionMgr = new DocsSelectionManager(mFactory, DefaultSelectionManager.MODE_MULTIPLE);
+ mSelectionMgr = new DocsSelectionHelper(mFactory, DefaultSelectionHelper.MODE_MULTIPLE);
}
@Test
@@ -104,7 +104,7 @@ public class DocsSelectionManagerTest {
assertEquals(count, mCreated.size());
}
- private static final class TestSelectionManager implements SelectionManager {
+ private static final class TestSelectionManager implements SelectionHelper {
private boolean mCleared;
private Map<String, Boolean> mSelected = new HashMap<>();
@@ -122,7 +122,7 @@ public class DocsSelectionManagerTest {
}
@Override
- public void addEventListener(EventListener listener) {
+ public void addObserver(SelectionObserver listener) {
throw new UnsupportedOperationException();
}
@@ -142,6 +142,11 @@ public class DocsSelectionManagerTest {
}
@Override
+ public boolean isSelected(String id) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
public void restoreSelection(Selection other) {
throw new UnsupportedOperationException();
}
@@ -160,42 +165,42 @@ public class DocsSelectionManagerTest {
}
@Override
- public void toggleSelection(String modelId) {
+ public boolean select(String itemId) {
throw new UnsupportedOperationException();
}
@Override
- public void startRangeSelection(int pos) {
+ public boolean deselect(String itemId) {
throw new UnsupportedOperationException();
}
@Override
- public void snapRangeSelection(int pos) {
+ public void startRange(int pos) {
throw new UnsupportedOperationException();
}
@Override
- public void formNewSelectionRange(int startPos, int endPos) {
+ public void extendRange(int pos) {
throw new UnsupportedOperationException();
}
@Override
- public void endRangeSelection() {
+ public void endRange() {
throw new UnsupportedOperationException();
}
@Override
- public boolean isRangeSelectionActive() {
+ public boolean isRangeActive() {
throw new UnsupportedOperationException();
}
@Override
- public void setSelectionRangeBegin(int position) {
+ public void anchorRange(int position) {
throw new UnsupportedOperationException();
}
@Override
- public void setProvisionalSelection(Set<String> newSelection) {
+ public void extendProvisionalRange(int pos) {
throw new UnsupportedOperationException();
}
@@ -210,7 +215,7 @@ public class DocsSelectionManagerTest {
}
@Override
- public void snapProvisionalRangeSelection(int pos) {
+ public void setProvisionalSelection(Set<String> newSelection) {
throw new UnsupportedOperationException();
}
}
diff --git a/tests/unit/com/android/documentsui/FocusManagerTest.java b/tests/unit/com/android/documentsui/FocusManagerTest.java
index 9c5796225..cd71db6cd 100644
--- a/tests/unit/com/android/documentsui/FocusManagerTest.java
+++ b/tests/unit/com/android/documentsui/FocusManagerTest.java
@@ -21,9 +21,9 @@ import android.test.suitebuilder.annotation.SmallTest;
import com.android.documentsui.base.Features;
import com.android.documentsui.dirlist.TestData;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.testing.TestModel;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestFeatures;
import com.android.documentsui.testing.TestRecyclerView;
@@ -39,13 +39,13 @@ public class FocusManagerTest extends AndroidTestCase {
private FocusManager mManager;
private TestRecyclerView mView;
- private SelectionManager mSelectionMgr;
+ private SelectionHelper mSelectionMgr;
private TestFeatures mFeatures;
@Override
public void setUp() throws Exception {
mView = TestRecyclerView.create(ITEMS);
- mSelectionMgr = SelectionManagers.createTestInstance(ITEMS);
+ mSelectionMgr = SelectionHelpers.createTestInstance(ITEMS);
mFeatures = new TestFeatures();
mManager = new FocusManager(mFeatures, mSelectionMgr, null, null, 0)
.reset(mView, new TestModel(TEST_AUTHORITY, mFeatures));
@@ -68,13 +68,13 @@ public class FocusManagerTest extends AndroidTestCase {
public void testFocusDirectoryList_noItemsToFocus() {
mView = TestRecyclerView.create(new ArrayList<>());
mManager = new FocusManager(
- mFeatures, SelectionManagers.createTestInstance(), null, null, 0)
+ mFeatures, SelectionHelpers.createTestInstance(), null, null, 0)
.reset(mView, new TestModel(TEST_AUTHORITY, mFeatures));
assertFalse(mManager.focusDirectoryList());
}
public void testFocusDirectoryList_hasSelection() {
- mSelectionMgr.toggleSelection("0");
+ mSelectionMgr.select("0");
assertFalse(mManager.focusDirectoryList());
}
}
diff --git a/tests/unit/com/android/documentsui/SharedInputHandlerTest.java b/tests/unit/com/android/documentsui/SharedInputHandlerTest.java
index 0f5c28064..9c28094a5 100644
--- a/tests/unit/com/android/documentsui/SharedInputHandlerTest.java
+++ b/tests/unit/com/android/documentsui/SharedInputHandlerTest.java
@@ -27,8 +27,8 @@ import android.view.MotionEvent;
import com.android.documentsui.base.Procedure;
import com.android.documentsui.dirlist.TestFocusHandler;
-import com.android.documentsui.selection.SelectionManager;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.selection.SelectionHelper;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestFeatures;
import org.junit.Before;
@@ -40,7 +40,7 @@ import org.junit.runner.RunWith;
public class SharedInputHandlerTest {
private SharedInputHandler mSharedInputHandler;
- private SelectionManager mSelectionMgr = SelectionManagers.createTestInstance();
+ private SelectionHelper mSelectionMgr = SelectionHelpers.createTestInstance();
private TestFeatures mFeatures = new TestFeatures();
private TestFocusHandler mFocusHandler = new TestFocusHandler();
private boolean mDirPopHappened;
@@ -75,10 +75,10 @@ public class SharedInputHandlerTest {
@Test
public void testBackButton_CancelsSearch() {
- mSelectionMgr.toggleSelection("1");
+ mSelectionMgr.select("1");
mSharedInputHandler = new SharedInputHandler(
new TestFocusHandler(),
- SelectionManagers.createTestInstance(),
+ SelectionHelpers.createTestInstance(),
() -> {
mCanceledSearch = true;
return true;
@@ -96,7 +96,7 @@ public class SharedInputHandlerTest {
@Test
public void testBackButton_ClearsSelection() {
- mSelectionMgr.toggleSelection("1");
+ mSelectionMgr.select("1");
assertEquals(mSelectionMgr.getSelection().size(), 1);
KeyEvent backEvent =
new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, 0, 0);
@@ -120,10 +120,10 @@ public class SharedInputHandlerTest {
@Test
public void testEscButton_CancelsSearch() {
- mSelectionMgr.toggleSelection("1");
+ mSelectionMgr.select("1");
mSharedInputHandler = new SharedInputHandler(
new TestFocusHandler(),
- SelectionManagers.createTestInstance(),
+ SelectionHelpers.createTestInstance(),
() -> {
mCanceledSearch = true;
return true;
@@ -141,7 +141,7 @@ public class SharedInputHandlerTest {
@Test
public void testEscButton_ClearsSelection() {
- mSelectionMgr.toggleSelection("1");
+ mSelectionMgr.select("1");
assertEquals(mSelectionMgr.getSelection().size(), 1);
KeyEvent escapeEvent =
new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_ESCAPE, 0, 0);
diff --git a/tests/unit/com/android/documentsui/dirlist/DirectoryAddonsAdapterTest.java b/tests/unit/com/android/documentsui/dirlist/DirectoryAddonsAdapterTest.java
index 68169bc36..c25e43feb 100644
--- a/tests/unit/com/android/documentsui/dirlist/DirectoryAddonsAdapterTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/DirectoryAddonsAdapterTest.java
@@ -66,6 +66,17 @@ public class DirectoryAddonsAdapterTest extends AndroidTestCase {
assertEquals(mEnv.model.getItemCount() + 1, mAdapter.getItemCount());
}
+ public void testGetPosition() {
+ mEnv.model.createFolder("a"); // id will be "1"...derived from insert position.
+ mEnv.model.createFile("b"); // id will be "2"
+ mEnv.model.update();
+
+ assertEquals(0, mAdapter.getPosition("1"));
+ // adapter inserts a view between item 0 and 1 to force layout
+ // break between folders and files. This is reflected by an offset position.
+ assertEquals(2, mAdapter.getPosition("2"));
+ }
+
// Tests that the item count is correct for a directory containing only subdirs.
public void testItemCount_allDirs() {
String[] names = {"Trader Joe's", "Alphabeta", "Lucky", "Vons", "Gelson's"};
@@ -187,8 +198,11 @@ public class DirectoryAddonsAdapterTest extends AndroidTestCase {
}
private static class DummyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+ @Override
public int getItemCount() { return 0; }
+ @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {}
+ @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}
diff --git a/tests/unit/com/android/documentsui/dirlist/DragHostTest.java b/tests/unit/com/android/documentsui/dirlist/DragHostTest.java
index 4331ac401..7db69dca3 100644
--- a/tests/unit/com/android/documentsui/dirlist/DragHostTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/DragHostTest.java
@@ -28,10 +28,10 @@ import android.view.View;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.files.TestActivity;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.testing.ClipDatas;
import com.android.documentsui.testing.DragEvents;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestDragAndDropManager;
import com.android.documentsui.testing.TestEnv;
@@ -55,7 +55,7 @@ public class DragHostTest {
private TestDialogController mDialogs;
private DragHost<?> dragHost;
private TestDragAndDropManager mDragAndDropManager;
- private SelectionManager mSelectionMgr;
+ private SelectionHelper mSelectionMgr;
private boolean mIsDocumentView;
private DocumentHolder mNextDocumentHolder;
private DocumentInfo mNextDocumentInfo;
@@ -66,7 +66,7 @@ public class DragHostTest {
mActivity = TestActivity.create(mEnv);
mDialogs = new TestDialogController();
mDragAndDropManager = new TestDragAndDropManager();
- mSelectionMgr = SelectionManagers.createTestInstance(ITEMS);
+ mSelectionMgr = SelectionHelpers.createTestInstance(ITEMS);
mActionHandler = new TestActionHandler();
dragHost = new DragHost<>(
mActivity,
diff --git a/tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java b/tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java
index 37e597164..e917761ea 100644
--- a/tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java
@@ -26,7 +26,7 @@ import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent;
import android.view.View;
-import com.android.documentsui.DocsSelectionManager;
+import com.android.documentsui.DocsSelectionHelper;
import com.android.documentsui.MenuManager.SelectionDetails;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.Events;
@@ -35,7 +35,7 @@ import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.DragStartListener.RuntimeDragStartListener;
import com.android.documentsui.selection.MutableSelection;
import com.android.documentsui.selection.Selection;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestDragAndDropManager;
import com.android.documentsui.testing.TestEventDetailsLookup;
import com.android.documentsui.testing.TestEvents;
@@ -55,7 +55,7 @@ public class DragStartListenerTest {
private RuntimeDragStartListener mListener;
private TestEvents.Builder mEvent;
- private DocsSelectionManager mMultiSelectManager;
+ private DocsSelectionHelper mSelectionMgr;
private TestEventDetailsLookup mDocLookup;
private SelectionDetails mSelectionDetails;
private String mViewModelId;
@@ -63,7 +63,7 @@ public class DragStartListenerTest {
@Before
public void setUp() throws Exception {
- mMultiSelectManager = SelectionManagers.createTestInstance();
+ mSelectionMgr = SelectionHelpers.createTestInstance();
mManager = new TestDragAndDropManager();
mSelectionDetails = new TestSelectionDetails();
mDocLookup = new TestEventDetailsLookup();
@@ -80,7 +80,7 @@ public class DragStartListenerTest {
null, // icon helper
state,
mDocLookup,
- mMultiSelectManager,
+ mSelectionMgr,
mSelectionDetails,
// view finder
(float x, float y) -> {
@@ -158,7 +158,7 @@ public class DragStartListenerTest {
MutableSelection selection = new MutableSelection();
selection.add("1234");
selection.add("5678");
- mMultiSelectManager.replaceSelection(selection);
+ mSelectionMgr.replaceSelection(selection);
selection = mListener.getSelectionToBeCopied("1234",
mEvent.action(MotionEvent.ACTION_MOVE).build());
@@ -171,21 +171,21 @@ public class DragStartListenerTest {
public void testDragStart_newNonSelectedItem() {
MutableSelection selection = new MutableSelection();
selection.add("5678");
- mMultiSelectManager.replaceSelection(selection);
+ mSelectionMgr.replaceSelection(selection);
selection = mListener.getSelectionToBeCopied("1234",
mEvent.action(MotionEvent.ACTION_MOVE).build());
assertTrue(selection.size() == 1);
assertTrue(selection.contains("1234"));
// After this, selection should be cleared
- assertFalse(mMultiSelectManager.hasSelection());
+ assertFalse(mSelectionMgr.hasSelection());
}
@Test
public void testCtrlDragStart_newNonSelectedItem() {
MutableSelection selection = new MutableSelection();
selection.add("5678");
- mMultiSelectManager.replaceSelection(selection);
+ mSelectionMgr.replaceSelection(selection);
selection = mListener.getSelectionToBeCopied("1234",
mEvent.action(MotionEvent.ACTION_MOVE).ctrl().build());
diff --git a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_KeyboardTest.java b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_KeyboardTest.java
index 976ccbecb..746c94e36 100644
--- a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_KeyboardTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_KeyboardTest.java
@@ -23,9 +23,9 @@ import android.support.test.runner.AndroidJUnit4;
import android.view.KeyEvent;
import android.view.MotionEvent;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.SelectionProbe;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestEventDetailsLookup;
import com.android.documentsui.testing.TestEventHandler;
@@ -57,7 +57,7 @@ public final class UserInputHandler_KeyboardTest {
@Before
public void setUp() {
- SelectionManager selectionMgr = SelectionManagers.createTestInstance(ITEMS);
+ SelectionHelper selectionMgr = SelectionHelpers.createTestInstance(ITEMS);
mActionHandler = new TestActionHandler();
mDetailsLookup = new TestEventDetailsLookup();
diff --git a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_MouseTest.java b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_MouseTest.java
index ebd57e4e2..3fc88d448 100644
--- a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_MouseTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_MouseTest.java
@@ -30,9 +30,9 @@ import android.support.test.runner.AndroidJUnit4;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.SelectionProbe;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestDocumentDetails;
import com.android.documentsui.testing.TestEventDetailsLookup;
@@ -58,7 +58,7 @@ public final class UserInputHandler_MouseTest {
private TestEventDetailsLookup mDetailsLookup;
private TestFocusHandler mFocusHandler;
private SelectionProbe mSelection;
- private SelectionManager mSelectionMgr;
+ private SelectionHelper mSelectionMgr;
private TestPredicate<DocumentDetails> mCanSelect;
private TestEventHandler<MotionEvent> mContextMenuClickHandler;
private TestEventHandler<MotionEvent> mDragAndDropHandler;
@@ -70,7 +70,7 @@ public final class UserInputHandler_MouseTest {
@Before
public void setUp() {
- mSelectionMgr = SelectionManagers.createTestInstance(ITEMS);
+ mSelectionMgr = SelectionHelpers.createTestInstance(ITEMS);
mActionHandler = new TestActionHandler();
mDetailsLookup = new TestEventDetailsLookup();
mSelection = new SelectionProbe(mSelectionMgr);
@@ -189,7 +189,7 @@ public final class UserInputHandler_MouseTest {
mFocusHandler.focusModelId = "7";
// This is a hack-y test, since the real FocusManager would've set range begin itself.
- mSelectionMgr.setSelectionRangeBegin(7);
+ mSelectionMgr.anchorRange(7);
mSelection.assertNoSelection();
mDetailsLookup.initAt(11);
diff --git a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_RangeTest.java b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_RangeTest.java
index 2e0cc56a5..0c6e08294 100644
--- a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_RangeTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_RangeTest.java
@@ -24,9 +24,9 @@ import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.SelectionProbe;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestEventDetailsLookup;
import com.android.documentsui.testing.TestEventHandler;
@@ -63,7 +63,7 @@ public final class UserInputHandler_RangeTest {
@Before
public void setUp() {
- SelectionManager selectionMgr = SelectionManagers.createTestInstance(ITEMS);
+ SelectionHelper selectionMgr = SelectionHelpers.createTestInstance(ITEMS);
mActionHandler = new TestActionHandler();
mDetailsLookup = new TestEventDetailsLookup();
mFocusHandler = new TestFocusHandler();
diff --git a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_TouchTest.java b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_TouchTest.java
index 346f11b9e..e7eb8f419 100644
--- a/tests/unit/com/android/documentsui/dirlist/UserInputHandler_TouchTest.java
+++ b/tests/unit/com/android/documentsui/dirlist/UserInputHandler_TouchTest.java
@@ -24,9 +24,9 @@ import android.support.test.runner.AndroidJUnit4;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
-import com.android.documentsui.selection.SelectionManager;
+import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.SelectionProbe;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestEventDetailsLookup;
import com.android.documentsui.testing.TestEventHandler;
@@ -45,6 +45,7 @@ public final class UserInputHandler_TouchTest {
private static final List<String> ITEMS = TestData.create(100);
private UserInputHandler mInputHandler;
+ private SelectionHelper mSelectionMgr;
private TestActionHandler mActionHandler;
private TestEventDetailsLookup mDetailsLookup;
private SelectionProbe mSelection;
@@ -54,14 +55,14 @@ public final class UserInputHandler_TouchTest {
private TestEventHandler<MotionEvent> mGestureSelectHandler;
private TestEventHandler<Void> mPerformHapticFeedback;
+
@Before
public void setUp() {
- SelectionManager selectionMgr = SelectionManagers.createTestInstance(ITEMS);
-
+ mSelectionMgr = SelectionHelpers.createTestInstance(ITEMS);
mActionHandler = new TestActionHandler();
mDetailsLookup = new TestEventDetailsLookup();
- mSelection = new SelectionProbe(selectionMgr);
+ mSelection = new SelectionProbe(mSelectionMgr);
mCanSelect = new TestPredicate<>();
mRightClickHandler = new TestEventHandler<>();
mDragAndDropHandler = new TestEventHandler<>();
@@ -71,7 +72,7 @@ public final class UserInputHandler_TouchTest {
mInputHandler = new UserInputHandler(
mActionHandler,
new TestFocusHandler(),
- selectionMgr,
+ mSelectionMgr,
mDetailsLookup,
mCanSelect,
mRightClickHandler::accept,
@@ -116,8 +117,7 @@ public final class UserInputHandler_TouchTest {
@Test
public void testSelectionHotspot_UnselectsSelectedItem() {
- mDetailsLookup.initAt(11);
- mInputHandler.onLongPress(TAP);
+ mSelectionMgr.select("11");
mDetailsLookup.initAt(11).setInItemSelectRegion(true);
mInputHandler.onSingleTapUp(TAP);
@@ -153,8 +153,9 @@ public final class UserInputHandler_TouchTest {
@Test
public void testTap_UnselectsSelectedItem() {
+ mSelectionMgr.select("11");
+
mDetailsLookup.initAt(11);
- mInputHandler.onLongPress(TAP);
mInputHandler.onSingleTapUp(TAP);
mSelection.assertNoSelection();
@@ -162,9 +163,12 @@ public final class UserInputHandler_TouchTest {
@Test
public void testTapOff_ClearsSelection() {
+ mSelectionMgr.select("7");
mDetailsLookup.initAt(7);
+
mInputHandler.onLongPress(TAP);
+ mSelectionMgr.select("11");
mDetailsLookup.initAt(11);
mInputHandler.onSingleTapUp(TAP);
diff --git a/tests/unit/com/android/documentsui/files/MenuManagerTest.java b/tests/unit/com/android/documentsui/files/MenuManagerTest.java
index 6180993e2..3a4201545 100644
--- a/tests/unit/com/android/documentsui/files/MenuManagerTest.java
+++ b/tests/unit/com/android/documentsui/files/MenuManagerTest.java
@@ -32,8 +32,8 @@ import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.TestContext;
import com.android.documentsui.dirlist.TestData;
-import com.android.documentsui.selection.SelectionManager;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.selection.SelectionHelper;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestDirectoryDetails;
import com.android.documentsui.testing.TestEnv;
import com.android.documentsui.testing.TestFeatures;
@@ -112,7 +112,7 @@ public final class MenuManagerTest {
private State state = new State();
private MenuManager mgr;
private TestActivity activity = TestActivity.create(TestEnv.create());
- private SelectionManager selectionManager;
+ private SelectionHelper selectionManager;
@Before
public void setUp() {
@@ -176,8 +176,8 @@ public final class MenuManagerTest {
dirDetails = new TestDirectoryDetails();
testSearchManager = new TestSearchViewManager();
preferences = new TestScopedPreferences();
- selectionManager = SelectionManagers.createTestInstance(TestData.create(1));
- selectionManager.toggleSelection("0");
+ selectionManager = SelectionHelpers.createTestInstance(TestData.create(1));
+ selectionManager.select("0");
mgr = new MenuManager(
features,
diff --git a/tests/unit/com/android/documentsui/picker/ActionHandlerTest.java b/tests/unit/com/android/documentsui/picker/ActionHandlerTest.java
index 8a502bf9e..5d4156558 100644
--- a/tests/unit/com/android/documentsui/picker/ActionHandlerTest.java
+++ b/tests/unit/com/android/documentsui/picker/ActionHandlerTest.java
@@ -80,7 +80,7 @@ public class ActionHandlerTest {
mEnv.dialogs.confirmNext();
- mEnv.selectionMgr.toggleSelection("1");
+ mEnv.selectionMgr.select("1");
AsyncTask.setDefaultExecutor(mEnv.mExecutor);
}
diff --git a/tests/unit/com/android/documentsui/selection/DefaultSelectionManagerTest.java b/tests/unit/com/android/documentsui/selection/DefaultSelectionHelperTest.java
index ae572c7ac..572613596 100644
--- a/tests/unit/com/android/documentsui/selection/DefaultSelectionManagerTest.java
+++ b/tests/unit/com/android/documentsui/selection/DefaultSelectionHelperTest.java
@@ -15,6 +15,7 @@
*/
package com.android.documentsui.selection;
+import static org.junit.Assert.assertFalse;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -22,7 +23,7 @@ import android.util.SparseBooleanArray;
import com.android.documentsui.dirlist.TestData;
import com.android.documentsui.dirlist.TestDocumentsAdapter;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
import org.junit.Before;
import org.junit.Test;
@@ -35,19 +36,19 @@ import java.util.Set;
@RunWith(AndroidJUnit4.class)
@SmallTest
-public class DefaultSelectionManagerTest {
+public class DefaultSelectionHelperTest {
private static final List<String> ITEMS = TestData.create(100);
private final Set<String> mIgnored = new HashSet<>();
private TestDocumentsAdapter mAdapter;
- private DefaultSelectionManager mManager;
- private TestSelectionEventListener mListener;
+ private DefaultSelectionHelper mManager;
+ private TestSelectionObserver mListener;
private SelectionProbe mSelection;
@Before
public void setUp() throws Exception {
- mListener = new TestSelectionEventListener();
+ mListener = new TestSelectionObserver();
mAdapter = new TestDocumentsAdapter(ITEMS);
SelectionPredicate canSelect = new SelectionPredicate() {
@@ -61,9 +62,9 @@ public class DefaultSelectionManagerTest {
throw new UnsupportedOperationException("Not implemented.");
}
};
- mManager = new DefaultSelectionManager(
- DefaultSelectionManager.MODE_MULTIPLE, mAdapter, mAdapter, canSelect);
- mManager.addEventListener(mListener);
+ mManager = new DefaultSelectionHelper(
+ DefaultSelectionHelper.MODE_MULTIPLE, mAdapter, mAdapter, canSelect);
+ mManager.addObserver(mListener);
mSelection = new SelectionProbe(mManager, mListener);
@@ -71,37 +72,63 @@ public class DefaultSelectionManagerTest {
}
@Test
- public void testSelection() {
- // Check selection.
- mManager.toggleSelection(ITEMS.get(7));
+ public void testSelect() {
+ mManager.select(ITEMS.get(7));
+
mSelection.assertSelection(7);
- // Check deselection.
- mManager.toggleSelection(ITEMS.get(7));
+ }
+
+ @Test
+ public void testDeselect() {
+ mManager.select(ITEMS.get(7));
+ mManager.deselect(ITEMS.get(7));
+
mSelection.assertNoSelection();
}
@Test
public void testSelection_DoNothingOnUnselectableItem() {
mIgnored.add(ITEMS.get(7));
+ boolean selected = mManager.select(ITEMS.get(7));
- mManager.toggleSelection(ITEMS.get(7));
+ assertFalse(selected);
mSelection.assertNoSelection();
}
@Test
- public void testSelection_NotifiesSelectionChanged() {
- // Selection should notify.
- mManager.toggleSelection(ITEMS.get(7));
+ public void testSelect_NotifiesListenersOfChange() {
+ mManager.select(ITEMS.get(7));
+
mListener.assertSelectionChanged();
- // Deselection should notify.
- mManager.toggleSelection(ITEMS.get(7));
+ }
+
+
+ @Test
+ public void testSelect_NotifiesAdapterOfSelect() {
+ mManager.select(ITEMS.get(7));
+
+ mAdapter.assertSelectionChanged(7);
+ }
+
+ @Test
+ public void testSelect_NotifiesAdapterOfDeselect() {
+ mManager.select(ITEMS.get(7));
+ mAdapter.resetSelectionChanged();
+ mManager.deselect(ITEMS.get(7));
+ mAdapter.assertSelectionChanged(7);
+ }
+
+ @Test
+ public void testDeselect_NotifiesSelectionChanged() {
+ mManager.select(ITEMS.get(7));
+ mManager.deselect(ITEMS.get(7));
+
mListener.assertSelectionChanged();
}
@Test
public void testSelection_PersistsOnUpdate() {
- mManager.toggleSelection(ITEMS.get(7));
-
+ mManager.select(ITEMS.get(7));
mAdapter.updateTestModelIds(ITEMS);
mSelection.assertSelection(7);
@@ -109,8 +136,8 @@ public class DefaultSelectionManagerTest {
@Test
public void testSelection_IntersectsWithNewDataSet() {
- mManager.toggleSelection(ITEMS.get(99));
- mManager.toggleSelection(ITEMS.get(7));
+ mManager.select(ITEMS.get(99));
+ mManager.select(ITEMS.get(7));
mAdapter.updateTestModelIds(TestData.create(50));
@@ -137,8 +164,8 @@ public class DefaultSelectionManagerTest {
@Test
public void testRangeSelection() {
- mManager.startRangeSelection(15);
- mManager.snapRangeSelection(19);
+ mManager.startRange(15);
+ mManager.extendRange(19);
mSelection.assertRangeSelection(15, 19);
}
@@ -146,8 +173,8 @@ public class DefaultSelectionManagerTest {
public void testRangeSelection_SkipUnselectableItem() {
mIgnored.add(ITEMS.get(17));
- mManager.startRangeSelection(15);
- mManager.snapRangeSelection(19);
+ mManager.startRange(15);
+ mManager.extendRange(19);
mSelection.assertRangeSelected(15, 16);
mSelection.assertNotSelected(17);
@@ -156,35 +183,35 @@ public class DefaultSelectionManagerTest {
@Test
public void testRangeSelection_snapExpand() {
- mManager.startRangeSelection(15);
- mManager.snapRangeSelection(19);
- mManager.snapRangeSelection(27);
+ mManager.startRange(15);
+ mManager.extendRange(19);
+ mManager.extendRange(27);
mSelection.assertRangeSelection(15, 27);
}
@Test
public void testRangeSelection_snapContract() {
- mManager.startRangeSelection(15);
- mManager.snapRangeSelection(27);
- mManager.snapRangeSelection(19);
+ mManager.startRange(15);
+ mManager.extendRange(27);
+ mManager.extendRange(19);
mSelection.assertRangeSelection(15, 19);
}
@Test
public void testRangeSelection_snapInvert() {
- mManager.startRangeSelection(15);
- mManager.snapRangeSelection(27);
- mManager.snapRangeSelection(3);
+ mManager.startRange(15);
+ mManager.extendRange(27);
+ mManager.extendRange(3);
mSelection.assertRangeSelection(3, 15);
}
@Test
public void testRangeSelection_multiple() {
- mManager.startRangeSelection(15);
- mManager.snapRangeSelection(27);
- mManager.endRangeSelection();
- mManager.startRangeSelection(42);
- mManager.snapRangeSelection(57);
+ mManager.startRange(15);
+ mManager.extendRange(27);
+ mManager.endRange();
+ mManager.startRange(42);
+ mManager.extendRange(57);
mSelection.assertSelectionSize(29);
mSelection.assertRangeSelected(15, 27);
mSelection.assertRangeSelected(42, 57);
@@ -192,21 +219,21 @@ public class DefaultSelectionManagerTest {
@Test
public void testProvisionalRangeSelection() {
- mManager.startRangeSelection(13);
- mManager.snapProvisionalRangeSelection(15);
+ mManager.startRange(13);
+ mManager.extendProvisionalRange(15);
mSelection.assertRangeSelection(13, 15);
mManager.getSelection().mergeProvisionalSelection();
- mManager.endRangeSelection();
+ mManager.endRange();
mSelection.assertSelectionSize(3);
}
@Test
public void testProvisionalRangeSelection_endEarly() {
- mManager.startRangeSelection(13);
- mManager.snapProvisionalRangeSelection(15);
+ mManager.startRange(13);
+ mManager.extendProvisionalRange(15);
mSelection.assertRangeSelection(13, 15);
- mManager.endRangeSelection();
+ mManager.endRange();
// If we end range selection prematurely for provision selection, nothing should be selected
// except the first item
mSelection.assertSelectionSize(1);
@@ -214,24 +241,24 @@ public class DefaultSelectionManagerTest {
@Test
public void testProvisionalRangeSelection_snapExpand() {
- mManager.startRangeSelection(13);
- mManager.snapProvisionalRangeSelection(15);
+ mManager.startRange(13);
+ mManager.extendProvisionalRange(15);
mSelection.assertRangeSelection(13, 15);
mManager.getSelection().mergeProvisionalSelection();
- mManager.snapRangeSelection(18);
+ mManager.extendRange(18);
mSelection.assertRangeSelection(13, 18);
}
@Test
public void testCombinationRangeSelection_IntersectsOldSelection() {
- mManager.startRangeSelection(13);
- mManager.snapRangeSelection(15);
+ mManager.startRange(13);
+ mManager.extendRange(15);
mSelection.assertRangeSelection(13, 15);
- mManager.startRangeSelection(11);
- mManager.snapProvisionalRangeSelection(18);
+ mManager.startRange(11);
+ mManager.extendProvisionalRange(18);
mSelection.assertRangeSelected(11, 18);
- mManager.endRangeSelection();
+ mManager.endRange();
mSelection.assertRangeSelected(13, 15);
mSelection.assertRangeSelected(11, 11);
mSelection.assertSelectionSize(4);
@@ -317,8 +344,8 @@ public class DefaultSelectionManagerTest {
@Test
public void testProvisionalSelection_Cancel() {
- mManager.toggleSelection(ITEMS.get(1));
- mManager.toggleSelection(ITEMS.get(2));
+ mManager.select(ITEMS.get(1));
+ mManager.select(ITEMS.get(2));
Selection s = mManager.getSelection();
SparseBooleanArray provisional = new SparseBooleanArray();
@@ -333,8 +360,8 @@ public class DefaultSelectionManagerTest {
@Test
public void testProvisionalSelection_IntersectsAppliedSelection() {
- mManager.toggleSelection(ITEMS.get(1));
- mManager.toggleSelection(ITEMS.get(2));
+ mManager.select(ITEMS.get(1));
+ mManager.select(ITEMS.get(2));
Selection s = mManager.getSelection();
// Mimicking band selection case -- BandController notifies item callback by itself.
diff --git a/tests/unit/com/android/documentsui/selection/DefaultSelectionManager_SingleSelectTest.java b/tests/unit/com/android/documentsui/selection/DefaultSelectionHelper_SingleSelectTest.java
index e720045a3..f1a1062c2 100644
--- a/tests/unit/com/android/documentsui/selection/DefaultSelectionManager_SingleSelectTest.java
+++ b/tests/unit/com/android/documentsui/selection/DefaultSelectionHelper_SingleSelectTest.java
@@ -22,8 +22,7 @@ import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.documentsui.dirlist.TestData;
-import com.android.documentsui.dirlist.TestDocumentsAdapter;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.testing.SelectionHelpers;
import org.junit.Before;
import org.junit.Test;
@@ -33,39 +32,38 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
@SmallTest
-public class DefaultSelectionManager_SingleSelectTest {
+public class DefaultSelectionHelper_SingleSelectTest {
private static final List<String> ITEMS = TestData.create(100);
- private SelectionManager mManager;
- private TestSelectionEventListener mListener;
- private TestDocumentsAdapter mAdapter;
+ private SelectionHelper mManager;
+ private TestSelectionObserver mListener;
private SelectionProbe mSelection;
@Before
public void setUp() throws Exception {
- mListener = new TestSelectionEventListener();
- mManager = SelectionManagers.createTestInstance(ITEMS, DefaultSelectionManager.MODE_SINGLE);
- mManager.addEventListener(mListener);
+ mListener = new TestSelectionObserver();
+ mManager = SelectionHelpers.createTestInstance(ITEMS, DefaultSelectionHelper.MODE_SINGLE);
+ mManager.addObserver(mListener);
mSelection = new SelectionProbe(mManager);
}
@Test
public void testSimpleSelect() {
- mManager.toggleSelection(ITEMS.get(3));
- mManager.toggleSelection(ITEMS.get(4));
+ mManager.select(ITEMS.get(3));
+ mManager.select(ITEMS.get(4));
mListener.assertSelectionChanged();
mSelection.assertSelection(4);
}
@Test
public void testRangeSelectionNotEstablished() {
- mManager.toggleSelection(ITEMS.get(3));
+ mManager.select(ITEMS.get(3));
mListener.reset();
try {
- mManager.snapRangeSelection(10);
+ mManager.extendRange(10);
fail("Should have thrown.");
} catch (Exception expected) {}
diff --git a/tests/unit/com/android/documentsui/selection/addons/BandSelectorTest.java b/tests/unit/com/android/documentsui/selection/addons/BandSelectionHelperTest.java
index f4026f5b6..25d2bf948 100644
--- a/tests/unit/com/android/documentsui/selection/addons/BandSelectorTest.java
+++ b/tests/unit/com/android/documentsui/selection/addons/BandSelectionHelperTest.java
@@ -28,7 +28,9 @@ import android.view.MotionEvent;
import com.android.documentsui.dirlist.TestData;
import com.android.documentsui.dirlist.TestDocumentsAdapter;
-import com.android.documentsui.testing.SelectionManagers;
+import com.android.documentsui.selection.addons.BandSelectionHelper;
+import com.android.documentsui.selection.addons.ContentLock;
+import com.android.documentsui.testing.SelectionHelpers;
import com.android.documentsui.testing.TestEvents.Builder;
import org.junit.Before;
@@ -40,10 +42,10 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
@SmallTest
-public class BandSelectorTest {
+public class BandSelectionHelperTest {
private static final List<String> ITEMS = TestData.create(10);
- private BandSelector mBandController;
+ private BandSelectionHelper mBandController;
private boolean mIsActive;
private Builder mStartBuilder;
private Builder mStopBuilder;
@@ -56,12 +58,12 @@ public class BandSelectorTest {
mIsActive = false;
TestDocumentsAdapter adapter = new TestDocumentsAdapter(ITEMS);
mSelectionHost = new TestSelectionHost();
- mBandController = new BandSelector(
+ mBandController = new BandSelectionHelper(
mSelectionHost,
adapter, // adapter
adapter, // stableIds
- SelectionManagers.createTestInstance(ITEMS),
- SelectionManagers.CAN_SET_ANYTHING,
+ SelectionHelpers.createTestInstance(ITEMS),
+ SelectionHelpers.CAN_SET_ANYTHING,
new ContentLock()) {
@Override
public boolean isActive() {
@@ -137,12 +139,12 @@ public class BandSelectorTest {
@Test
public void testBadStart_NoItems() {
TestDocumentsAdapter emptyAdapter = new TestDocumentsAdapter(Collections.EMPTY_LIST);
- mBandController = new BandSelector(
+ mBandController = new BandSelectionHelper(
new TestSelectionHost(),
emptyAdapter,
emptyAdapter,
- SelectionManagers.createTestInstance(ITEMS),
- SelectionManagers.CAN_SET_ANYTHING,
+ SelectionHelpers.createTestInstance(ITEMS),
+ SelectionHelpers.CAN_SET_ANYTHING,
new ContentLock());
assertFalse(mBandController.shouldStart(mStartEvent));
@@ -199,7 +201,7 @@ public class BandSelectorTest {
mStopBuilder.action(MotionEvent.ACTION_DOWN).touch().build()));
}
- private final class TestSelectionHost implements BandSelector.SelectionHost {
+ private final class TestSelectionHost implements BandSelectionHelper.SelectionHost {
private boolean mCanInitiateBand = true;
diff --git a/tests/unit/com/android/documentsui/selection/addons/ContentLockTest.java b/tests/unit/com/android/documentsui/selection/addons/ContentLockTest.java
index 94048abf1..75ce17e94 100644
--- a/tests/unit/com/android/documentsui/selection/addons/ContentLockTest.java
+++ b/tests/unit/com/android/documentsui/selection/addons/ContentLockTest.java
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import com.android.documentsui.selection.addons.ContentLock;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/tests/unit/com/android/documentsui/selection/addons/GestureSelectorTest.java b/tests/unit/com/android/documentsui/selection/addons/GestureSelectionHelperTest.java
index 129ce693d..dd6ae1fcf 100644
--- a/tests/unit/com/android/documentsui/selection/addons/GestureSelectorTest.java
+++ b/tests/unit/com/android/documentsui/selection/addons/GestureSelectionHelperTest.java
@@ -24,14 +24,14 @@ import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent;
import android.view.View;
-import com.android.documentsui.selection.addons.GestureSelector.RecyclerViewDelegate;
+import com.android.documentsui.selection.addons.GestureSelectionHelper.RecyclerViewDelegate;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
-public class GestureSelectorTest {
+public class GestureSelectionHelperTest {
// Simulate a (20, 20) box locating at (20, 20)
static final int LEFT_BORDER = 20;
diff --git a/tests/unit/com/android/documentsui/selection/addons/GridModelTest.java b/tests/unit/com/android/documentsui/selection/addons/GridModelTest.java
index edbb4134a..239ea4d31 100644
--- a/tests/unit/com/android/documentsui/selection/addons/GridModelTest.java
+++ b/tests/unit/com/android/documentsui/selection/addons/GridModelTest.java
@@ -29,7 +29,9 @@ import android.support.v7.widget.RecyclerView.OnScrollListener;
import android.view.MotionEvent;
import com.android.documentsui.dirlist.TestDocumentsAdapter;
-import com.android.documentsui.selection.SelectionManager.SelectionPredicate;
+import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
+import com.android.documentsui.selection.addons.BandSelectionHelper;
+import com.android.documentsui.selection.addons.GridModel;
import org.junit.After;
import org.junit.Test;
@@ -307,7 +309,7 @@ public class GridModelTest {
mHost.mScrollListener.onScrolled(null, 0, dy);
}
- private static final class TestHost implements BandSelector.SelectionHost {
+ private static final class TestHost implements BandSelectionHelper.SelectionHost {
private final int mNumColumns;
private final int mNumRows;
diff --git a/tests/unit/com/android/documentsui/selection/addons/ViewAutoScrollerTest.java b/tests/unit/com/android/documentsui/selection/addons/ViewAutoScrollerTest.java
index 076289146..723c97946 100644
--- a/tests/unit/com/android/documentsui/selection/addons/ViewAutoScrollerTest.java
+++ b/tests/unit/com/android/documentsui/selection/addons/ViewAutoScrollerTest.java
@@ -23,6 +23,7 @@ import android.graphics.Point;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import com.android.documentsui.selection.addons.ViewAutoScroller;
import com.android.documentsui.selection.addons.ViewAutoScroller.Callbacks;
import com.android.documentsui.selection.addons.ViewAutoScroller.ScrollHost;