Home | History | Annotate | Download | only in documentsui
      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;
     18 
     19 import android.annotation.IntDef;
     20 import android.app.PendingIntent;
     21 import android.content.ContentProvider;
     22 import android.content.Intent;
     23 import android.content.pm.ResolveInfo;
     24 import android.net.Uri;
     25 import android.view.DragEvent;
     26 
     27 import com.android.documentsui.base.BooleanConsumer;
     28 import com.android.documentsui.base.DocumentInfo;
     29 import com.android.documentsui.base.DocumentStack;
     30 import com.android.documentsui.base.RootInfo;
     31 import com.android.documentsui.dirlist.DocumentDetails;
     32 
     33 import java.lang.annotation.Retention;
     34 import java.lang.annotation.RetentionPolicy;
     35 import java.util.function.Consumer;
     36 
     37 import javax.annotation.Nullable;
     38 
     39 public interface ActionHandler {
     40 
     41     @IntDef({
     42         VIEW_TYPE_NONE,
     43         VIEW_TYPE_REGULAR,
     44         VIEW_TYPE_PREVIEW
     45     })
     46     @Retention(RetentionPolicy.SOURCE)
     47     public @interface ViewType {}
     48     public static final int VIEW_TYPE_NONE = 0;
     49     public static final int VIEW_TYPE_REGULAR = 1;
     50     public static final int VIEW_TYPE_PREVIEW = 2;
     51 
     52     void onActivityResult(int requestCode, int resultCode, Intent data);
     53 
     54     void openSettings(RootInfo root);
     55 
     56     /**
     57      * Drops documents on a root.
     58      */
     59     boolean dropOn(DragEvent event, RootInfo root);
     60 
     61     /**
     62      * Attempts to eject the identified root. Returns a boolean answer to listener.
     63      */
     64     void ejectRoot(RootInfo root, BooleanConsumer listener);
     65 
     66     /**
     67      * Attempts to fetch the DocumentInfo for the supplied root. Returns the DocumentInfo to the
     68      * callback. If the task times out, callback will be called with null DocumentInfo. Supply
     69      * {@link TimeoutTask#DEFAULT_TIMEOUT} if you don't want to the task to ever time out.
     70      */
     71     void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback);
     72 
     73     /**
     74      * Attempts to refresh the given DocumentInfo, which should be at the top of the state stack.
     75      * Returns a boolean answer to the callback, given by {@link ContentProvider#refresh}.
     76      */
     77     void refreshDocument(DocumentInfo doc, BooleanConsumer callback);
     78 
     79 
     80     /**
     81      * Attempts to start the authentication process caused by
     82      * {@link android.app.AuthenticationRequiredException}.
     83      */
     84     void startAuthentication(PendingIntent intent);
     85 
     86     void showAppDetails(ResolveInfo info);
     87 
     88     void openRoot(RootInfo root);
     89 
     90     void openRoot(ResolveInfo app);
     91 
     92     void loadRoot(Uri uri);
     93 
     94     void openSelectedInNewWindow();
     95 
     96     void openInNewWindow(DocumentStack path);
     97 
     98     void pasteIntoFolder(RootInfo root);
     99 
    100     void selectAllFiles();
    101 
    102     @Nullable DocumentInfo renameDocument(String name, DocumentInfo document);
    103 
    104     /**
    105      * If container, then opens the container, otherwise views using the specified type of view.
    106      * If the primary view type is unavailable, then fallback to the alternative type of view.
    107      */
    108     boolean openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback);
    109 
    110     /**
    111      * This is called when user hovers over a doc for enough time during a drag n' drop, to open a
    112      * folder that accepts drop. We should only open a container that's not an archive, since archives
    113      * do not accept dropping.
    114      */
    115     void springOpenDirectory(DocumentInfo doc);
    116 
    117     void showChooserForDoc(DocumentInfo doc);
    118 
    119     void openRootDocument(@Nullable DocumentInfo rootDoc);
    120 
    121     void openContainerDocument(DocumentInfo doc);
    122 
    123     void cutToClipboard();
    124 
    125     void copyToClipboard();
    126 
    127     /**
    128      * In general, selected = selection or single focused item
    129      */
    130     void deleteSelectedDocuments();
    131 
    132     void shareSelectedDocuments();
    133 
    134     /**
    135      * Called when initial activity setup is complete. Implementations
    136      * should override this method to set the initial location of the
    137      * app.
    138      */
    139     void initLocation(Intent intent);
    140 
    141     void registerDisplayStateChangedListener(Runnable l);
    142     void unregisterDisplayStateChangedListener(Runnable l);
    143 
    144     void loadDocumentsForCurrentStack();
    145 
    146     void viewInOwner();
    147 
    148     void setDebugMode(boolean enabled);
    149     void showDebugMessage();
    150 
    151     /**
    152      * Allow action handler to be initialized in a new scope.
    153      * @return this
    154      */
    155     <T extends ActionHandler> T reset(DirectoryReloadLock reloadLock);
    156 }
    157