Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 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 | |
Ben Lin | 8003008 | 2017-05-01 18:50:05 -0700 | [diff] [blame] | 19 | import android.app.PendingIntent; |
Ben Lin | 174fc2e | 2017-03-01 17:53:20 -0800 | [diff] [blame] | 20 | import android.content.ContentProvider; |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 22 | import android.content.pm.ResolveInfo; |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Ben Lin | 174fc2e | 2017-03-01 17:53:20 -0800 | [diff] [blame] | 24 | import android.view.DragEvent; |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 25 | |
shawnlin | 8dafe61 | 2019-08-14 20:10:18 +0800 | [diff] [blame] | 26 | import androidx.annotation.IntDef; |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 27 | import androidx.recyclerview.selection.ItemDetailsLookup.ItemDetails; |
| 28 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 29 | import com.android.documentsui.base.BooleanConsumer; |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 30 | import com.android.documentsui.base.DocumentInfo; |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 31 | import com.android.documentsui.base.DocumentStack; |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 32 | import com.android.documentsui.base.RootInfo; |
Kelvin Kwan | a34bbd9 | 2020-02-10 23:49:21 +0000 | [diff] [blame] | 33 | import com.android.documentsui.base.UserId; |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 34 | |
Tomasz Mikolajewski | d22cc18 | 2017-03-15 16:13:46 +0900 | [diff] [blame] | 35 | import java.lang.annotation.Retention; |
| 36 | import java.lang.annotation.RetentionPolicy; |
shawnlin | 8dafe61 | 2019-08-14 20:10:18 +0800 | [diff] [blame] | 37 | import java.util.List; |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 38 | import java.util.function.Consumer; |
| 39 | |
Jon Mann | 30d8c79 | 2017-02-21 17:44:49 -0800 | [diff] [blame] | 40 | import javax.annotation.Nullable; |
| 41 | |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 42 | /** |
| 43 | * Interface to handle action for document. |
| 44 | */ |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 45 | public interface ActionHandler { |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 46 | |
Tomasz Mikolajewski | d22cc18 | 2017-03-15 16:13:46 +0900 | [diff] [blame] | 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 | |
Ben Lin | 8003008 | 2017-05-01 18:50:05 -0700 | [diff] [blame] | 58 | void onActivityResult(int requestCode, int resultCode, Intent data); |
| 59 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 60 | void openSettings(RootInfo root); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 61 | |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 62 | /** |
| 63 | * Drops documents on a root. |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 64 | */ |
Ben Lin | 174fc2e | 2017-03-01 17:53:20 -0800 | [diff] [blame] | 65 | boolean dropOn(DragEvent event, RootInfo root); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 66 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 67 | /** |
| 68 | * Attempts to eject the identified root. Returns a boolean answer to listener. |
| 69 | */ |
| 70 | void ejectRoot(RootInfo root, BooleanConsumer listener); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 71 | |
Ben Lin | 30b0dc1 | 2017-03-07 15:37:16 -0800 | [diff] [blame] | 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 | */ |
| 77 | void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback); |
| 78 | |
Ben Lin | e9abd2d | 2016-12-06 11:39:52 -0800 | [diff] [blame] | 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 | */ |
| 83 | void refreshDocument(DocumentInfo doc, BooleanConsumer callback); |
| 84 | |
Ben Lin | 8003008 | 2017-05-01 18:50:05 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Attempts to start the authentication process caused by |
| 88 | * {@link android.app.AuthenticationRequiredException}. |
| 89 | */ |
| 90 | void startAuthentication(PendingIntent intent); |
| 91 | |
Kelvin Kwan | 9d344de | 2020-04-08 14:23:30 +0100 | [diff] [blame] | 92 | void requestQuietModeDisabled(RootInfo info, UserId userId); |
| 93 | |
Kelvin Kwan | a34bbd9 | 2020-02-10 23:49:21 +0000 | [diff] [blame] | 94 | void showAppDetails(ResolveInfo info, UserId userId); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 95 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 96 | void openRoot(RootInfo root); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 97 | |
Kelvin Kwan | a649f54 | 2020-02-20 20:36:23 +0000 | [diff] [blame] | 98 | void openRoot(ResolveInfo app, UserId userId); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 99 | |
Kelvin Kwan | 9feaaf5 | 2020-02-13 15:43:31 +0000 | [diff] [blame] | 100 | void loadRoot(Uri uri, UserId userId); |
| 101 | |
| 102 | void loadCrossProfileRoot(RootInfo info, UserId selectedUser); |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 103 | |
Ivan Chiang | 9b9a282 | 2018-09-19 17:03:22 +0800 | [diff] [blame] | 104 | void loadFirstRoot(Uri uri); |
| 105 | |
Steve McKay | 5b0a2c1 | 2016-10-07 11:22:31 -0700 | [diff] [blame] | 106 | void openSelectedInNewWindow(); |
| 107 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 108 | void openInNewWindow(DocumentStack path); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 109 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 110 | void pasteIntoFolder(RootInfo root); |
Steve McKay | 6d20d19 | 2016-09-21 17:57:10 -0700 | [diff] [blame] | 111 | |
Jon Mann | 30d8c79 | 2017-02-21 17:44:49 -0800 | [diff] [blame] | 112 | void selectAllFiles(); |
| 113 | |
Tony Huang | 76c6c9d | 2019-08-12 18:04:06 +0800 | [diff] [blame] | 114 | /** |
| 115 | * Attempts to deselect all selected files. |
| 116 | */ |
| 117 | void deselectAllFiles(); |
| 118 | |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 119 | void showCreateDirectoryDialog(); |
| 120 | |
Austin Kolander | f5042d0 | 2017-06-08 09:20:30 -0700 | [diff] [blame] | 121 | void showInspector(DocumentInfo doc); |
Dooper | 0930d4c | 2017-06-02 10:32:00 -0700 | [diff] [blame] | 122 | |
Jon Mann | 30d8c79 | 2017-02-21 17:44:49 -0800 | [diff] [blame] | 123 | @Nullable DocumentInfo renameDocument(String name, DocumentInfo document); |
| 124 | |
Tomasz Mikolajewski | d22cc18 | 2017-03-15 16:13:46 +0900 | [diff] [blame] | 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 | */ |
Riddle Hsu | 0c37598 | 2018-06-21 22:06:43 +0800 | [diff] [blame] | 129 | boolean openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback); |
Steve McKay | c8889af | 2016-09-23 11:22:41 -0700 | [diff] [blame] | 130 | |
Ben Lin | d8d0ad2 | 2017-01-11 13:30:50 -0800 | [diff] [blame] | 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 | */ |
| 136 | void springOpenDirectory(DocumentInfo doc); |
| 137 | |
Garfield Tan | 208945c | 2016-10-04 14:36:38 -0700 | [diff] [blame] | 138 | void showChooserForDoc(DocumentInfo doc); |
| 139 | |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 140 | void openRootDocument(@Nullable DocumentInfo rootDoc); |
| 141 | |
Garfield Tan | 63bf813 | 2016-10-11 11:00:49 -0700 | [diff] [blame] | 142 | void openContainerDocument(DocumentInfo doc); |
| 143 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 144 | boolean previewItem(ItemDetails<String> doc); |
| 145 | |
Ben Lin | d947f01 | 2016-10-18 14:32:49 -0700 | [diff] [blame] | 146 | void cutToClipboard(); |
| 147 | |
| 148 | void copyToClipboard(); |
| 149 | |
| 150 | /** |
shawnlin | 8dafe61 | 2019-08-14 20:10:18 +0800 | [diff] [blame] | 151 | * Show delete dialog |
Ben Lin | d947f01 | 2016-10-18 14:32:49 -0700 | [diff] [blame] | 152 | */ |
shawnlin | 8dafe61 | 2019-08-14 20:10:18 +0800 | [diff] [blame] | 153 | void showDeleteDialog(); |
| 154 | |
| 155 | /** |
| 156 | * Delete the selected document(s) |
| 157 | */ |
| 158 | void deleteSelectedDocuments(List<DocumentInfo> docs, DocumentInfo srcParent); |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 159 | |
Steve McKay | d071895 | 2016-10-10 13:43:36 -0700 | [diff] [blame] | 160 | void shareSelectedDocuments(); |
| 161 | |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 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 | */ |
| 167 | void initLocation(Intent intent); |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 168 | |
Jon Mann | 30d8c79 | 2017-02-21 17:44:49 -0800 | [diff] [blame] | 169 | void registerDisplayStateChangedListener(Runnable l); |
| 170 | void unregisterDisplayStateChangedListener(Runnable l); |
| 171 | |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 172 | void loadDocumentsForCurrentStack(); |
| 173 | |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 174 | void viewInOwner(); |
| 175 | |
Jon Mann | eb1d11b | 2017-04-01 15:36:59 -0700 | [diff] [blame] | 176 | void setDebugMode(boolean enabled); |
| 177 | void showDebugMessage(); |
| 178 | |
Tony Huang | 243cf9c | 2018-10-16 16:15:18 +0800 | [diff] [blame] | 179 | void showSortDialog(); |
| 180 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 181 | /** |
Tony Huang | 94fc11a | 2019-10-30 18:00:20 +0800 | [diff] [blame] | 182 | * Switch launch icon show/hide status. |
| 183 | */ |
| 184 | void switchLauncherIcon(); |
| 185 | |
| 186 | /** |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 187 | * Allow action handler to be initialized in a new scope. |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 188 | * @return this |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 189 | */ |
Steve McKay | 1239452 | 2017-08-24 14:14:10 -0700 | [diff] [blame] | 190 | <T extends ActionHandler> T reset(ContentLock contentLock); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 191 | } |