blob: 5f74b583ef06be3e60705d9bae9aea0754758a0e [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
Jeff Sharkeya4ff00f2018-07-09 14:57:51 -060019import androidx.annotation.IntDef;
Ben Lin80030082017-05-01 18:50:05 -070020import android.app.PendingIntent;
Ben Lin174fc2e2017-03-01 17:53:20 -080021import android.content.ContentProvider;
Steve McKay988d8a32016-09-27 09:41:17 -070022import android.content.Intent;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070023import android.content.pm.ResolveInfo;
Steve McKay988d8a32016-09-27 09:41:17 -070024import android.net.Uri;
Ben Lin174fc2e2017-03-01 17:53:20 -080025import android.view.DragEvent;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070026
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;
Ben Lin30b0dc12017-03-07 15:37:16 -080036import java.util.function.Consumer;
37
Jon Mann30d8c792017-02-21 17:44:49 -080038import javax.annotation.Nullable;
39
Riddle Hsu0c375982018-06-21 22:06:43 +080040/**
41 * Interface to handle action for document.
42 */
Steve McKay739f94b2016-09-22 14:54:23 -070043public interface ActionHandler {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070044
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +090045 @IntDef({
46 VIEW_TYPE_NONE,
47 VIEW_TYPE_REGULAR,
48 VIEW_TYPE_PREVIEW
49 })
50 @Retention(RetentionPolicy.SOURCE)
51 public @interface ViewType {}
52 public static final int VIEW_TYPE_NONE = 0;
53 public static final int VIEW_TYPE_REGULAR = 1;
54 public static final int VIEW_TYPE_PREVIEW = 2;
55
Ben Lin80030082017-05-01 18:50:05 -070056 void onActivityResult(int requestCode, int resultCode, Intent data);
57
Steve McKay739f94b2016-09-22 14:54:23 -070058 void openSettings(RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070059
Garfield Tanb285b402016-09-21 17:12:18 -070060 /**
61 * Drops documents on a root.
Garfield Tanb285b402016-09-21 17:12:18 -070062 */
Ben Lin174fc2e2017-03-01 17:53:20 -080063 boolean dropOn(DragEvent event, RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070064
Steve McKay739f94b2016-09-22 14:54:23 -070065 /**
66 * Attempts to eject the identified root. Returns a boolean answer to listener.
67 */
68 void ejectRoot(RootInfo root, BooleanConsumer listener);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070069
Ben Lin30b0dc12017-03-07 15:37:16 -080070 /**
71 * Attempts to fetch the DocumentInfo for the supplied root. Returns the DocumentInfo to the
72 * callback. If the task times out, callback will be called with null DocumentInfo. Supply
73 * {@link TimeoutTask#DEFAULT_TIMEOUT} if you don't want to the task to ever time out.
74 */
75 void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback);
76
Ben Line9abd2d2016-12-06 11:39:52 -080077 /**
78 * Attempts to refresh the given DocumentInfo, which should be at the top of the state stack.
79 * Returns a boolean answer to the callback, given by {@link ContentProvider#refresh}.
80 */
81 void refreshDocument(DocumentInfo doc, BooleanConsumer callback);
82
Ben Lin80030082017-05-01 18:50:05 -070083
84 /**
85 * Attempts to start the authentication process caused by
86 * {@link android.app.AuthenticationRequiredException}.
87 */
88 void startAuthentication(PendingIntent intent);
89
Steve McKay739f94b2016-09-22 14:54:23 -070090 void showAppDetails(ResolveInfo info);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070091
Steve McKay739f94b2016-09-22 14:54:23 -070092 void openRoot(RootInfo root);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070093
Steve McKay739f94b2016-09-22 14:54:23 -070094 void openRoot(ResolveInfo app);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070095
Steve McKay988d8a32016-09-27 09:41:17 -070096 void loadRoot(Uri uri);
97
Ivan Chiang9b9a2822018-09-19 17:03:22 +080098 void loadFirstRoot(Uri uri);
99
Steve McKay5b0a2c12016-10-07 11:22:31 -0700100 void openSelectedInNewWindow();
101
Steve McKay739f94b2016-09-22 14:54:23 -0700102 void openInNewWindow(DocumentStack path);
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700103
Steve McKay739f94b2016-09-22 14:54:23 -0700104 void pasteIntoFolder(RootInfo root);
Steve McKay6d20d192016-09-21 17:57:10 -0700105
Jon Mann30d8c792017-02-21 17:44:49 -0800106 void selectAllFiles();
107
Ben Linff7f3ae2017-04-25 16:08:52 -0700108 void showCreateDirectoryDialog();
109
Austin Kolanderf5042d02017-06-08 09:20:30 -0700110 void showInspector(DocumentInfo doc);
Dooper0930d4c2017-06-02 10:32:00 -0700111
Jon Mann30d8c792017-02-21 17:44:49 -0800112 @Nullable DocumentInfo renameDocument(String name, DocumentInfo document);
113
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +0900114 /**
115 * If container, then opens the container, otherwise views using the specified type of view.
116 * If the primary view type is unavailable, then fallback to the alternative type of view.
117 */
Riddle Hsu0c375982018-06-21 22:06:43 +0800118 boolean openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback);
Steve McKayc8889af2016-09-23 11:22:41 -0700119
Ben Lind8d0ad22017-01-11 13:30:50 -0800120 /**
121 * This is called when user hovers over a doc for enough time during a drag n' drop, to open a
122 * folder that accepts drop. We should only open a container that's not an archive, since archives
123 * do not accept dropping.
124 */
125 void springOpenDirectory(DocumentInfo doc);
126
Garfield Tan208945c2016-10-04 14:36:38 -0700127 void showChooserForDoc(DocumentInfo doc);
128
Garfield Tane9670332017-03-06 18:33:23 -0800129 void openRootDocument(@Nullable DocumentInfo rootDoc);
130
Garfield Tan63bf8132016-10-11 11:00:49 -0700131 void openContainerDocument(DocumentInfo doc);
132
Tony Huang7a7e7df2018-11-06 17:16:47 +0800133 boolean previewItem(ItemDetails<String> doc);
134
Ben Lind947f012016-10-18 14:32:49 -0700135 void cutToClipboard();
136
137 void copyToClipboard();
138
139 /**
140 * In general, selected = selection or single focused item
141 */
Steve McKaybd9f05a2016-10-10 10:18:36 -0700142 void deleteSelectedDocuments();
Steve McKay988d8a32016-09-27 09:41:17 -0700143
Steve McKayd0718952016-10-10 13:43:36 -0700144 void shareSelectedDocuments();
145
Steve McKay988d8a32016-09-27 09:41:17 -0700146 /**
147 * Called when initial activity setup is complete. Implementations
148 * should override this method to set the initial location of the
149 * app.
150 */
151 void initLocation(Intent intent);
Steve McKay92ae43d2016-11-08 12:06:58 -0800152
Jon Mann30d8c792017-02-21 17:44:49 -0800153 void registerDisplayStateChangedListener(Runnable l);
154 void unregisterDisplayStateChangedListener(Runnable l);
155
Garfield Tane9670332017-03-06 18:33:23 -0800156 void loadDocumentsForCurrentStack();
157
Jon Mann253a9922017-03-21 18:53:27 -0700158 void viewInOwner();
159
Jon Manneb1d11b2017-04-01 15:36:59 -0700160 void setDebugMode(boolean enabled);
161 void showDebugMessage();
162
Tony Huang243cf9c2018-10-16 16:15:18 +0800163 void showSortDialog();
164
Steve McKay92ae43d2016-11-08 12:06:58 -0800165 /**
166 * Allow action handler to be initialized in a new scope.
Garfield Tane9670332017-03-06 18:33:23 -0800167 * @return this
Steve McKay92ae43d2016-11-08 12:06:58 -0800168 */
Steve McKay12394522017-08-24 14:14:10 -0700169 <T extends ActionHandler> T reset(ContentLock contentLock);
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700170}