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