blob: 15124eb33b981b110b8440f288cf2fd68c6704d3 [file] [log] [blame]
Garfield Tan7d75f7b2016-09-20 16:33:24 -07001/*
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
Ben Lin80030082017-05-01 18:50:05 -070019import android.app.PendingIntent;
Ben Lin174fc2e2017-03-01 17:53:20 -080020import android.content.ContentProvider;
Steve McKay988d8a32016-09-27 09:41:17 -070021import android.content.Intent;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070022import android.content.pm.ResolveInfo;
Steve McKay988d8a32016-09-27 09:41:17 -070023import android.net.Uri;
Ben Lin174fc2e2017-03-01 17:53:20 -080024import android.view.DragEvent;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070025
shawnlin8dafe612019-08-14 20:10:18 +080026import androidx.annotation.IntDef;
Riddle Hsu0c375982018-06-21 22:06:43 +080027import androidx.recyclerview.selection.ItemDetailsLookup.ItemDetails;
28
Steve McKay739f94b2016-09-22 14:54:23 -070029import com.android.documentsui.base.BooleanConsumer;
Garfield Tan208945c2016-10-04 14:36:38 -070030import com.android.documentsui.base.DocumentInfo;
Steve McKay739f94b2016-09-22 14:54:23 -070031import com.android.documentsui.base.DocumentStack;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070032import com.android.documentsui.base.RootInfo;
Kelvin Kwana34bbd92020-02-10 23:49:21 +000033import com.android.documentsui.base.UserId;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070034
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +090035import java.lang.annotation.Retention;
36import java.lang.annotation.RetentionPolicy;
shawnlin8dafe612019-08-14 20:10:18 +080037import java.util.List;
Ben Lin30b0dc12017-03-07 15:37:16 -080038import java.util.function.Consumer;
39
Jon Mann30d8c792017-02-21 17:44:49 -080040import javax.annotation.Nullable;
41
Riddle Hsu0c375982018-06-21 22:06:43 +080042/**
43 * Interface to handle action for document.
44 */
Steve McKay739f94b2016-09-22 14:54:23 -070045public interface ActionHandler {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070046
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +090047 @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
Ben Lin80030082017-05-01 18:50:05 -070058 void onActivityResult(int requestCode, int resultCode, Intent data);
59
Steve McKay739f94b2016-09-22 14:54:23 -070060 void openSettings(RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070061
Garfield Tanb285b402016-09-21 17:12:18 -070062 /**
63 * Drops documents on a root.
Garfield Tanb285b402016-09-21 17:12:18 -070064 */
Ben Lin174fc2e2017-03-01 17:53:20 -080065 boolean dropOn(DragEvent event, RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070066
Steve McKay739f94b2016-09-22 14:54:23 -070067 /**
68 * Attempts to eject the identified root. Returns a boolean answer to listener.
69 */
70 void ejectRoot(RootInfo root, BooleanConsumer listener);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070071
Ben Lin30b0dc12017-03-07 15:37:16 -080072 /**
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 */
77 void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback);
78
Ben Line9abd2d2016-12-06 11:39:52 -080079 /**
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 */
83 void refreshDocument(DocumentInfo doc, BooleanConsumer callback);
84
Ben Lin80030082017-05-01 18:50:05 -070085
86 /**
87 * Attempts to start the authentication process caused by
88 * {@link android.app.AuthenticationRequiredException}.
89 */
90 void startAuthentication(PendingIntent intent);
91
Kelvin Kwan9d344de2020-04-08 14:23:30 +010092 void requestQuietModeDisabled(RootInfo info, UserId userId);
93
Kelvin Kwana34bbd92020-02-10 23:49:21 +000094 void showAppDetails(ResolveInfo info, UserId userId);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070095
Steve McKay739f94b2016-09-22 14:54:23 -070096 void openRoot(RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070097
Kelvin Kwana649f542020-02-20 20:36:23 +000098 void openRoot(ResolveInfo app, UserId userId);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070099
Kelvin Kwan9feaaf52020-02-13 15:43:31 +0000100 void loadRoot(Uri uri, UserId userId);
101
102 void loadCrossProfileRoot(RootInfo info, UserId selectedUser);
Steve McKay988d8a32016-09-27 09:41:17 -0700103
Ivan Chiang9b9a2822018-09-19 17:03:22 +0800104 void loadFirstRoot(Uri uri);
105
Steve McKay5b0a2c12016-10-07 11:22:31 -0700106 void openSelectedInNewWindow();
107
Steve McKay739f94b2016-09-22 14:54:23 -0700108 void openInNewWindow(DocumentStack path);
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700109
Steve McKay739f94b2016-09-22 14:54:23 -0700110 void pasteIntoFolder(RootInfo root);
Steve McKay6d20d192016-09-21 17:57:10 -0700111
Jon Mann30d8c792017-02-21 17:44:49 -0800112 void selectAllFiles();
113
Tony Huang76c6c9d2019-08-12 18:04:06 +0800114 /**
115 * Attempts to deselect all selected files.
116 */
117 void deselectAllFiles();
118
Ben Linff7f3ae2017-04-25 16:08:52 -0700119 void showCreateDirectoryDialog();
120
Austin Kolanderf5042d02017-06-08 09:20:30 -0700121 void showInspector(DocumentInfo doc);
Dooper0930d4c2017-06-02 10:32:00 -0700122
Jon Mann30d8c792017-02-21 17:44:49 -0800123 @Nullable DocumentInfo renameDocument(String name, DocumentInfo document);
124
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +0900125 /**
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 */
Riddle Hsu0c375982018-06-21 22:06:43 +0800129 boolean openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback);
Steve McKayc8889af2016-09-23 11:22:41 -0700130
Ben Lind8d0ad22017-01-11 13:30:50 -0800131 /**
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 */
136 void springOpenDirectory(DocumentInfo doc);
137
Garfield Tan208945c2016-10-04 14:36:38 -0700138 void showChooserForDoc(DocumentInfo doc);
139
Garfield Tane9670332017-03-06 18:33:23 -0800140 void openRootDocument(@Nullable DocumentInfo rootDoc);
141
Garfield Tan63bf8132016-10-11 11:00:49 -0700142 void openContainerDocument(DocumentInfo doc);
143
Tony Huang7a7e7df2018-11-06 17:16:47 +0800144 boolean previewItem(ItemDetails<String> doc);
145
Ben Lind947f012016-10-18 14:32:49 -0700146 void cutToClipboard();
147
148 void copyToClipboard();
149
150 /**
shawnlin8dafe612019-08-14 20:10:18 +0800151 * Show delete dialog
Ben Lind947f012016-10-18 14:32:49 -0700152 */
shawnlin8dafe612019-08-14 20:10:18 +0800153 void showDeleteDialog();
154
155 /**
156 * Delete the selected document(s)
157 */
158 void deleteSelectedDocuments(List<DocumentInfo> docs, DocumentInfo srcParent);
Steve McKay988d8a32016-09-27 09:41:17 -0700159
Steve McKayd0718952016-10-10 13:43:36 -0700160 void shareSelectedDocuments();
161
Steve McKay988d8a32016-09-27 09:41:17 -0700162 /**
163 * Called when initial activity setup is complete. Implementations
164 * should override this method to set the initial location of the
165 * app.
166 */
167 void initLocation(Intent intent);
Steve McKay92ae43d2016-11-08 12:06:58 -0800168
Jon Mann30d8c792017-02-21 17:44:49 -0800169 void registerDisplayStateChangedListener(Runnable l);
170 void unregisterDisplayStateChangedListener(Runnable l);
171
Garfield Tane9670332017-03-06 18:33:23 -0800172 void loadDocumentsForCurrentStack();
173
Jon Mann253a9922017-03-21 18:53:27 -0700174 void viewInOwner();
175
Jon Manneb1d11b2017-04-01 15:36:59 -0700176 void setDebugMode(boolean enabled);
177 void showDebugMessage();
178
Tony Huang243cf9c2018-10-16 16:15:18 +0800179 void showSortDialog();
180
Steve McKay92ae43d2016-11-08 12:06:58 -0800181 /**
Tony Huang94fc11a2019-10-30 18:00:20 +0800182 * Switch launch icon show/hide status.
183 */
184 void switchLauncherIcon();
185
186 /**
Steve McKay92ae43d2016-11-08 12:06:58 -0800187 * Allow action handler to be initialized in a new scope.
Garfield Tane9670332017-03-06 18:33:23 -0800188 * @return this
Steve McKay92ae43d2016-11-08 12:06:58 -0800189 */
Steve McKay12394522017-08-24 14:14:10 -0700190 <T extends ActionHandler> T reset(ContentLock contentLock);
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700191}