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