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 17package com.android.documentsui; 18 19import android.annotation.IntDef; 20import android.app.PendingIntent; 21import android.content.ContentProvider; 22import android.content.Intent; 23import android.content.pm.ResolveInfo; 24import android.net.Uri; 25import android.view.DragEvent; 26 27import com.android.documentsui.base.BooleanConsumer; 28import com.android.documentsui.base.DocumentInfo; 29import com.android.documentsui.base.DocumentStack; 30import com.android.documentsui.base.RootInfo; 31import com.android.documentsui.selection.ContentLock; 32import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails; 33 34import java.lang.annotation.Retention; 35import java.lang.annotation.RetentionPolicy; 36import java.util.function.Consumer; 37 38import javax.annotation.Nullable; 39 40public 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 53 void onActivityResult(int requestCode, int resultCode, Intent data); 54 55 void openSettings(RootInfo root); 56 57 /** 58 * Drops documents on a root. 59 */ 60 boolean dropOn(DragEvent event, RootInfo root); 61 62 /** 63 * Attempts to eject the identified root. Returns a boolean answer to listener. 64 */ 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 */ 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 */ 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 */ 85 void startAuthentication(PendingIntent intent); 86 87 void showAppDetails(ResolveInfo info); 88 89 void openRoot(RootInfo root); 90 91 void openRoot(ResolveInfo app); 92 93 void loadRoot(Uri uri); 94 95 void openSelectedInNewWindow(); 96 97 void openInNewWindow(DocumentStack path); 98 99 void pasteIntoFolder(RootInfo root); 100 101 void selectAllFiles(); 102 103 void showCreateDirectoryDialog(); 104 105 void showInspector(DocumentInfo doc); 106 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 */ 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 */ 120 void springOpenDirectory(DocumentInfo doc); 121 122 void showChooserForDoc(DocumentInfo doc); 123 124 void openRootDocument(@Nullable DocumentInfo rootDoc); 125 126 void openContainerDocument(DocumentInfo doc); 127 128 void cutToClipboard(); 129 130 void copyToClipboard(); 131 132 /** 133 * In general, selected = selection or single focused item 134 */ 135 void deleteSelectedDocuments(); 136 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 */ 144 void initLocation(Intent intent); 145 146 void registerDisplayStateChangedListener(Runnable l); 147 void unregisterDisplayStateChangedListener(Runnable l); 148 149 void loadDocumentsForCurrentStack(); 150 151 void viewInOwner(); 152 153 void setDebugMode(boolean enabled); 154 void showDebugMessage(); 155 156 /** 157 * Allow action handler to be initialized in a new scope. 158 * @return this 159 */ 160 <T extends ActionHandler> T reset(ContentLock contentLock); 161} 162