blob: 7308272ca93e14733d63a78af3b05057a83dead1 [file] [log] [blame]
Steve McKayd0a2a2c2015-03-25 14:35:33 -07001/*
2 * Copyright (C) 2015 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
Steve McKayb6006b22016-09-29 09:23:45 -070017package com.android.documentsui.files;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070018
Steve McKaydf5add42016-01-28 12:02:57 -080019import static com.android.documentsui.OperationDialogFragment.DIALOG_TYPE_UNKNOWN;
Steve McKay7ef09a22015-05-06 12:16:40 -070020
Steve McKay7295c482017-03-15 17:51:32 -070021import android.app.ActivityManager.TaskDescription;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070022import android.content.Intent;
Tony Huangf7b05c42019-05-02 16:51:01 +080023import android.graphics.Color;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070024import android.net.Uri;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070025import android.os.Bundle;
Steve McKay0599a442015-05-05 14:50:00 -070026import android.view.KeyEvent;
Ben Lina8673232016-09-28 15:40:04 -070027import android.view.KeyboardShortcutGroup;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070028import android.view.Menu;
29import android.view.MenuItem;
Tony Huangf7b05c42019-05-02 16:51:01 +080030import android.view.View;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070031
Sunny Goyal5b225532018-07-03 12:44:03 -070032import androidx.annotation.CallSuper;
Tony Huang8d8d92f2018-09-13 14:41:16 +080033import androidx.fragment.app.FragmentManager;
Sunny Goyal5b225532018-07-03 12:44:03 -070034
Steve McKaybd9f05a2016-10-10 10:18:36 -070035import com.android.documentsui.ActionModeController;
Steve McKay16e0c1f2016-09-15 12:41:13 -070036import com.android.documentsui.BaseActivity;
Steve McKay365e3cb2017-08-31 10:27:08 -070037import com.android.documentsui.DocsSelectionHelper;
Steve McKay16e0c1f2016-09-15 12:41:13 -070038import com.android.documentsui.DocumentsApplication;
Ben Lin75b7b902016-11-02 15:59:29 -070039import com.android.documentsui.FocusManager;
Steve McKay92ae43d2016-11-08 12:06:58 -080040import com.android.documentsui.Injector;
Ben Lin7c35b032016-05-31 13:24:01 -070041import com.android.documentsui.MenuManager.DirectoryDetails;
Steve McKay16e0c1f2016-09-15 12:41:13 -070042import com.android.documentsui.OperationDialogFragment;
Steve McKaydf5add42016-01-28 12:02:57 -080043import com.android.documentsui.OperationDialogFragment.DialogType;
Garfield Tan239ab972016-09-16 13:33:48 -070044import com.android.documentsui.ProviderExecutor;
45import com.android.documentsui.R;
Steve McKay04718262016-11-08 11:01:35 -080046import com.android.documentsui.SharedInputHandler;
Steve McKay052985f2017-06-07 11:30:46 -070047import com.android.documentsui.ShortcutsUpdater;
Steve McKayd0805062016-09-15 14:30:38 -070048import com.android.documentsui.base.DocumentInfo;
Steve McKay98f8c5f2017-03-03 13:52:14 -080049import com.android.documentsui.base.Features;
Steve McKayd0805062016-09-15 14:30:38 -070050import com.android.documentsui.base.RootInfo;
Steve McKayd9caa6a2016-09-15 16:36:45 -070051import com.android.documentsui.base.State;
Garfield, Tan9666ce62016-07-12 11:02:09 -070052import com.android.documentsui.clipping.DocumentClipper;
Steve McKay988d8a32016-09-27 09:41:17 -070053import com.android.documentsui.dirlist.AnimationView.AnimationType;
Tony Huange092d2d2018-12-26 19:02:51 +080054import com.android.documentsui.dirlist.AppsRowManager;
Steve McKayf68210e2015-11-03 15:23:16 -080055import com.android.documentsui.dirlist.DirectoryFragment;
Ben Lin30b0dc12017-03-07 15:37:16 -080056import com.android.documentsui.prefs.ScopedPreferences;
Steve McKayc83baa02016-01-06 18:32:13 -080057import com.android.documentsui.services.FileOperationService;
Steve McKayd0805062016-09-15 14:30:38 -070058import com.android.documentsui.sidebar.RootsFragment;
Steve McKayc8889af2016-09-23 11:22:41 -070059import com.android.documentsui.ui.DialogController;
Steve McKay92ae43d2016-11-08 12:06:58 -080060import com.android.documentsui.ui.MessageBuilder;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070061
Tomasz Mikolajewski332d8192015-04-13 19:38:43 +090062import java.util.ArrayList;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070063import java.util.List;
Steve McKayd0a2a2c2015-03-25 14:35:33 -070064
Steve McKayb68dd222015-04-20 17:18:15 -070065/**
Steve McKay64ac2512015-05-12 12:49:58 -070066 * Standalone file management activity.
Steve McKayb68dd222015-04-20 17:18:15 -070067 */
Steve McKay92ae43d2016-11-08 12:06:58 -080068public class FilesActivity extends BaseActivity implements ActionHandler.Addons {
Steve McKayedc65bb2015-07-31 14:35:22 -070069
Steve McKay6525a192016-10-18 14:28:00 -070070 private static final String TAG = "FilesActivity";
Steve McKay92ae43d2016-11-08 12:06:58 -080071 static final String PREFERENCES_SCOPE = "files";
Steve McKayd0a2a2c2015-03-25 14:35:33 -070072
Steve McKay92ae43d2016-11-08 12:06:58 -080073 private Injector<ActionHandler<FilesActivity>> mInjector;
Ben Lin79ae3a72016-10-13 10:57:45 -070074 private ActivityInputHandler mActivityInputHandler;
Steve McKay04718262016-11-08 11:01:35 -080075 private SharedInputHandler mSharedInputHandler;
Steve McKayb68dd222015-04-20 17:18:15 -070076
Steve McKayb6006b22016-09-29 09:23:45 -070077 public FilesActivity() {
Steve McKay0fbfc652015-08-20 16:48:49 -070078 super(R.layout.files_activity, TAG);
Steve McKayb68dd222015-04-20 17:18:15 -070079 }
Steve McKayd0a2a2c2015-03-25 14:35:33 -070080
Tobias Thierere3830da2017-07-14 12:51:34 +010081 // make these methods visible in this package to work around compiler bug http://b/62218600
82 @Override protected boolean focusSidebar() { return super.focusSidebar(); }
83 @Override protected boolean popDir() { return super.popDir(); }
84
Steve McKayd0a2a2c2015-03-25 14:35:33 -070085 @Override
86 public void onCreate(Bundle icicle) {
Steve McKay6525a192016-10-18 14:28:00 -070087
Steve McKay92ae43d2016-11-08 12:06:58 -080088 MessageBuilder messages = new MessageBuilder(this);
Steve McKay5bd5cb42017-04-02 08:36:50 -070089 Features features = Features.create(this);
Steve McKay0ce04b72017-06-05 13:23:54 -070090 ScopedPreferences prefs = ScopedPreferences.create(this, PREFERENCES_SCOPE);
91
Steve McKay92ae43d2016-11-08 12:06:58 -080092 mInjector = new Injector<>(
Tomasz Mikolajewski0d83d322017-02-07 12:29:39 +090093 features,
Steve McKay92ae43d2016-11-08 12:06:58 -080094 new Config(),
95 ScopedPreferences.create(this, PREFERENCES_SCOPE),
96 messages,
shawnlin8dafe612019-08-14 20:10:18 +080097 DialogController.create(features, this),
Steve McKay0ce04b72017-06-05 13:23:54 -070098 DocumentsApplication.getFileTypeLookup(this),
99 new ShortcutsUpdater(this, prefs)::update);
Steve McKay6525a192016-10-18 14:28:00 -0700100
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700101 super.onCreate(icicle);
102
Steve McKay92ae43d2016-11-08 12:06:58 -0800103 DocumentClipper clipper = DocumentsApplication.getDocumentClipper(this);
Riddle Hsu0c375982018-06-21 22:06:43 +0800104 mInjector.selectionMgr = DocsSelectionHelper.create();
Steve McKay04718262016-11-08 11:01:35 -0800105
Steve McKay92ae43d2016-11-08 12:06:58 -0800106 mInjector.focusManager = new FocusManager(
Steve McKay98f8c5f2017-03-03 13:52:14 -0800107 mInjector.features,
Ben Lin340ab172017-01-27 11:41:26 -0800108 mInjector.selectionMgr,
109 mDrawer,
110 this::focusSidebar,
Tony Huang09571b22019-03-14 14:47:53 +0800111 getColor(R.color.primary));
Steve McKay04718262016-11-08 11:01:35 -0800112
Steve McKay92ae43d2016-11-08 12:06:58 -0800113 mInjector.menuManager = new MenuManager(
Steve McKay710248d2017-03-14 10:09:30 -0700114 mInjector.features,
Steve McKaye5d6ca22016-09-19 20:27:24 -0700115 mSearchManager,
116 mState,
117 new DirectoryDetails(this) {
118 @Override
119 public boolean hasItemsToPaste() {
Steve McKay92ae43d2016-11-08 12:06:58 -0800120 return clipper.hasItemsToPaste();
Steve McKaye5d6ca22016-09-19 20:27:24 -0700121 }
Jon Mann253a9922017-03-21 18:53:27 -0700122 },
123 getApplicationContext(),
124 mInjector.selectionMgr,
Jon Mann9bd40992017-03-24 12:34:34 -0700125 mProviders::getApplicationName,
Tony Huang76c6c9d2019-08-12 18:04:06 +0800126 mInjector.getModel()::getItemUri,
127 mInjector.getModel()::getItemCount);
Steve McKaybd9f05a2016-10-10 10:18:36 -0700128
Steve McKay92ae43d2016-11-08 12:06:58 -0800129 mInjector.actionModeController = new ActionModeController(
Steve McKaybd9f05a2016-10-10 10:18:36 -0700130 this,
Steve McKay92ae43d2016-11-08 12:06:58 -0800131 mInjector.selectionMgr,
132 mInjector.menuManager,
133 mInjector.messages);
Steve McKaybd9f05a2016-10-10 10:18:36 -0700134
Steve McKay92ae43d2016-11-08 12:06:58 -0800135 mInjector.actions = new ActionHandler<>(
Steve McKayc8889af2016-09-23 11:22:41 -0700136 this,
Steve McKayc8889af2016-09-23 11:22:41 -0700137 mState,
Jon Mann9bd40992017-03-24 12:34:34 -0700138 mProviders,
Garfield Tan63bf8132016-10-11 11:00:49 -0700139 mDocs,
Garfield Tan63bf8132016-10-11 11:00:49 -0700140 mSearchManager,
Steve McKay988d8a32016-09-27 09:41:17 -0700141 ProviderExecutor::forAuthority,
Steve McKay92ae43d2016-11-08 12:06:58 -0800142 mInjector.actionModeController,
Steve McKay92ae43d2016-11-08 12:06:58 -0800143 clipper,
Jon Mann30d8c792017-02-21 17:44:49 -0800144 DocumentsApplication.getClipStore(this),
Garfield Tanda2c0f02017-04-11 13:47:58 -0700145 DocumentsApplication.getDragAndDropManager(this),
Jon Mann30d8c792017-02-21 17:44:49 -0800146 mInjector);
Steve McKay1f199482015-05-20 15:58:42 -0700147
Garfield Tane9670332017-03-06 18:33:23 -0800148 mInjector.searchManager = mSearchManager;
149
Tony Huange092d2d2018-12-26 19:02:51 +0800150 mAppsRowManager = new AppsRowManager(mInjector.actions);
151 mInjector.appsRowManager = mAppsRowManager;
152
Steve McKay92ae43d2016-11-08 12:06:58 -0800153 mActivityInputHandler =
shawnlin8dafe612019-08-14 20:10:18 +0800154 new ActivityInputHandler(mInjector.actions::showDeleteDialog);
Steve McKay98f8c5f2017-03-03 13:52:14 -0800155 mSharedInputHandler =
Ben Lin0902f072017-03-13 18:25:29 -0700156 new SharedInputHandler(
157 mInjector.focusManager,
158 mInjector.selectionMgr,
159 mInjector.searchManager::cancelSearch,
160 this::popDir,
Rhed Jao23c4bc02018-05-18 16:24:04 +0800161 mInjector.features,
Bill Lin35bfbef2019-08-05 16:09:53 +0800162 mDrawer,
163 mInjector.searchManager::onSearchBarClicked);
Ben Lin79ae3a72016-10-13 10:57:45 -0700164
Tony Huang8d8d92f2018-09-13 14:41:16 +0800165 RootsFragment.show(getSupportFragmentManager(), null);
Steve McKay459bc2b2015-09-16 15:07:31 -0700166
Tomasz Mikolajewskicdbbbe02015-12-25 17:06:52 +0900167 final Intent intent = getIntent();
Steve McKay4d0255f2015-09-25 16:02:56 -0700168
Steve McKay92ae43d2016-11-08 12:06:58 -0800169 mInjector.actions.initLocation(intent);
Steve McKay7295c482017-03-15 17:51:32 -0700170
171 // Allow the activity to masquerade as another, so we can look both like
172 // Downloads and Files, but with only a single underlying activity.
173 if (intent.hasExtra(LauncherActivity.TASK_LABEL_RES)
174 && intent.hasExtra(LauncherActivity.TASK_ICON_RES)) {
175 updateTaskDescription(intent);
176 }
177
Tony Huangf7b05c42019-05-02 16:51:01 +0800178 // Set save container background to transparent for edge to edge nav bar.
179 View saveContainer = findViewById(R.id.container_save);
180 saveContainer.setBackgroundColor(Color.TRANSPARENT);
181
Steve McKay988d8a32016-09-27 09:41:17 -0700182 presentFileErrors(icicle, intent);
183 }
Steve McKay739f94b2016-09-22 14:54:23 -0700184
Steve McKay7295c482017-03-15 17:51:32 -0700185 // This is called in the intent contains label and icon resources.
186 // When that is true, the launcher activity has supplied them so we
187 // can adapt our presentation to how we were launched.
188 // Without this code, overlaying launcher_icon and launcher_label
189 // resources won't create a complete illusion of the activity being renamed.
190 // E.g. if we re-brand Files to Downloads by overlaying label and icon
191 // when the user tapped recents they'd see not "Downloads", but the
192 // underlying Activity description...Files.
193 // Alternate if we rename this activity, when launching other ways
194 // like when browsing files on a removable disk, the app would be
195 // called Downloads, which is also not the desired behavior.
196 private void updateTaskDescription(final Intent intent) {
197 int labelRes = intent.getIntExtra(LauncherActivity.TASK_LABEL_RES, -1);
198 assert(labelRes > -1);
199 String label = getResources().getString(labelRes);
200
201 int iconRes = intent.getIntExtra(LauncherActivity.TASK_ICON_RES, -1);
202 assert(iconRes > -1);
203
Sunny Goyal5b225532018-07-03 12:44:03 -0700204 setTaskDescription(new TaskDescription(label, iconRes));
Steve McKay7295c482017-03-15 17:51:32 -0700205 }
206
Steve McKay988d8a32016-09-27 09:41:17 -0700207 private void presentFileErrors(Bundle icicle, final Intent intent) {
Tomasz Mikolajewskidd2b31c2016-01-22 16:22:51 +0900208 final @DialogType int dialogType = intent.getIntExtra(
209 FileOperationService.EXTRA_DIALOG_TYPE, DIALOG_TYPE_UNKNOWN);
Tomasz Mikolajewskicdbbbe02015-12-25 17:06:52 +0900210 // DialogFragment takes care of restoring the dialog on configuration change.
211 // Only show it manually for the first time (icicle is null).
Tomasz Mikolajewskidd2b31c2016-01-22 16:22:51 +0900212 if (icicle == null && dialogType != DIALOG_TYPE_UNKNOWN) {
213 final int opType = intent.getIntExtra(
Garfield, Tan48334772016-06-28 17:17:38 -0700214 FileOperationService.EXTRA_OPERATION_TYPE,
Tomasz Mikolajewskidd2b31c2016-01-22 16:22:51 +0900215 FileOperationService.OPERATION_COPY);
Steve McKay99f1dc32016-12-29 16:02:01 -0800216 final ArrayList<DocumentInfo> docList =
217 intent.getParcelableArrayListExtra(FileOperationService.EXTRA_FAILED_DOCS);
Tomasz Mikolajewski664025e2017-02-01 11:54:48 +0900218 final ArrayList<Uri> uriList =
Steve McKay99f1dc32016-12-29 16:02:01 -0800219 intent.getParcelableArrayListExtra(FileOperationService.EXTRA_FAILED_URIS);
Tomasz Mikolajewskidd2b31c2016-01-22 16:22:51 +0900220 OperationDialogFragment.show(
Tony Huang8d8d92f2018-09-13 14:41:16 +0800221 getSupportFragmentManager(),
Tomasz Mikolajewskidd2b31c2016-01-22 16:22:51 +0900222 dialogType,
Steve McKay99f1dc32016-12-29 16:02:01 -0800223 docList,
224 uriList,
Tomasz Mikolajewskicdbbbe02015-12-25 17:06:52 +0900225 mState.stack,
Steve McKayc83baa02016-01-06 18:32:13 -0800226 opType);
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700227 }
228 }
229
Steve McKay0fbfc652015-08-20 16:48:49 -0700230 @Override
Steve McKay16e0c1f2016-09-15 12:41:13 -0700231 public void includeState(State state) {
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700232 final Intent intent = getIntent();
Ben Kwa0574b182015-09-08 07:31:19 -0700233
Garfield Tan78ade2b2017-02-28 13:19:53 -0800234 // This is a remnant of old logic where we used to initialize accept MIME types in
Jon Mann9bd40992017-03-24 12:34:34 -0700235 // BaseActivity. ProvidersAccess still rely on this being correctly initialized so we still have
Garfield Tan78ade2b2017-02-28 13:19:53 -0800236 // to initialize it in FilesActivity.
237 state.initAcceptMimes(intent, "*/*");
Steve McKay459bc2b2015-09-16 15:07:31 -0700238 state.action = State.ACTION_BROWSE;
Ben Kwa0574b182015-09-08 07:31:19 -0700239 state.allowMultiple = true;
Steve McKay64ac2512015-05-12 12:49:58 -0700240
Steve McKay459bc2b2015-09-16 15:07:31 -0700241 // Options specific to the DocumentsActivity.
Steve McKay0af8afd2016-02-25 13:34:03 -0800242 assert(!intent.hasExtra(Intent.EXTRA_LOCAL_ONLY));
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700243 }
244
245 @Override
246 protected void onPostCreate(Bundle savedInstanceState) {
247 super.onPostCreate(savedInstanceState);
Steve McKaya8fa58d2015-12-08 17:02:03 -0800248 // This check avoids a flicker from "Recents" to "Home".
249 // Only update action bar at this point if there is an active
Dooper0930d4c2017-06-02 10:32:00 -0700250 // search. Why? Because this avoid an early (undesired) load of
Steve McKaya8fa58d2015-12-08 17:02:03 -0800251 // the recents root...which is the default root in other activities.
252 // In Files app "Home" is the default, but it is loaded async.
Steve McKay18d01e82016-02-03 11:15:57 -0800253 // update will be called once Home root is loaded.
Steve McKaya8fa58d2015-12-08 17:02:03 -0800254 // Except while searching we need this call to ensure the
Dooper0930d4c2017-06-02 10:32:00 -0700255 // search bits get laid out correctly.
Steve McKaya8fa58d2015-12-08 17:02:03 -0800256 if (mSearchManager.isSearching()) {
Steve McKay18d01e82016-02-03 11:15:57 -0800257 mNavigator.update();
Steve McKaya8fa58d2015-12-08 17:02:03 -0800258 }
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700259 }
260
261 @Override
Steve McKay459bc2b2015-09-16 15:07:31 -0700262 public void onResume() {
263 super.onResume();
264
265 final RootInfo root = getCurrentRoot();
266
267 // If we're browsing a specific root, and that root went away, then we
268 // have no reason to hang around.
269 // TODO: Rather than just disappearing, maybe we should inform
270 // the user what has happened, let them close us. Less surprising.
Jon Mann9bd40992017-03-24 12:34:34 -0700271 if (mProviders.getRootBlocking(root.authority, root.rootId) == null) {
Steve McKay459bc2b2015-09-16 15:07:31 -0700272 finish();
273 }
274 }
275
276 @Override
Steve McKay18d01e82016-02-03 11:15:57 -0800277 public String getDrawerTitle() {
Steve McKay17f7e582016-04-04 15:26:48 -0700278 Intent intent = getIntent();
279 return (intent != null && intent.hasExtra(Intent.EXTRA_TITLE))
280 ? intent.getStringExtra(Intent.EXTRA_TITLE)
Steve McKaya0b52652016-10-27 12:56:55 -0700281 : getString(R.string.app_label);
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700282 }
283
284 @Override
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700285 public boolean onPrepareOptionsMenu(Menu menu) {
Steve McKaye9809272015-10-01 11:39:24 -0700286 super.onPrepareOptionsMenu(menu);
Steve McKay92ae43d2016-11-08 12:06:58 -0800287 mInjector.menuManager.updateOptionMenu(menu);
Steve McKaye9809272015-10-01 11:39:24 -0700288 return true;
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700289 }
290
291 @Override
Steve McKay1f199482015-05-20 15:58:42 -0700292 public boolean onOptionsItemSelected(MenuItem item) {
Jon Mann49be24c2017-02-13 17:29:20 -0800293 DirectoryFragment dir;
Steve McKayf2c8b0d2015-09-23 15:44:24 -0700294 switch (item.getItemId()) {
Ben Linff7f3ae2017-04-25 16:08:52 -0700295 case R.id.option_menu_create_dir:
Steve McKay0af8afd2016-02-25 13:34:03 -0800296 assert(canCreateDirectory());
Ben Linff7f3ae2017-04-25 16:08:52 -0700297 mInjector.actions.showCreateDirectoryDialog();
Aga Wronska4972d712016-03-30 13:55:19 -0700298 break;
Ben Linff7f3ae2017-04-25 16:08:52 -0700299 case R.id.option_menu_new_window:
Steve McKay92ae43d2016-11-08 12:06:58 -0800300 mInjector.actions.openInNewWindow(mState.stack);
Aga Wronska4972d712016-03-30 13:55:19 -0700301 break;
Ben Linff7f3ae2017-04-25 16:08:52 -0700302 case R.id.option_menu_settings:
Steve McKay92ae43d2016-11-08 12:06:58 -0800303 mInjector.actions.openSettings(getCurrentRoot());
Ben Lin5668b862016-06-28 17:12:52 -0700304 break;
Ben Linff7f3ae2017-04-25 16:08:52 -0700305 case R.id.option_menu_select_all:
Jon Mann30d8c792017-02-21 17:44:49 -0800306 mInjector.actions.selectAllFiles();
Jon Mann49be24c2017-02-13 17:29:20 -0800307 break;
Steve McKay0c7ad032017-08-09 11:50:10 -0700308 case R.id.option_menu_inspect:
Steve McKayefd10ac2017-07-25 13:33:57 -0700309 mInjector.actions.showInspector(getCurrentDirectory());
310 break;
Aga Wronska4972d712016-03-30 13:55:19 -0700311 default:
312 return super.onOptionsItemSelected(item);
Steve McKay1f199482015-05-20 15:58:42 -0700313 }
Aga Wronska4972d712016-03-30 13:55:19 -0700314 return true;
Steve McKay1f199482015-05-20 15:58:42 -0700315 }
316
317 @Override
Ben Lina8673232016-09-28 15:40:04 -0700318 public void onProvideKeyboardShortcuts(
319 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
Steve McKay92ae43d2016-11-08 12:06:58 -0800320 mInjector.menuManager.updateKeyboardShortcutsMenu(data, this::getString);
Ben Lina8673232016-09-28 15:40:04 -0700321 }
322
323 @Override
Steve McKay988d8a32016-09-27 09:41:17 -0700324 public void refreshDirectory(@AnimationType int anim) {
Tony Huang8d8d92f2018-09-13 14:41:16 +0800325 final FragmentManager fm = getSupportFragmentManager();
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700326 final RootInfo root = getCurrentRoot();
327 final DocumentInfo cwd = getCurrentDirectory();
328
Steve McKay0af8afd2016-02-25 13:34:03 -0800329 assert(!mSearchManager.isSearching());
Aga Wronskaaf5ace52016-02-17 13:50:42 -0800330
Garfield Tane9670332017-03-06 18:33:23 -0800331 if (mState.stack.isRecents()) {
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700332 DirectoryFragment.showRecentsOpen(fm, anim);
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700333 } else {
Aga Wronskaaf5ace52016-02-17 13:50:42 -0800334 // Normal boring directory
335 DirectoryFragment.showDirectory(fm, root, cwd, anim);
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700336 }
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700337 }
338
339 @Override
Steve McKay351a7492015-08-04 10:11:01 -0700340 public void onDocumentsPicked(List<DocumentInfo> docs) {
341 throw new UnsupportedOperationException();
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700342 }
343
Steve McKay351a7492015-08-04 10:11:01 -0700344 @Override
Steve McKayeed2f4e2016-10-03 20:30:52 -0700345 public void onDocumentPicked(DocumentInfo doc) {
Tomasz Mikolajewskid22cc182017-03-15 16:13:46 +0900346 throw new UnsupportedOperationException();
Tomasz Mikolajewskibe4e38b2016-04-07 18:00:08 +0900347 }
348
Garfield, Tan804133e2016-04-20 15:13:56 -0700349 @Override
Steve McKay16e0c1f2016-09-15 12:41:13 -0700350 public void onDirectoryCreated(DocumentInfo doc) {
Ben Lin81afd7f2016-08-22 18:24:03 -0700351 assert(doc.isDirectory());
Steve McKay92ae43d2016-11-08 12:06:58 -0800352 mInjector.focusManager.focusDocument(doc.documentId);
Ben Lin81afd7f2016-08-22 18:24:03 -0700353 }
354
Takamasa Kuramitsu59710522018-06-29 18:42:21 +0900355 @Override
356 protected boolean canInspectDirectory() {
357 return getCurrentDirectory() != null && mInjector.getModel().doc != null;
358 }
359
Ben Linaa66c432016-10-12 12:11:24 -0700360 @CallSuper
361 @Override
362 public boolean onKeyDown(int keyCode, KeyEvent event) {
Steve McKay04718262016-11-08 11:01:35 -0800363 return mActivityInputHandler.onKeyDown(keyCode, event)
Bill Lin35bfbef2019-08-05 16:09:53 +0800364 || mSharedInputHandler.onKeyDown(keyCode, event)
Steve McKay04718262016-11-08 11:01:35 -0800365 || super.onKeyDown(keyCode, event);
Ben Linaa66c432016-10-12 12:11:24 -0700366 }
367
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700368 @Override
Steve McKay0599a442015-05-05 14:50:00 -0700369 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
370 DirectoryFragment dir;
Steve McKayd4800812016-02-02 11:41:03 -0800371 // TODO: All key events should be statically bound using alphabeticShortcut.
372 // But not working.
Steve McKay0599a442015-05-05 14:50:00 -0700373 switch (keyCode) {
374 case KeyEvent.KEYCODE_A:
Jon Mann30d8c792017-02-21 17:44:49 -0800375 mInjector.actions.selectAllFiles();
Steve McKay0599a442015-05-05 14:50:00 -0700376 return true;
Ben Linff4d5842016-04-18 14:35:28 -0700377 case KeyEvent.KEYCODE_X:
Steve McKay92ae43d2016-11-08 12:06:58 -0800378 mInjector.actions.cutToClipboard();
Ben Linff4d5842016-04-18 14:35:28 -0700379 return true;
Steve McKay1f199482015-05-20 15:58:42 -0700380 case KeyEvent.KEYCODE_C:
Steve McKay92ae43d2016-11-08 12:06:58 -0800381 mInjector.actions.copyToClipboard();
Steve McKay6035b3c2015-12-04 11:19:09 -0800382 return true;
383 case KeyEvent.KEYCODE_V:
Steve McKayd4800812016-02-02 11:41:03 -0800384 dir = getDirectoryFragment();
385 if (dir != null) {
386 dir.pasteFromClipboard();
387 }
Steve McKay6035b3c2015-12-04 11:19:09 -0800388 return true;
389 default:
390 return super.onKeyShortcut(keyCode, event);
Steve McKay0599a442015-05-05 14:50:00 -0700391 }
392 }
393
Steve McKayb68dd222015-04-20 17:18:15 -0700394 @Override
Steve McKay92ae43d2016-11-08 12:06:58 -0800395 public Injector<ActionHandler<FilesActivity>> getInjector() {
396 return mInjector;
Steve McKayc8889af2016-09-23 11:22:41 -0700397 }
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700398}