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 import android.support.annotation.Nullable;
24 
25 import com.android.documentsui.base.DocumentInfo;
26 import com.android.documentsui.base.DocumentStack;
27 import com.android.documentsui.base.RootInfo;
28 import com.android.documentsui.selection.Selection;
29 import com.android.documentsui.services.FileOperationService.OpType;
30 import com.android.documentsui.services.FileOperations;
31 
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();
getOpType(ClipData data)44     @OpType int getOpType(ClipData data);
45 
46     /**
47      * Returns {@link ClipData} representing the selection, or null if selection is empty,
48      * or cannot be converted.
49      */
getClipDataForDocuments( Function<String, Uri> uriBuilder, Selection selection, @OpType int opType)50     ClipData getClipDataForDocuments(
51         Function<String, Uri> uriBuilder, Selection selection, @OpType int opType);
52 
53     /**
54      * Puts {@code ClipData} in a primary clipboard, describing a copy operation
55      */
clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection selection)56     void clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection selection);
57 
58     /**
59      *  Puts {@Code ClipData} in a primary clipboard, describing a cut operation
60      */
clipDocumentsForCut( Function<String, Uri> uriBuilder, Selection selection, DocumentInfo parent)61     void clipDocumentsForCut(
62             Function<String, Uri> uriBuilder, Selection selection, DocumentInfo parent);
63 
64     /**
65      * Copies documents from clipboard. It's the same as {@link #copyFromClipData} with clipData
66      * returned from {@link ClipboardManager#getPrimaryClip()}.
67      *
68      * @param destination destination document.
69      * @param docStack the document stack to the destination folder (not including the destination
70      *                 folder)
71      * @param callback callback to notify when operation finishes.
72      */
copyFromClipboard( DocumentInfo destination, DocumentStack docStack, FileOperations.Callback callback)73     void copyFromClipboard(
74             DocumentInfo destination,
75             DocumentStack docStack,
76             FileOperations.Callback callback);
77 
78     /**
79      * Copies documents from clipboard. It's the same as {@link #copyFromClipData} with clipData
80      * returned from {@link ClipboardManager#getPrimaryClip()}.
81      *
82      * @param docStack the document stack to the destination folder,
83      * @param callback callback to notify when operation finishes.
84      */
copyFromClipboard( DocumentStack docStack, FileOperations.Callback callback)85     void copyFromClipboard(
86             DocumentStack docStack,
87             FileOperations.Callback callback);
88 
89     /**
90      * Copied documents from given clip data to a root directory.
91      * @param root the root which root directory to copy to
92      * @param destination the root directory
93      * @param clipData the clipData to copy from
94      * @param callback callback to notify when operation finishes
95      */
copyFromClipData( final RootInfo root, final DocumentInfo destination, final ClipData clipData, final FileOperations.Callback callback)96     void copyFromClipData(
97             final RootInfo root,
98             final DocumentInfo destination,
99             final ClipData clipData,
100             final FileOperations.Callback callback);
101 
102     /**
103      * Copies documents from given clip data to a folder.
104      *
105      * @param destination destination folder
106      * @param docStack the document stack to the destination folder (not including the destination
107      *                 folder)
108      * @param clipData the clipData to copy from
109      * @param callback callback to notify when operation finishes
110      */
copyFromClipData( final DocumentInfo destination, final DocumentStack docStack, final ClipData clipData, final FileOperations.Callback callback)111     void copyFromClipData(
112             final DocumentInfo destination,
113             final DocumentStack docStack,
114             final ClipData clipData,
115             final FileOperations.Callback callback);
116 
117     /**
118      * Copies documents from given clip data to a folder.
119      *
120      * @param dstStack the document stack to the destination folder, including the destination
121      *            folder.
122      * @param clipData the clipData to copy from
123      * @param callback callback to notify when operation finishes
124      */
copyFromClipData( final DocumentStack dstStack, final ClipData clipData, final FileOperations.Callback callback)125     void copyFromClipData(
126             final DocumentStack dstStack,
127             final ClipData clipData,
128             final FileOperations.Callback callback);
129 }
130