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 android.content.ClipData; 20 import android.net.Uri; 21 import android.util.Pair; 22 23 import androidx.recyclerview.selection.Selection; 24 25 import com.android.documentsui.base.DocumentInfo; 26 import com.android.documentsui.base.DocumentStack; 27 import com.android.documentsui.clipping.DocumentClipper; 28 import com.android.documentsui.services.FileOperationService; 29 import com.android.documentsui.services.FileOperationService.OpType; 30 import com.android.documentsui.services.FileOperations.Callback; 31 32 import java.util.ArrayList; 33 import java.util.List; 34 import java.util.function.Function; 35 36 public class TestDocumentClipper implements DocumentClipper { 37 38 public ClipData nextClip; 39 public ClipData primaryClip; 40 41 public final TestEventHandler<List<Uri>> clipForCut = new TestEventHandler<>(); 42 43 public final TestEventListener<Pair<DocumentStack, ClipData>> copyFromClip = 44 new TestEventListener<>(); 45 public final TestEventListener<Integer> opType = new TestEventListener<>(); 46 47 @Override hasItemsToPaste()48 public boolean hasItemsToPaste() { 49 return false; 50 } 51 52 @Override getClipDataForDocuments( Function<String, Uri> uriBuilder, Selection<String> selection, int opType)53 public ClipData getClipDataForDocuments( 54 Function<String, Uri> uriBuilder, Selection<String> selection, int opType) { 55 return nextClip; 56 } 57 58 @Override getClipDataForDocuments(List<Uri> uris, @FileOperationService.OpType int opType)59 public ClipData getClipDataForDocuments(List<Uri> uris, 60 @FileOperationService.OpType int opType) { 61 return nextClip; 62 } 63 64 @Override getClipDataForDocuments(List<Uri> uris, @FileOperationService.OpType int opType, DocumentInfo parent)65 public ClipData getClipDataForDocuments(List<Uri> uris, 66 @FileOperationService.OpType int opType, DocumentInfo parent) { 67 return nextClip; 68 } 69 70 @Override clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection<String> selection)71 public void clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection<String> selection) { 72 } 73 74 @Override clipDocumentsForCut(Function<String, Uri> uriBuilder, Selection<String> selection, DocumentInfo parent)75 public void clipDocumentsForCut(Function<String, Uri> uriBuilder, Selection<String> selection, 76 DocumentInfo parent) { 77 List<Uri> uris = new ArrayList<>(selection.size()); 78 for (String id : selection) { 79 uris.add(uriBuilder.apply(id)); 80 } 81 82 clipForCut.accept(uris); 83 } 84 85 @Override copyFromClipboard(DocumentInfo destination, DocumentStack docStack, Callback callback)86 public void copyFromClipboard(DocumentInfo destination, DocumentStack docStack, 87 Callback callback) { 88 copyFromClip.accept(Pair.create(new DocumentStack(docStack, destination), primaryClip)); 89 } 90 91 @Override copyFromClipboard(DocumentStack docStack, Callback callback)92 public void copyFromClipboard(DocumentStack docStack, Callback callback) { 93 copyFromClip.accept(Pair.create(docStack, primaryClip)); 94 } 95 96 @Override copyFromClipData(DocumentInfo destination, DocumentStack docStack, ClipData clipData, Callback callback)97 public void copyFromClipData(DocumentInfo destination, DocumentStack docStack, 98 ClipData clipData, Callback callback) { 99 copyFromClip.accept(Pair.create(new DocumentStack(docStack, destination), clipData)); 100 } 101 102 @Override copyFromClipData(DocumentStack dstStack, ClipData clipData, @OpType int opType, Callback callback)103 public void copyFromClipData(DocumentStack dstStack, ClipData clipData, 104 @OpType int opType, Callback callback) { 105 copyFromClip.accept(Pair.create(dstStack, clipData)); 106 this.opType.accept(opType); 107 } 108 109 @Override copyFromClipData(DocumentStack docStack, ClipData clipData, Callback callback)110 public void copyFromClipData(DocumentStack docStack, ClipData clipData, Callback callback) { 111 copyFromClip.accept(Pair.create(docStack, clipData)); 112 } 113 } 114