Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 1 | /* |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 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 | |
Garfield, Tan | 9666ce6 | 2016-07-12 11:02:09 -0700 | [diff] [blame] | 17 | package com.android.documentsui.clipping; |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 18 | |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 19 | import android.content.ClipData; |
| 20 | import android.content.ClipboardManager; |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 23 | |
| 24 | import androidx.recyclerview.selection.Selection; |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 25 | |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 26 | import com.android.documentsui.base.DocumentInfo; |
| 27 | import com.android.documentsui.base.DocumentStack; |
Ben Lin | ff4d584 | 2016-04-18 14:35:28 -0700 | [diff] [blame] | 28 | import com.android.documentsui.services.FileOperationService.OpType; |
Garfield, Tan | 4d00914 | 2016-05-12 14:12:18 -0700 | [diff] [blame] | 29 | import com.android.documentsui.services.FileOperations; |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 30 | |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 31 | import java.util.List; |
Steve McKay | 84769b8 | 2016-06-09 10:46:07 -0700 | [diff] [blame] | 32 | import java.util.function.Function; |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 33 | |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 34 | public interface DocumentClipper { |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 35 | |
Garfield, Tan | edce554 | 2016-06-17 15:32:28 -0700 | [diff] [blame] | 36 | static final String OP_JUMBO_SELECTION_SIZE = "jumboSelection-size"; |
| 37 | static final String OP_JUMBO_SELECTION_TAG = "jumboSelection-tag"; |
| 38 | |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 39 | static public DocumentClipper create(Context context, ClipStore clipStore) { |
| 40 | return new RuntimeDocumentClipper(context, clipStore); |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 43 | boolean hasItemsToPaste(); |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 44 | |
Garfield, Tan | edce554 | 2016-06-17 15:32:28 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Returns {@link ClipData} representing the selection, or null if selection is empty, |
| 47 | * or cannot be converted. |
Garfield, Tan | edce554 | 2016-06-17 15:32:28 -0700 | [diff] [blame] | 48 | */ |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 49 | ClipData getClipDataForDocuments(Function<String, Uri> uriBuilder, Selection<String> selection, |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 50 | @OpType int opType); |
| 51 | |
| 52 | /** |
| 53 | * Returns {@link ClipData} representing the list of {@link Uri}, or null if the list is empty. |
| 54 | */ |
| 55 | ClipData getClipDataForDocuments(List<Uri> uris, @OpType int opType, DocumentInfo parent); |
Vladislav Kaznacheev | 0859d30 | 2016-05-03 15:37:21 -0700 | [diff] [blame] | 56 | |
Ben Lin | ff4d584 | 2016-04-18 14:35:28 -0700 | [diff] [blame] | 57 | /** |
Garfield Tan | 2e81db6 | 2017-04-27 15:06:49 -0700 | [diff] [blame] | 58 | * Returns {@link ClipData} representing the list of {@link Uri}, or null if the list is empty. |
| 59 | */ |
| 60 | ClipData getClipDataForDocuments(List<Uri> uris, @OpType int opType); |
| 61 | |
| 62 | /** |
Ben Lin | ff4d584 | 2016-04-18 14:35:28 -0700 | [diff] [blame] | 63 | * Puts {@code ClipData} in a primary clipboard, describing a copy operation |
| 64 | */ |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 65 | void clipDocumentsForCopy(Function<String, Uri> uriBuilder, Selection<String> selection); |
Ben Lin | ff4d584 | 2016-04-18 14:35:28 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Puts {@Code ClipData} in a primary clipboard, describing a cut operation |
| 69 | */ |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 70 | void clipDocumentsForCut( |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 71 | Function<String, Uri> uriBuilder, Selection<String> selection, DocumentInfo parent); |
Ben Lin | ff4d584 | 2016-04-18 14:35:28 -0700 | [diff] [blame] | 72 | |
Garfield, Tan | edce554 | 2016-06-17 15:32:28 -0700 | [diff] [blame] | 73 | /** |
Garfield, Tan | 4d00914 | 2016-05-12 14:12:18 -0700 | [diff] [blame] | 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. |
Garfield Tan | 85a479e | 2017-03-16 11:22:00 -0700 | [diff] [blame] | 78 | * @param docStack the document stack to the destination folder (not including the destination |
| 79 | * folder) |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 80 | * @param callback callback to notify when operation is scheduled or rejected. |
Garfield, Tan | 4d00914 | 2016-05-12 14:12:18 -0700 | [diff] [blame] | 81 | */ |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 82 | void copyFromClipboard( |
Steve McKay | 84769b8 | 2016-06-09 10:46:07 -0700 | [diff] [blame] | 83 | DocumentInfo destination, |
| 84 | DocumentStack docStack, |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 85 | FileOperations.Callback callback); |
Garfield, Tan | 4d00914 | 2016-05-12 14:12:18 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
Ben Lin | db7a0e7 | 2017-03-02 11:18:22 -0800 | [diff] [blame] | 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, |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 92 | * @param callback callback to notify when operation is scheduled or rejected. |
Ben Lin | db7a0e7 | 2017-03-02 11:18:22 -0800 | [diff] [blame] | 93 | */ |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 94 | void copyFromClipboard( |
Ben Lin | db7a0e7 | 2017-03-02 11:18:22 -0800 | [diff] [blame] | 95 | DocumentStack docStack, |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 96 | FileOperations.Callback callback); |
Ben Lin | db7a0e7 | 2017-03-02 11:18:22 -0800 | [diff] [blame] | 97 | |
| 98 | /** |
Garfield, Tan | a5588b6 | 2016-07-13 09:23:04 -0700 | [diff] [blame] | 99 | * Copies documents from given clip data to a folder. |
Garfield, Tan | 4d00914 | 2016-05-12 14:12:18 -0700 | [diff] [blame] | 100 | * |
Garfield, Tan | a5588b6 | 2016-07-13 09:23:04 -0700 | [diff] [blame] | 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 |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 105 | * @param callback callback to notify when operation is scheduled or rejected. |
Garfield, Tan | 4d00914 | 2016-05-12 14:12:18 -0700 | [diff] [blame] | 106 | */ |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 107 | void copyFromClipData( |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 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 | */ |
| 122 | void copyFromClipData( |
| 123 | DocumentStack dstStack, |
| 124 | ClipData clipData, |
| 125 | @OpType int opType, |
| 126 | FileOperations.Callback callback); |
Garfield Tan | 85a479e | 2017-03-16 11:22:00 -0700 | [diff] [blame] | 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 |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 134 | * @param callback callback to notify when operation is scheduled or rejected. |
Garfield Tan | 85a479e | 2017-03-16 11:22:00 -0700 | [diff] [blame] | 135 | */ |
| 136 | void copyFromClipData( |
Garfield Tan | da2c0f0 | 2017-04-11 13:47:58 -0700 | [diff] [blame] | 137 | DocumentStack dstStack, |
| 138 | ClipData clipData, |
| 139 | FileOperations.Callback callback); |
Steve McKay | 1f19948 | 2015-05-20 15:58:42 -0700 | [diff] [blame] | 140 | } |