1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.documentsui.testing; 18 19 import com.android.documentsui.DocsSelectionHelper; 20 import com.android.documentsui.dirlist.DocsStableIdProvider; 21 import com.android.documentsui.dirlist.DocumentsAdapter; 22 import com.android.documentsui.dirlist.TestDocumentsAdapter; 23 import com.android.documentsui.selection.DefaultSelectionHelper; 24 import com.android.documentsui.selection.DefaultSelectionHelper.SelectionMode; 25 import com.android.documentsui.selection.SelectionHelper.SelectionPredicate; 26 27 import java.util.Collections; 28 import java.util.List; 29 30 public class SelectionHelpers { 31 32 public static final SelectionPredicate CAN_SET_ANYTHING = new SelectionPredicate() { 33 @Override 34 public boolean canSetStateForId(String id, boolean nextState) { 35 return true; 36 } 37 38 @Override 39 public boolean canSetStateAtPosition(int position, boolean nextState) { 40 return true; 41 } 42 }; 43 44 private SelectionHelpers() {} 45 46 public static DocsSelectionHelper createTestInstance() { 47 return createTestInstance(Collections.emptyList()); 48 } 49 50 public static DocsSelectionHelper createTestInstance(List<String> docs) { 51 return createTestInstance(docs, DefaultSelectionHelper.MODE_MULTIPLE); 52 } 53 54 public static DocsSelectionHelper createTestInstance( 55 List<String> docs, @SelectionMode int mode) { 56 return createTestInstance(new TestDocumentsAdapter(docs), mode, CAN_SET_ANYTHING); 57 } 58 59 public static DocsSelectionHelper createTestInstance( 60 DocumentsAdapter adapter, @SelectionMode int mode, SelectionPredicate canSetState) { 61 DocsSelectionHelper manager = mode == DefaultSelectionHelper.MODE_SINGLE 62 ? DocsSelectionHelper.createSingleSelect() 63 : DocsSelectionHelper.createMultiSelect(); 64 65 manager.reset(adapter, new DocsStableIdProvider(adapter), canSetState); 66 67 return manager; 68 } 69 } 70