1 /*
2  * Copyright (C) 2017 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.clipping;
18 
19 import android.content.ClipData;
20 import android.content.ClipboardManager;
21 import android.content.Context;
22 import android.net.Uri;
23 
24 import androidx.recyclerview.selection.Selection;
25 
26 import com.android.documentsui.base.DocumentInfo;
27 import com.android.documentsui.base.DocumentStack;
28 import com.android.documentsui.services.FileOperationService.OpType;
29 import com.android.documentsui.services.FileOperations;
30 
31 import java.util.List;
32 import java.util.function.Function;
33 
34 public interface DocumentClipper {
35 
36     static final String OP_JUMBO_SELECTION_SIZE = "jumboSelection-size";
37     static final String OP_JUMBO_SELECTION_TAG = "jumboSelection-tag";
38 
create(Context context, ClipStore clipStore)39     static public DocumentClipper create(Context context, ClipStore clipStore) {
40         return new RuntimeDocumentClipper(context, clipStore);
41     }
42 
hasItemsToPaste()43     boolean hasItemsToPaste();
44 
45     /**
46      * Returns {@link ClipData} representing the selection, or null if selection is empty,
47      * or cannot be converted.
48      */
getClipDataForDocuments(Function<String, Uri> uriBuilder, Selection<String> selection, @OpType int opType)49     ClipData getClipDataForDocuments(Function<String, Uri> uriBuilder, Selection<String> selection,
50             @OpType int opType);
51 
52     /**
53      * Returns {@link ClipData} representing the list of {@link Uri}, or null if the list is empty.
54      */
getClipDataForDocuments(List<Uri> uris, @OpType int opType, DocumentInfo parent)55     ClipData getClipDataForDocuments(List<Uri> uris, @OpType int opType, DocumentInfo parent);
56 
57     /**
58      * Returns {@link ClipData} representing the list of {@link Uri}, or null if the list is empty.
59      */
getClipDataForDocuments(List<Uri> uris, @OpType int opType)60     ClipData getClipDataForDocuments(List<Uri> uris, @OpType int opType);
61 
62     /**
63      * Puts {@code ClipData} in a primary clipboard, describing a copy operation
64      */
clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection<String> selection)65     void clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection<String> selection);
66 
67     /**
68      *  Puts {@Code ClipData} in a primary clipboard, describing a cut operation
69      */
clipDocumentsForCut( Function<String, Uri> uriBuilder, Selection<String> selection, DocumentInfo parent)70     void clipDocumentsForCut(
71             Function<String, Uri> uriBuilder, Selection<String> selection, DocumentInfo parent);
72 
73     /**
74      * Copies documents from clipboard. It's the same as {@link #copyFromClipData} with clipData
75      * returned from {@link ClipboardManager#getPrimaryClip()}.
76      *
77      * @param destination destination document.
78      * @param docStack the document stack to the destination folder (not including the destination
79      *                 folder)
80      * @param callback callback to notify when operation is scheduled or rejected.
81      */
copyFromClipboard( DocumentInfo destination, DocumentStack docStack, FileOperations.Callback callback)82     void copyFromClipboard(
83             DocumentInfo destination,
84             DocumentStack docStack,
85             FileOperations.Callback callback);
86 
87     /**
88      * Copies documents from clipboard. It's the same as {@link #copyFromClipData} with clipData
89      * returned from {@link ClipboardManager#getPrimaryClip()}.
90      *
91      * @param docStack the document stack to the destination folder,
92      * @param callback callback to notify when operation is scheduled or rejected.
93      */
copyFromClipboard( DocumentStack docStack, FileOperations.Callback callback)94     void copyFromClipboard(
95             DocumentStack docStack,
96             FileOperations.Callback callback);
97 
98     /**
99      * Copies documents from given clip data to a folder.
100      *
101      * @param destination destination folder
102      * @param docStack the document stack to the destination folder (not including the destination
103      *                 folder)
104      * @param clipData the clipData to copy from
105      * @param callback callback to notify when operation is scheduled or rejected.
106      */
copyFromClipData( DocumentInfo destination, DocumentStack docStack, ClipData clipData, FileOperations.Callback callback)107     void copyFromClipData(
108             DocumentInfo destination,
109             DocumentStack docStack,
110             ClipData clipData,
111             FileOperations.Callback callback);
112 
113     /**
114      * Copies documents from given clip data to a folder, ignoring the op type in clip data.
115      *
116      * @param dstStack the document stack to the destination folder, including the destination
117      *                 folder.
118      * @param clipData the clipData to copy from
119      * @param opType the operation type
120      * @param callback callback to notify when operation is scheduled or rejected.
121      */
copyFromClipData( DocumentStack dstStack, ClipData clipData, @OpType int opType, FileOperations.Callback callback)122     void copyFromClipData(
123             DocumentStack dstStack,
124             ClipData clipData,
125             @OpType int opType,
126             FileOperations.Callback callback);
127 
128     /**
129      * Copies documents from given clip data to a folder.
130      *
131      * @param dstStack the document stack to the destination folder, including the destination
132      *            folder.
133      * @param clipData the clipData to copy from
134      * @param callback callback to notify when operation is scheduled or rejected.
135      */
copyFromClipData( DocumentStack dstStack, ClipData clipData, FileOperations.Callback callback)136     void copyFromClipData(
137             DocumentStack dstStack,
138             ClipData clipData,
139             FileOperations.Callback callback);
140 }
141