blob: c61f8a92e43266b97d051b821c8b16a0f0824e4e [file] [log] [blame]
Jeff Sharkeye22d02e2013-04-26 16:54:55 -07001/*
2 * Copyright (C) 2013 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 McKay16e0c1f2016-09-15 12:41:13 -070017package com.android.documentsui.picker;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070018
Steve McKayd9caa6a2016-09-15 16:36:45 -070019import static com.android.documentsui.base.Shared.DEBUG;
20import static com.android.documentsui.base.State.ACTION_CREATE;
21import static com.android.documentsui.base.State.ACTION_GET_CONTENT;
22import static com.android.documentsui.base.State.ACTION_OPEN;
23import static com.android.documentsui.base.State.ACTION_OPEN_TREE;
24import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION;
Jeff Sharkey311a7d82015-04-11 21:27:21 -070025
Steve McKayb68dd222015-04-20 17:18:15 -070026import android.app.Fragment;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070027import android.app.FragmentManager;
Jeff Sharkey1d890e02013-08-15 11:24:03 -070028import android.content.ComponentName;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070029import android.content.Intent;
Jeff Sharkey1d890e02013-08-15 11:24:03 -070030import android.content.pm.ResolveInfo;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070031import android.net.Uri;
32import android.os.Bundle;
Jeff Sharkeyf339f252013-08-15 16:17:41 -070033import android.provider.DocumentsContract;
Steve McKay04718262016-11-08 11:01:35 -080034import android.support.annotation.CallSuper;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070035import android.util.Log;
Steve McKay04718262016-11-08 11:01:35 -080036import android.view.KeyEvent;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070037import android.view.Menu;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070038
Steve McKaybd9f05a2016-10-10 10:18:36 -070039import com.android.documentsui.ActionModeController;
Steve McKay16e0c1f2016-09-15 12:41:13 -070040import com.android.documentsui.BaseActivity;
Ben Lin75b7b902016-11-02 15:59:29 -070041import com.android.documentsui.FocusManager;
Steve McKay92ae43d2016-11-08 12:06:58 -080042import com.android.documentsui.Injector;
Steve McKay16e0c1f2016-09-15 12:41:13 -070043import com.android.documentsui.MenuManager.DirectoryDetails;
Steve McKay988d8a32016-09-27 09:41:17 -070044import com.android.documentsui.ProviderExecutor;
Steve McKay990f76e2016-09-16 12:36:58 -070045import com.android.documentsui.R;
Steve McKay04718262016-11-08 11:01:35 -080046import com.android.documentsui.SharedInputHandler;
Steve McKayd0805062016-09-15 14:30:38 -070047import com.android.documentsui.base.DocumentInfo;
Steve McKay98f8c5f2017-03-03 13:52:14 -080048import com.android.documentsui.base.Features;
Steve McKayd0718952016-10-10 13:43:36 -070049import com.android.documentsui.base.MimeTypes;
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.Shared;
52import com.android.documentsui.base.State;
Steve McKayf68210e2015-11-03 15:23:16 -080053import com.android.documentsui.dirlist.DirectoryFragment;
Steve McKaye8b547f2016-12-19 14:42:55 -080054import com.android.documentsui.prefs.ScopedPreferences;
Steve McKay4f78ba62016-10-04 16:48:49 -070055import com.android.documentsui.selection.SelectionManager;
Steve McKayc83baa02016-01-06 18:32:13 -080056import com.android.documentsui.services.FileOperationService;
Steve McKayd0805062016-09-15 14:30:38 -070057import com.android.documentsui.sidebar.RootsFragment;
Steve McKayc8889af2016-09-23 11:22:41 -070058import com.android.documentsui.ui.DialogController;
Steve McKay92ae43d2016-11-08 12:06:58 -080059import com.android.documentsui.ui.MessageBuilder;
Jeff Sharkeyf7adc932013-07-30 17:08:39 -070060
Ben Kwa0e66b9b2015-05-18 13:18:05 -070061import java.util.List;
62
Steve McKay92ae43d2016-11-08 12:06:58 -080063public class PickActivity extends BaseActivity implements ActionHandler.Addons {
64
65 static final String PREFERENCES_SCOPE = "picker";
Steve McKay990f76e2016-09-16 12:36:58 -070066
Steve McKayb6006b22016-09-29 09:23:45 -070067 private static final String TAG = "PickActivity";
Steve McKay6525a192016-10-18 14:28:00 -070068 private static final int CODE_FORWARD = 42;
69
Steve McKay92ae43d2016-11-08 12:06:58 -080070 private Injector<ActionHandler<PickActivity>> mInjector;
Steve McKay04718262016-11-08 11:01:35 -080071 private SharedInputHandler mSharedInputHandler;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070072
Garfield Tan23ac60c2017-03-13 17:40:43 -070073 private LastAccessedStorage mLastAccessed;
74
Steve McKay16e0c1f2016-09-15 12:41:13 -070075 public PickActivity() {
Steve McKay18d01e82016-02-03 11:15:57 -080076 super(R.layout.documents_activity, TAG);
Steve McKayb68dd222015-04-20 17:18:15 -070077 }
78
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070079 @Override
80 public void onCreate(Bundle icicle) {
Steve McKay6525a192016-10-18 14:28:00 -070081
Steve McKay92ae43d2016-11-08 12:06:58 -080082 mInjector = new Injector<>(
Steve McKay98f8c5f2017-03-03 13:52:14 -080083 Features.create(getResources()),
Steve McKay92ae43d2016-11-08 12:06:58 -080084 new Config(),
85 ScopedPreferences.create(this, PREFERENCES_SCOPE),
86 new MessageBuilder(this),
Garfield Tan23ac60c2017-03-13 17:40:43 -070087 DialogController.create(this, null));
Steve McKay6525a192016-10-18 14:28:00 -070088
Steve McKay0fbfc652015-08-20 16:48:49 -070089 super.onCreate(icicle);
Steve McKay739f94b2016-09-22 14:54:23 -070090
Steve McKay92ae43d2016-11-08 12:06:58 -080091 mInjector.selectionMgr = new SelectionManager(
Steve McKay4f78ba62016-10-04 16:48:49 -070092 mState.allowMultiple
93 ? SelectionManager.MODE_MULTIPLE
94 : SelectionManager.MODE_SINGLE);
Steve McKay04718262016-11-08 11:01:35 -080095
Steve McKay92ae43d2016-11-08 12:06:58 -080096 mInjector.focusManager = new FocusManager(
Steve McKay98f8c5f2017-03-03 13:52:14 -080097 mInjector.features,
Steve McKay92ae43d2016-11-08 12:06:58 -080098 mInjector.selectionMgr,
Steve McKay04718262016-11-08 11:01:35 -080099 mDrawer,
Steve McKay92ae43d2016-11-08 12:06:58 -0800100 this::focusSidebar,
Steve McKay04718262016-11-08 11:01:35 -0800101 getColor(R.color.accent_dark));
102
Steve McKay92ae43d2016-11-08 12:06:58 -0800103 mInjector.menuManager = new MenuManager(mSearchManager, mState, new DirectoryDetails(this));
Garfield Tane9670332017-03-06 18:33:23 -0800104
Steve McKay92ae43d2016-11-08 12:06:58 -0800105 mInjector.actionModeController = new ActionModeController(
Steve McKay5b0a2c12016-10-07 11:22:31 -0700106 this,
Steve McKay92ae43d2016-11-08 12:06:58 -0800107 mInjector.selectionMgr,
108 mInjector.menuManager,
109 mInjector.messages);
Garfield Tane9670332017-03-06 18:33:23 -0800110
Garfield Tan23ac60c2017-03-13 17:40:43 -0700111 mLastAccessed = LastAccessedStorage.create();
Jon Mann30d8c792017-02-21 17:44:49 -0800112 mInjector.actions = new ActionHandler<>(
113 this,
114 mState,
115 mRoots,
116 mDocs,
117 mSearchManager,
118 ProviderExecutor::forAuthority,
Garfield Tan23ac60c2017-03-13 17:40:43 -0700119 mInjector,
120 mLastAccessed);
Steve McKay5b0a2c12016-10-07 11:22:31 -0700121
Garfield Tane9670332017-03-06 18:33:23 -0800122 mInjector.searchManager = mSearchManager;
123
Steve McKay988d8a32016-09-27 09:41:17 -0700124 Intent intent = getIntent();
125
Steve McKay98f8c5f2017-03-03 13:52:14 -0800126 mSharedInputHandler =
Ben Lin0902f072017-03-13 18:25:29 -0700127 new SharedInputHandler(
128 mInjector.focusManager,
129 mInjector.selectionMgr,
130 mInjector.searchManager::cancelSearch,
131 this::popDir,
132 mInjector.features);
Steve McKay988d8a32016-09-27 09:41:17 -0700133 setupLayout(intent);
Steve McKay92ae43d2016-11-08 12:06:58 -0800134 mInjector.actions.initLocation(intent);
Steve McKay988d8a32016-09-27 09:41:17 -0700135 }
136
137 private void setupLayout(Intent intent) {
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700138 if (mState.action == ACTION_CREATE) {
Steve McKay988d8a32016-09-27 09:41:17 -0700139 final String mimeType = intent.getType();
140 final String title = intent.getStringExtra(Intent.EXTRA_TITLE);
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700141 SaveFragment.show(getFragmentManager(), mimeType, title);
Daichi Hironocaadd412015-04-10 15:50:38 +0900142 } else if (mState.action == ACTION_OPEN_TREE ||
Ben Kwaae967802015-09-25 14:48:29 -0700143 mState.action == ACTION_PICK_COPY_DESTINATION) {
Jeff Sharkey6e565ff2014-04-05 19:05:24 -0700144 PickFragment.show(getFragmentManager());
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700145 }
146
147 if (mState.action == ACTION_GET_CONTENT) {
Steve McKay988d8a32016-09-27 09:41:17 -0700148 final Intent moreApps = new Intent(intent);
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700149 moreApps.setComponent(null);
150 moreApps.setPackage(null);
151 RootsFragment.show(getFragmentManager(), moreApps);
Daichi Hironocaadd412015-04-10 15:50:38 +0900152 } else if (mState.action == ACTION_OPEN ||
153 mState.action == ACTION_CREATE ||
154 mState.action == ACTION_OPEN_TREE ||
Ben Kwaae967802015-09-25 14:48:29 -0700155 mState.action == ACTION_PICK_COPY_DESTINATION) {
Ben Lin821727a2016-07-08 10:49:53 -0700156 RootsFragment.show(getFragmentManager(), (Intent) null);
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700157 }
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700158 }
159
Steve McKay0fbfc652015-08-20 16:48:49 -0700160 @Override
Steve McKay16e0c1f2016-09-15 12:41:13 -0700161 protected void includeState(State state) {
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700162 final Intent intent = getIntent();
Garfield Tan78ade2b2017-02-28 13:19:53 -0800163
164 String defaultMimeType = (intent.getType() == null) ? "*/*" : intent.getType();
165 state.initAcceptMimes(intent, defaultMimeType);
166
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700167 final String action = intent.getAction();
168 if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) {
Steve McKayb68dd222015-04-20 17:18:15 -0700169 state.action = ACTION_OPEN;
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700170 } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) {
Steve McKayb68dd222015-04-20 17:18:15 -0700171 state.action = ACTION_CREATE;
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700172 } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
Steve McKayb68dd222015-04-20 17:18:15 -0700173 state.action = ACTION_GET_CONTENT;
Jeff Sharkeyf4943e12014-06-04 16:42:47 -0700174 } else if (Intent.ACTION_OPEN_DOCUMENT_TREE.equals(action)) {
Steve McKayb68dd222015-04-20 17:18:15 -0700175 state.action = ACTION_OPEN_TREE;
Ben Kwaae967802015-09-25 14:48:29 -0700176 } else if (Shared.ACTION_PICK_COPY_DESTINATION.equals(action)) {
177 state.action = ACTION_PICK_COPY_DESTINATION;
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700178 }
179
Steve McKayb68dd222015-04-20 17:18:15 -0700180 if (state.action == ACTION_OPEN || state.action == ACTION_GET_CONTENT) {
181 state.allowMultiple = intent.getBooleanExtra(
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700182 Intent.EXTRA_ALLOW_MULTIPLE, false);
183 }
184
Tomasz Mikolajewski95d9c252015-11-16 11:41:28 +0900185 if (state.action == ACTION_OPEN || state.action == ACTION_GET_CONTENT
186 || state.action == ACTION_CREATE) {
187 state.openableOnly = intent.hasCategory(Intent.CATEGORY_OPENABLE);
188 }
189
Ben Kwaae967802015-09-25 14:48:29 -0700190 if (state.action == ACTION_PICK_COPY_DESTINATION) {
Steve McKayf1719342016-02-17 15:02:01 -0800191 // Indicates that a copy operation (or move) includes a directory.
192 // Why? Directory creation isn't supported by some roots (like Downloads).
193 // This allows us to restrict available roots to just those with support.
Steve McKayb68dd222015-04-20 17:18:15 -0700194 state.directoryCopy = intent.getBooleanExtra(
Ben Kwaae967802015-09-25 14:48:29 -0700195 Shared.EXTRA_DIRECTORY_COPY, false);
Steve McKayf1719342016-02-17 15:02:01 -0800196 state.copyOperationSubType = intent.getIntExtra(
Garfield, Tan48334772016-06-28 17:17:38 -0700197 FileOperationService.EXTRA_OPERATION_TYPE,
Steve McKayc83baa02016-01-06 18:32:13 -0800198 FileOperationService.OPERATION_COPY);
Daichi Hironof2a822d2015-04-14 17:12:54 +0900199 }
Jeff Sharkey8b997042013-09-19 15:25:56 -0700200 }
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700201
Steve McKayc8889af2016-09-23 11:22:41 -0700202 @Override
Steve McKayb68dd222015-04-20 17:18:15 -0700203 public void onAppPicked(ResolveInfo info) {
204 final Intent intent = new Intent(getIntent());
205 intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_FORWARD_RESULT);
206 intent.setComponent(new ComponentName(
207 info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
208 startActivityForResult(intent, CODE_FORWARD);
209 }
Jeff Sharkey38ec2522013-09-24 12:07:12 -0700210
Steve McKayb68dd222015-04-20 17:18:15 -0700211 @Override
212 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Ben Kwa543a2922016-03-22 11:11:46 -0700213 if (DEBUG) Log.d(TAG, "onActivityResult() code=" + resultCode);
Jeff Sharkey38ec2522013-09-24 12:07:12 -0700214
Steve McKayb68dd222015-04-20 17:18:15 -0700215 // Only relay back results when not canceled; otherwise stick around to
216 // let the user pick another app/backend.
217 if (requestCode == CODE_FORWARD && resultCode != RESULT_CANCELED) {
Jeff Sharkey8b997042013-09-19 15:25:56 -0700218
Steve McKayb68dd222015-04-20 17:18:15 -0700219 // Remember that we last picked via external app
Garfield Tan23ac60c2017-03-13 17:40:43 -0700220 mLastAccessed.setLastAccessedToExternalApp(this);
Steve McKayb68dd222015-04-20 17:18:15 -0700221
222 // Pass back result to original caller
223 setResult(resultCode, data);
224 finish();
225 } else {
226 super.onActivityResult(requestCode, resultCode, data);
Jeff Sharkeyf339f252013-08-15 16:17:41 -0700227 }
228 }
229
Jeff Sharkey46165b52013-07-31 20:53:22 -0700230 @Override
231 protected void onPostCreate(Bundle savedInstanceState) {
232 super.onPostCreate(savedInstanceState);
Steve McKay18d01e82016-02-03 11:15:57 -0800233 mDrawer.update();
234 mNavigator.update();
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700235 }
236
Steve McKayb68dd222015-04-20 17:18:15 -0700237 @Override
Steve McKay18d01e82016-02-03 11:15:57 -0800238 public String getDrawerTitle() {
239 String title = getIntent().getStringExtra(DocumentsContract.EXTRA_PROMPT);
240 if (title == null) {
241 if (mState.action == ACTION_OPEN ||
242 mState.action == ACTION_GET_CONTENT ||
243 mState.action == ACTION_OPEN_TREE) {
244 title = getResources().getString(R.string.title_open);
245 } else if (mState.action == ACTION_CREATE ||
246 mState.action == ACTION_PICK_COPY_DESTINATION) {
247 title = getResources().getString(R.string.title_save);
Tomasz Mikolajewski77fd4022015-06-12 16:22:17 -0700248 } else {
Steve McKay17f7e582016-04-04 15:26:48 -0700249 // If all else fails, just call it "Documents".
250 title = getResources().getString(R.string.app_label);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700251 }
Jeff Sharkeye6fcceb2014-07-28 16:38:52 -0700252 }
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700253
Steve McKay18d01e82016-02-03 11:15:57 -0800254 return title;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700255 }
256
257 @Override
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700258 public boolean onPrepareOptionsMenu(Menu menu) {
259 super.onPrepareOptionsMenu(menu);
Steve McKay92ae43d2016-11-08 12:06:58 -0800260 mInjector.menuManager.updateOptionMenu(menu);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700261
Jeff Sharkey724deeb2013-08-31 15:02:20 -0700262 final DocumentInfo cwd = getCurrentDirectory();
Jeff Sharkey5b535922013-08-02 15:55:26 -0700263
Steve McKaye9809272015-10-01 11:39:24 -0700264 if (mState.action == ACTION_CREATE) {
265 final FragmentManager fm = getFragmentManager();
Steve McKay0fe95042015-10-14 17:41:13 -0700266 SaveFragment.get(fm).prepareForDirectory(cwd);
Jeff Sharkey5b535922013-08-02 15:55:26 -0700267 }
Jeff Sharkey46165b52013-07-31 20:53:22 -0700268
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700269 return true;
270 }
271
272 @Override
Steve McKay16e0c1f2016-09-15 12:41:13 -0700273 protected void refreshDirectory(int anim) {
Jeff Sharkey5b535922013-08-02 15:55:26 -0700274 final FragmentManager fm = getFragmentManager();
Jeff Sharkeya4d1f222013-09-07 14:45:03 -0700275 final RootInfo root = getCurrentRoot();
Jeff Sharkey724deeb2013-08-31 15:02:20 -0700276 final DocumentInfo cwd = getCurrentDirectory();
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700277
Garfield Tane9670332017-03-06 18:33:23 -0800278 if (mState.stack.isRecents()) {
Garfield Tanae937582017-03-09 13:57:07 -0800279 DirectoryFragment.showRecentsOpen(fm, anim);
Jeff Sharkey7d58fc62013-09-12 16:25:02 -0700280
Garfield Tanae937582017-03-09 13:57:07 -0800281 // In recents we pick layout mode based on the mimetype,
282 // picking GRID for visual types. We intentionally don't
283 // consult a user's saved preferences here since they are
284 // set per root (not per root and per mimetype).
285 boolean visualMimes = MimeTypes.mimeMatches(
286 MimeTypes.VISUAL_MIMES, mState.acceptMimes);
287 mState.derivedMode = visualMimes ? State.MODE_GRID : State.MODE_LIST;
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700288 } else {
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700289 // Normal boring directory
Aga Wronska8788dad2016-01-15 17:30:15 -0800290 DirectoryFragment.showDirectory(fm, root, cwd, anim);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700291 }
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700292
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700293 // Forget any replacement target
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700294 if (mState.action == ACTION_CREATE) {
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700295 final SaveFragment save = SaveFragment.get(fm);
296 if (save != null) {
297 save.setReplaceTarget(null);
298 }
299 }
300
Daichi Hironocaadd412015-04-10 15:50:38 +0900301 if (mState.action == ACTION_OPEN_TREE ||
Ben Kwaae967802015-09-25 14:48:29 -0700302 mState.action == ACTION_PICK_COPY_DESTINATION) {
Jeff Sharkey6e565ff2014-04-05 19:05:24 -0700303 final PickFragment pick = PickFragment.get(fm);
304 if (pick != null) {
Steve McKayf1719342016-02-17 15:02:01 -0800305 pick.setPickTarget(mState.action, mState.copyOperationSubType, cwd);
Jeff Sharkey6e565ff2014-04-05 19:05:24 -0700306 }
307 }
Steve McKayb68dd222015-04-20 17:18:15 -0700308 }
Jeff Sharkey6e565ff2014-04-05 19:05:24 -0700309
Steve McKay16e0c1f2016-09-15 12:41:13 -0700310 @Override
311 protected void onDirectoryCreated(DocumentInfo doc) {
Steve McKay0af8afd2016-02-25 13:34:03 -0800312 assert(doc.isDirectory());
Steve McKay92ae43d2016-11-08 12:06:58 -0800313 mInjector.actions.openContainerDocument(doc);
Steve McKay5e1acc92016-02-19 12:57:05 -0800314 }
315
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700316 @Override
Steve McKayeed2f4e2016-10-03 20:30:52 -0700317 public void onDocumentPicked(DocumentInfo doc) {
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700318 final FragmentManager fm = getFragmentManager();
Tomasz Mikolajewski52fe4232016-11-25 14:23:39 +0900319 // Do not inline-open archives, as otherwise it would be impossible to pick
320 // archive files. Note, that picking files inside archives is not supported.
321 if (doc.isDirectory()) {
Steve McKay92ae43d2016-11-08 12:06:58 -0800322 mInjector.actions.openContainerDocument(doc);
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700323 } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700324 // Explicit file picked, return
Garfield Tan23ac60c2017-03-13 17:40:43 -0700325 mInjector.actions.finishPicking(doc.derivedUri);
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700326 } else if (mState.action == ACTION_CREATE) {
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700327 // Replace selected file
328 SaveFragment.get(fm).setReplaceTarget(doc);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700329 }
330 }
331
Steve McKayd0a2a2c2015-03-25 14:35:33 -0700332 @Override
Jeff Sharkey724deeb2013-08-31 15:02:20 -0700333 public void onDocumentsPicked(List<DocumentInfo> docs) {
Jeff Sharkeyb3620442013-09-01 18:41:04 -0700334 if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
Jeff Sharkey873daa32013-08-18 17:38:20 -0700335 final int size = docs.size();
336 final Uri[] uris = new Uri[size];
337 for (int i = 0; i < size; i++) {
Jeff Sharkeya4d1f222013-09-07 14:45:03 -0700338 uris[i] = docs.get(i).derivedUri;
Jeff Sharkey873daa32013-08-18 17:38:20 -0700339 }
Garfield Tan23ac60c2017-03-13 17:40:43 -0700340 mInjector.actions.finishPicking(uris);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700341 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700342 }
343
Steve McKay04718262016-11-08 11:01:35 -0800344 @CallSuper
345 @Override
346 public boolean onKeyDown(int keyCode, KeyEvent event) {
Ben Lin0902f072017-03-13 18:25:29 -0700347 return mSharedInputHandler.onKeyDown(
348 keyCode,
349 event)
Steve McKay04718262016-11-08 11:01:35 -0800350 || super.onKeyDown(keyCode, event);
351 }
Steve McKayc7dc0cf2016-02-04 12:15:22 -0800352
Garfield Tan894d4872017-03-17 12:23:22 -0700353 @Override
354 public void setResult(int resultCode, Intent intent, int notUsed) {
355 setResult(resultCode, intent);
356 }
357
Steve McKay16e0c1f2016-09-15 12:41:13 -0700358 public static PickActivity get(Fragment fragment) {
359 return (PickActivity) fragment.getActivity();
Steve McKayb68dd222015-04-20 17:18:15 -0700360 }
361
Steve McKay92ae43d2016-11-08 12:06:58 -0800362 @Override
363 public Injector<ActionHandler<PickActivity>> getInjector() {
364 return mInjector;
365 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700366}