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