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