blob: a428df89848b4e64f21cf925988db4fa5e491740 [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;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070033
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +090034import java.lang.annotation.Retention;
35import java.lang.annotation.RetentionPolicy;
shawnlin8dafe612019-08-14 20:10:18 +080036import java.util.List;
Ben Lin30b0dc12017-03-07 15:37:16 -080037import java.util.function.Consumer;
38
Jon Mann30d8c792017-02-21 17:44:49 -080039import javax.annotation.Nullable;
40
Riddle Hsu0c375982018-06-21 22:06:43 +080041/**
42 * Interface to handle action for document.
43 */
Steve McKay739f94b2016-09-22 14:54:23 -070044public interface ActionHandler {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070045
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +090046 @IntDef({
47 VIEW_TYPE_NONE,
48 VIEW_TYPE_REGULAR,
49 VIEW_TYPE_PREVIEW
50 })
51 @Retention(RetentionPolicy.SOURCE)
52 public @interface ViewType {}
53 public static final int VIEW_TYPE_NONE = 0;
54 public static final int VIEW_TYPE_REGULAR = 1;
55 public static final int VIEW_TYPE_PREVIEW = 2;
56
Ben Lin80030082017-05-01 18:50:05 -070057 void onActivityResult(int requestCode, int resultCode, Intent data);
58
Steve McKay739f94b2016-09-22 14:54:23 -070059 void openSettings(RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070060
Garfield Tanb285b402016-09-21 17:12:18 -070061 /**
62 * Drops documents on a root.
Garfield Tanb285b402016-09-21 17:12:18 -070063 */
Ben Lin174fc2e2017-03-01 17:53:20 -080064 boolean dropOn(DragEvent event, RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070065
Steve McKay739f94b2016-09-22 14:54:23 -070066 /**
67 * Attempts to eject the identified root. Returns a boolean answer to listener.
68 */
69 void ejectRoot(RootInfo root, BooleanConsumer listener);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070070
Ben Lin30b0dc12017-03-07 15:37:16 -080071 /**
72 * Attempts to fetch the DocumentInfo for the supplied root. Returns the DocumentInfo to the
73 * callback. If the task times out, callback will be called with null DocumentInfo. Supply
74 * {@link TimeoutTask#DEFAULT_TIMEOUT} if you don't want to the task to ever time out.
75 */
76 void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback);
77
Ben Line9abd2d2016-12-06 11:39:52 -080078 /**
79 * Attempts to refresh the given DocumentInfo, which should be at the top of the state stack.
80 * Returns a boolean answer to the callback, given by {@link ContentProvider#refresh}.
81 */
82 void refreshDocument(DocumentInfo doc, BooleanConsumer callback);
83
Ben Lin80030082017-05-01 18:50:05 -070084
85 /**
86 * Attempts to start the authentication process caused by
87 * {@link android.app.AuthenticationRequiredException}.
88 */
89 void startAuthentication(PendingIntent intent);
90
Steve McKay739f94b2016-09-22 14:54:23 -070091 void showAppDetails(ResolveInfo info);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070092
Steve McKay739f94b2016-09-22 14:54:23 -070093 void openRoot(RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070094
Steve McKay739f94b2016-09-22 14:54:23 -070095 void openRoot(ResolveInfo app);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070096
Steve McKay988d8a32016-09-27 09:41:17 -070097 void loadRoot(Uri uri);
98
Ivan Chiang9b9a2822018-09-19 17:03:22 +080099 void loadFirstRoot(Uri uri);
100
Steve McKay5b0a2c12016-10-07 11:22:31 -0700101 void openSelectedInNewWindow();
102
Steve McKay739f94b2016-09-22 14:54:23 -0700103 void openInNewWindow(DocumentStack path);
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700104
Steve McKay739f94b2016-09-22 14:54:23 -0700105 void pasteIntoFolder(RootInfo root);
Steve McKay6d20d192016-09-21 17:57:10 -0700106
Jon Mann30d8c792017-02-21 17:44:49 -0800107 void selectAllFiles();
108
Tony Huang76c6c9d2019-08-12 18:04:06 +0800109 /**
110 * Attempts to deselect all selected files.
111 */
112 void deselectAllFiles();
113
Ben Linff7f3ae2017-04-25 16:08:52 -0700114 void showCreateDirectoryDialog();
115
Austin Kolanderf5042d02017-06-08 09:20:30 -0700116 void showInspector(DocumentInfo doc);
Dooper0930d4c2017-06-02 10:32:00 -0700117
Jon Mann30d8c792017-02-21 17:44:49 -0800118 @Nullable DocumentInfo renameDocument(String name, DocumentInfo document);
119
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +0900120 /**
121 * If container, then opens the container, otherwise views using the specified type of view.
122 * If the primary view type is unavailable, then fallback to the alternative type of view.
123 */
Riddle Hsu0c375982018-06-21 22:06:43 +0800124 boolean openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback);
Steve McKayc8889af2016-09-23 11:22:41 -0700125
Ben Lind8d0ad22017-01-11 13:30:50 -0800126 /**
127 * This is called when user hovers over a doc for enough time during a drag n' drop, to open a
128 * folder that accepts drop. We should only open a container that's not an archive, since archives
129 * do not accept dropping.
130 */
131 void springOpenDirectory(DocumentInfo doc);
132
Garfield Tan208945c2016-10-04 14:36:38 -0700133 void showChooserForDoc(DocumentInfo doc);
134
Garfield Tane9670332017-03-06 18:33:23 -0800135 void openRootDocument(@Nullable DocumentInfo rootDoc);
136
Garfield Tan63bf8132016-10-11 11:00:49 -0700137 void openContainerDocument(DocumentInfo doc);
138
Tony Huang7a7e7df2018-11-06 17:16:47 +0800139 boolean previewItem(ItemDetails<String> doc);
140
Ben Lind947f012016-10-18 14:32:49 -0700141 void cutToClipboard();
142
143 void copyToClipboard();
144
145 /**
shawnlin8dafe612019-08-14 20:10:18 +0800146 * Show delete dialog
Ben Lind947f012016-10-18 14:32:49 -0700147 */
shawnlin8dafe612019-08-14 20:10:18 +0800148 void showDeleteDialog();
149
150 /**
151 * Delete the selected document(s)
152 */
153 void deleteSelectedDocuments(List<DocumentInfo> docs, DocumentInfo srcParent);
Steve McKay988d8a32016-09-27 09:41:17 -0700154
Steve McKayd0718952016-10-10 13:43:36 -0700155 void shareSelectedDocuments();
156
Steve McKay988d8a32016-09-27 09:41:17 -0700157 /**
158 * Called when initial activity setup is complete. Implementations
159 * should override this method to set the initial location of the
160 * app.
161 */
162 void initLocation(Intent intent);
Steve McKay92ae43d2016-11-08 12:06:58 -0800163
Jon Mann30d8c792017-02-21 17:44:49 -0800164 void registerDisplayStateChangedListener(Runnable l);
165 void unregisterDisplayStateChangedListener(Runnable l);
166
Garfield Tane9670332017-03-06 18:33:23 -0800167 void loadDocumentsForCurrentStack();
168
Jon Mann253a9922017-03-21 18:53:27 -0700169 void viewInOwner();
170
Jon Manneb1d11b2017-04-01 15:36:59 -0700171 void setDebugMode(boolean enabled);
172 void showDebugMessage();
173
Tony Huang243cf9c2018-10-16 16:15:18 +0800174 void showSortDialog();
175
Steve McKay92ae43d2016-11-08 12:06:58 -0800176 /**
Tony Huang94fc11a2019-10-30 18:00:20 +0800177 * Switch launch icon show/hide status.
178 */
179 void switchLauncherIcon();
180
181 /**
Steve McKay92ae43d2016-11-08 12:06:58 -0800182 * Allow action handler to be initialized in a new scope.
Garfield Tane9670332017-03-06 18:33:23 -0800183 * @return this
Steve McKay92ae43d2016-11-08 12:06:58 -0800184 */
Steve McKay12394522017-08-24 14:14:10 -0700185 <T extends ActionHandler> T reset(ContentLock contentLock);
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700186}