Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 1 | /* |
| 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 McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 17 | package com.android.documentsui.picker; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 18 | |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 19 | import static com.android.documentsui.base.Shared.DEBUG; |
| 20 | import static com.android.documentsui.base.State.ACTION_CREATE; |
| 21 | import static com.android.documentsui.base.State.ACTION_GET_CONTENT; |
| 22 | import static com.android.documentsui.base.State.ACTION_OPEN; |
| 23 | import static com.android.documentsui.base.State.ACTION_OPEN_TREE; |
| 24 | import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION; |
Jeff Sharkey | 311a7d8 | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 25 | |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 26 | import android.app.Fragment; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 27 | import android.app.FragmentManager; |
Jeff Sharkey | 1d890e0 | 2013-08-15 11:24:03 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 29 | import android.content.Intent; |
Jeff Sharkey | 1d890e0 | 2013-08-15 11:24:03 -0700 | [diff] [blame] | 30 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 31 | import android.net.Uri; |
| 32 | import android.os.Bundle; |
Jeff Sharkey | f339f25 | 2013-08-15 16:17:41 -0700 | [diff] [blame] | 33 | import android.provider.DocumentsContract; |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 34 | import android.support.annotation.CallSuper; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 35 | import android.util.Log; |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 36 | import android.view.KeyEvent; |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 37 | import android.view.Menu; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 38 | |
Steve McKay | bd9f05a | 2016-10-10 10:18:36 -0700 | [diff] [blame] | 39 | import com.android.documentsui.ActionModeController; |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 40 | import com.android.documentsui.BaseActivity; |
Ben Lin | 75b7b90 | 2016-11-02 15:59:29 -0700 | [diff] [blame] | 41 | import com.android.documentsui.FocusManager; |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 42 | import com.android.documentsui.Injector; |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 43 | import com.android.documentsui.MenuManager.DirectoryDetails; |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 44 | import com.android.documentsui.ProviderExecutor; |
Steve McKay | 990f76e | 2016-09-16 12:36:58 -0700 | [diff] [blame] | 45 | import com.android.documentsui.R; |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 46 | import com.android.documentsui.SharedInputHandler; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 47 | import com.android.documentsui.base.DocumentInfo; |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 48 | import com.android.documentsui.base.Features; |
Steve McKay | d071895 | 2016-10-10 13:43:36 -0700 | [diff] [blame] | 49 | import com.android.documentsui.base.MimeTypes; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 50 | import com.android.documentsui.base.RootInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 51 | import com.android.documentsui.base.Shared; |
| 52 | import com.android.documentsui.base.State; |
Steve McKay | f68210e | 2015-11-03 15:23:16 -0800 | [diff] [blame] | 53 | import com.android.documentsui.dirlist.DirectoryFragment; |
Steve McKay | e8b547f | 2016-12-19 14:42:55 -0800 | [diff] [blame] | 54 | import com.android.documentsui.prefs.ScopedPreferences; |
Steve McKay | 4f78ba6 | 2016-10-04 16:48:49 -0700 | [diff] [blame] | 55 | import com.android.documentsui.selection.SelectionManager; |
Steve McKay | c83baa0 | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 56 | import com.android.documentsui.services.FileOperationService; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 57 | import com.android.documentsui.sidebar.RootsFragment; |
Steve McKay | c8889af | 2016-09-23 11:22:41 -0700 | [diff] [blame] | 58 | import com.android.documentsui.ui.DialogController; |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 59 | import com.android.documentsui.ui.MessageBuilder; |
Jeff Sharkey | f7adc93 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 60 | |
Ben Kwa | 0e66b9b | 2015-05-18 13:18:05 -0700 | [diff] [blame] | 61 | import java.util.List; |
| 62 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 63 | public class PickActivity extends BaseActivity implements ActionHandler.Addons { |
| 64 | |
| 65 | static final String PREFERENCES_SCOPE = "picker"; |
Steve McKay | 990f76e | 2016-09-16 12:36:58 -0700 | [diff] [blame] | 66 | |
Steve McKay | b6006b2 | 2016-09-29 09:23:45 -0700 | [diff] [blame] | 67 | private static final String TAG = "PickActivity"; |
Steve McKay | 6525a19 | 2016-10-18 14:28:00 -0700 | [diff] [blame] | 68 | private static final int CODE_FORWARD = 42; |
| 69 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 70 | private Injector<ActionHandler<PickActivity>> mInjector; |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 71 | private SharedInputHandler mSharedInputHandler; |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 72 | |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 73 | private LastAccessedStorage mLastAccessed; |
| 74 | |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 75 | public PickActivity() { |
Steve McKay | 18d01e8 | 2016-02-03 11:15:57 -0800 | [diff] [blame] | 76 | super(R.layout.documents_activity, TAG); |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 79 | @Override |
| 80 | public void onCreate(Bundle icicle) { |
Steve McKay | 6525a19 | 2016-10-18 14:28:00 -0700 | [diff] [blame] | 81 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 82 | mInjector = new Injector<>( |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 83 | Features.create(getResources()), |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 84 | new Config(), |
| 85 | ScopedPreferences.create(this, PREFERENCES_SCOPE), |
| 86 | new MessageBuilder(this), |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 87 | DialogController.create(this, null)); |
Steve McKay | 6525a19 | 2016-10-18 14:28:00 -0700 | [diff] [blame] | 88 | |
Steve McKay | 0fbfc65 | 2015-08-20 16:48:49 -0700 | [diff] [blame] | 89 | super.onCreate(icicle); |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 90 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 91 | mInjector.selectionMgr = new SelectionManager( |
Steve McKay | 4f78ba6 | 2016-10-04 16:48:49 -0700 | [diff] [blame] | 92 | mState.allowMultiple |
| 93 | ? SelectionManager.MODE_MULTIPLE |
| 94 | : SelectionManager.MODE_SINGLE); |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 95 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 96 | mInjector.focusManager = new FocusManager( |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 97 | mInjector.features, |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 98 | mInjector.selectionMgr, |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 99 | mDrawer, |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 100 | this::focusSidebar, |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 101 | getColor(R.color.accent_dark)); |
| 102 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 103 | mInjector.menuManager = new MenuManager(mSearchManager, mState, new DirectoryDetails(this)); |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 104 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 105 | mInjector.actionModeController = new ActionModeController( |
Steve McKay | 5b0a2c1 | 2016-10-07 11:22:31 -0700 | [diff] [blame] | 106 | this, |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 107 | mInjector.selectionMgr, |
| 108 | mInjector.menuManager, |
| 109 | mInjector.messages); |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 110 | |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 111 | mLastAccessed = LastAccessedStorage.create(); |
Jon Mann | 30d8c79 | 2017-02-21 17:44:49 -0800 | [diff] [blame] | 112 | mInjector.actions = new ActionHandler<>( |
| 113 | this, |
| 114 | mState, |
| 115 | mRoots, |
| 116 | mDocs, |
| 117 | mSearchManager, |
| 118 | ProviderExecutor::forAuthority, |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 119 | mInjector, |
| 120 | mLastAccessed); |
Steve McKay | 5b0a2c1 | 2016-10-07 11:22:31 -0700 | [diff] [blame] | 121 | |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 122 | mInjector.searchManager = mSearchManager; |
| 123 | |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 124 | Intent intent = getIntent(); |
| 125 | |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 126 | mSharedInputHandler = |
Ben Lin | 0902f07 | 2017-03-13 18:25:29 -0700 | [diff] [blame] | 127 | new SharedInputHandler( |
| 128 | mInjector.focusManager, |
| 129 | mInjector.selectionMgr, |
| 130 | mInjector.searchManager::cancelSearch, |
| 131 | this::popDir, |
| 132 | mInjector.features); |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 133 | setupLayout(intent); |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 134 | mInjector.actions.initLocation(intent); |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | private void setupLayout(Intent intent) { |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 138 | if (mState.action == ACTION_CREATE) { |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 139 | final String mimeType = intent.getType(); |
| 140 | final String title = intent.getStringExtra(Intent.EXTRA_TITLE); |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 141 | SaveFragment.show(getFragmentManager(), mimeType, title); |
Daichi Hirono | caadd41 | 2015-04-10 15:50:38 +0900 | [diff] [blame] | 142 | } else if (mState.action == ACTION_OPEN_TREE || |
Ben Kwa | ae96780 | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 143 | mState.action == ACTION_PICK_COPY_DESTINATION) { |
Jeff Sharkey | 6e565ff | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 144 | PickFragment.show(getFragmentManager()); |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | if (mState.action == ACTION_GET_CONTENT) { |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 148 | final Intent moreApps = new Intent(intent); |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 149 | moreApps.setComponent(null); |
| 150 | moreApps.setPackage(null); |
| 151 | RootsFragment.show(getFragmentManager(), moreApps); |
Daichi Hirono | caadd41 | 2015-04-10 15:50:38 +0900 | [diff] [blame] | 152 | } else if (mState.action == ACTION_OPEN || |
| 153 | mState.action == ACTION_CREATE || |
| 154 | mState.action == ACTION_OPEN_TREE || |
Ben Kwa | ae96780 | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 155 | mState.action == ACTION_PICK_COPY_DESTINATION) { |
Ben Lin | 821727a | 2016-07-08 10:49:53 -0700 | [diff] [blame] | 156 | RootsFragment.show(getFragmentManager(), (Intent) null); |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 157 | } |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Steve McKay | 0fbfc65 | 2015-08-20 16:48:49 -0700 | [diff] [blame] | 160 | @Override |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 161 | protected void includeState(State state) { |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 162 | final Intent intent = getIntent(); |
Garfield Tan | 78ade2b | 2017-02-28 13:19:53 -0800 | [diff] [blame] | 163 | |
| 164 | String defaultMimeType = (intent.getType() == null) ? "*/*" : intent.getType(); |
| 165 | state.initAcceptMimes(intent, defaultMimeType); |
| 166 | |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 167 | final String action = intent.getAction(); |
| 168 | if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) { |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 169 | state.action = ACTION_OPEN; |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 170 | } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) { |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 171 | state.action = ACTION_CREATE; |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 172 | } else if (Intent.ACTION_GET_CONTENT.equals(action)) { |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 173 | state.action = ACTION_GET_CONTENT; |
Jeff Sharkey | f4943e1 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 174 | } else if (Intent.ACTION_OPEN_DOCUMENT_TREE.equals(action)) { |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 175 | state.action = ACTION_OPEN_TREE; |
Ben Kwa | ae96780 | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 176 | } else if (Shared.ACTION_PICK_COPY_DESTINATION.equals(action)) { |
| 177 | state.action = ACTION_PICK_COPY_DESTINATION; |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 180 | if (state.action == ACTION_OPEN || state.action == ACTION_GET_CONTENT) { |
| 181 | state.allowMultiple = intent.getBooleanExtra( |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 182 | Intent.EXTRA_ALLOW_MULTIPLE, false); |
| 183 | } |
| 184 | |
Tomasz Mikolajewski | 95d9c25 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 185 | 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 Kwa | ae96780 | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 190 | if (state.action == ACTION_PICK_COPY_DESTINATION) { |
Steve McKay | f171934 | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 191 | // 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 McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 194 | state.directoryCopy = intent.getBooleanExtra( |
Ben Kwa | ae96780 | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 195 | Shared.EXTRA_DIRECTORY_COPY, false); |
Steve McKay | f171934 | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 196 | state.copyOperationSubType = intent.getIntExtra( |
Garfield, Tan | 4833477 | 2016-06-28 17:17:38 -0700 | [diff] [blame] | 197 | FileOperationService.EXTRA_OPERATION_TYPE, |
Steve McKay | c83baa0 | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 198 | FileOperationService.OPERATION_COPY); |
Daichi Hirono | f2a822d | 2015-04-14 17:12:54 +0900 | [diff] [blame] | 199 | } |
Jeff Sharkey | 8b99704 | 2013-09-19 15:25:56 -0700 | [diff] [blame] | 200 | } |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 201 | |
Steve McKay | c8889af | 2016-09-23 11:22:41 -0700 | [diff] [blame] | 202 | @Override |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 203 | 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 Sharkey | 38ec252 | 2013-09-24 12:07:12 -0700 | [diff] [blame] | 210 | |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 211 | @Override |
| 212 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Ben Kwa | 543a292 | 2016-03-22 11:11:46 -0700 | [diff] [blame] | 213 | if (DEBUG) Log.d(TAG, "onActivityResult() code=" + resultCode); |
Jeff Sharkey | 38ec252 | 2013-09-24 12:07:12 -0700 | [diff] [blame] | 214 | |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 215 | // 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 Sharkey | 8b99704 | 2013-09-19 15:25:56 -0700 | [diff] [blame] | 218 | |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 219 | // Remember that we last picked via external app |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 220 | mLastAccessed.setLastAccessedToExternalApp(this); |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 221 | |
| 222 | // Pass back result to original caller |
| 223 | setResult(resultCode, data); |
| 224 | finish(); |
| 225 | } else { |
| 226 | super.onActivityResult(requestCode, resultCode, data); |
Jeff Sharkey | f339f25 | 2013-08-15 16:17:41 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Jeff Sharkey | 46165b5 | 2013-07-31 20:53:22 -0700 | [diff] [blame] | 230 | @Override |
| 231 | protected void onPostCreate(Bundle savedInstanceState) { |
| 232 | super.onPostCreate(savedInstanceState); |
Steve McKay | 18d01e8 | 2016-02-03 11:15:57 -0800 | [diff] [blame] | 233 | mDrawer.update(); |
| 234 | mNavigator.update(); |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 237 | @Override |
Steve McKay | 18d01e8 | 2016-02-03 11:15:57 -0800 | [diff] [blame] | 238 | 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 Mikolajewski | 77fd402 | 2015-06-12 16:22:17 -0700 | [diff] [blame] | 248 | } else { |
Steve McKay | 17f7e58 | 2016-04-04 15:26:48 -0700 | [diff] [blame] | 249 | // If all else fails, just call it "Documents". |
| 250 | title = getResources().getString(R.string.app_label); |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 251 | } |
Jeff Sharkey | e6fcceb | 2014-07-28 16:38:52 -0700 | [diff] [blame] | 252 | } |
Jeff Sharkey | a5defe3 | 2013-08-05 17:56:48 -0700 | [diff] [blame] | 253 | |
Steve McKay | 18d01e8 | 2016-02-03 11:15:57 -0800 | [diff] [blame] | 254 | return title; |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | @Override |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 258 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 259 | super.onPrepareOptionsMenu(menu); |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 260 | mInjector.menuManager.updateOptionMenu(menu); |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 261 | |
Jeff Sharkey | 724deeb | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 262 | final DocumentInfo cwd = getCurrentDirectory(); |
Jeff Sharkey | 5b53592 | 2013-08-02 15:55:26 -0700 | [diff] [blame] | 263 | |
Steve McKay | e980927 | 2015-10-01 11:39:24 -0700 | [diff] [blame] | 264 | if (mState.action == ACTION_CREATE) { |
| 265 | final FragmentManager fm = getFragmentManager(); |
Steve McKay | 0fe9504 | 2015-10-14 17:41:13 -0700 | [diff] [blame] | 266 | SaveFragment.get(fm).prepareForDirectory(cwd); |
Jeff Sharkey | 5b53592 | 2013-08-02 15:55:26 -0700 | [diff] [blame] | 267 | } |
Jeff Sharkey | 46165b5 | 2013-07-31 20:53:22 -0700 | [diff] [blame] | 268 | |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 269 | return true; |
| 270 | } |
| 271 | |
| 272 | @Override |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 273 | protected void refreshDirectory(int anim) { |
Jeff Sharkey | 5b53592 | 2013-08-02 15:55:26 -0700 | [diff] [blame] | 274 | final FragmentManager fm = getFragmentManager(); |
Jeff Sharkey | a4d1f22 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 275 | final RootInfo root = getCurrentRoot(); |
Jeff Sharkey | 724deeb | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 276 | final DocumentInfo cwd = getCurrentDirectory(); |
Jeff Sharkey | c6cbdf1 | 2013-08-07 16:22:02 -0700 | [diff] [blame] | 277 | |
Garfield Tan | e967033 | 2017-03-06 18:33:23 -0800 | [diff] [blame] | 278 | if (mState.stack.isRecents()) { |
Garfield Tan | ae93758 | 2017-03-09 13:57:07 -0800 | [diff] [blame] | 279 | DirectoryFragment.showRecentsOpen(fm, anim); |
Jeff Sharkey | 7d58fc6 | 2013-09-12 16:25:02 -0700 | [diff] [blame] | 280 | |
Garfield Tan | ae93758 | 2017-03-09 13:57:07 -0800 | [diff] [blame] | 281 | // 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 Sharkey | 2e694f8 | 2013-08-06 16:26:14 -0700 | [diff] [blame] | 288 | } else { |
Jeff Sharkey | 2e694f8 | 2013-08-06 16:26:14 -0700 | [diff] [blame] | 289 | // Normal boring directory |
Aga Wronska | 8788dad | 2016-01-15 17:30:15 -0800 | [diff] [blame] | 290 | DirectoryFragment.showDirectory(fm, root, cwd, anim); |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 291 | } |
Jeff Sharkey | 2e694f8 | 2013-08-06 16:26:14 -0700 | [diff] [blame] | 292 | |
Jeff Sharkey | c6cbdf1 | 2013-08-07 16:22:02 -0700 | [diff] [blame] | 293 | // Forget any replacement target |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 294 | if (mState.action == ACTION_CREATE) { |
Jeff Sharkey | c6cbdf1 | 2013-08-07 16:22:02 -0700 | [diff] [blame] | 295 | final SaveFragment save = SaveFragment.get(fm); |
| 296 | if (save != null) { |
| 297 | save.setReplaceTarget(null); |
| 298 | } |
| 299 | } |
| 300 | |
Daichi Hirono | caadd41 | 2015-04-10 15:50:38 +0900 | [diff] [blame] | 301 | if (mState.action == ACTION_OPEN_TREE || |
Ben Kwa | ae96780 | 2015-09-25 14:48:29 -0700 | [diff] [blame] | 302 | mState.action == ACTION_PICK_COPY_DESTINATION) { |
Jeff Sharkey | 6e565ff | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 303 | final PickFragment pick = PickFragment.get(fm); |
| 304 | if (pick != null) { |
Steve McKay | f171934 | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 305 | pick.setPickTarget(mState.action, mState.copyOperationSubType, cwd); |
Jeff Sharkey | 6e565ff | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 306 | } |
| 307 | } |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 308 | } |
Jeff Sharkey | 6e565ff | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 309 | |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 310 | @Override |
| 311 | protected void onDirectoryCreated(DocumentInfo doc) { |
Steve McKay | 0af8afd | 2016-02-25 13:34:03 -0800 | [diff] [blame] | 312 | assert(doc.isDirectory()); |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 313 | mInjector.actions.openContainerDocument(doc); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Steve McKay | d0a2a2c | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 316 | @Override |
Steve McKay | eed2f4e | 2016-10-03 20:30:52 -0700 | [diff] [blame] | 317 | public void onDocumentPicked(DocumentInfo doc) { |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 318 | final FragmentManager fm = getFragmentManager(); |
Tomasz Mikolajewski | 52fe423 | 2016-11-25 14:23:39 +0900 | [diff] [blame] | 319 | // 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 McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 322 | mInjector.actions.openContainerDocument(doc); |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 323 | } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 324 | // Explicit file picked, return |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 325 | mInjector.actions.finishPicking(doc.derivedUri); |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 326 | } else if (mState.action == ACTION_CREATE) { |
Jeff Sharkey | c6cbdf1 | 2013-08-07 16:22:02 -0700 | [diff] [blame] | 327 | // Replace selected file |
| 328 | SaveFragment.get(fm).setReplaceTarget(doc); |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Steve McKay | d0a2a2c | 2015-03-25 14:35:33 -0700 | [diff] [blame] | 332 | @Override |
Jeff Sharkey | 724deeb | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 333 | public void onDocumentsPicked(List<DocumentInfo> docs) { |
Jeff Sharkey | b362044 | 2013-09-01 18:41:04 -0700 | [diff] [blame] | 334 | if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { |
Jeff Sharkey | 873daa3 | 2013-08-18 17:38:20 -0700 | [diff] [blame] | 335 | final int size = docs.size(); |
| 336 | final Uri[] uris = new Uri[size]; |
| 337 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | a4d1f22 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 338 | uris[i] = docs.get(i).derivedUri; |
Jeff Sharkey | 873daa3 | 2013-08-18 17:38:20 -0700 | [diff] [blame] | 339 | } |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 340 | mInjector.actions.finishPicking(uris); |
Jeff Sharkey | c317af8 | 2013-07-01 16:56:54 -0700 | [diff] [blame] | 341 | } |
Jeff Sharkey | 09c10bf | 2013-06-30 20:02:59 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 344 | @CallSuper |
| 345 | @Override |
| 346 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Ben Lin | 0902f07 | 2017-03-13 18:25:29 -0700 | [diff] [blame] | 347 | return mSharedInputHandler.onKeyDown( |
| 348 | keyCode, |
| 349 | event) |
Steve McKay | 0471826 | 2016-11-08 11:01:35 -0800 | [diff] [blame] | 350 | || super.onKeyDown(keyCode, event); |
| 351 | } |
Steve McKay | c7dc0cf | 2016-02-04 12:15:22 -0800 | [diff] [blame] | 352 | |
Garfield Tan | 894d487 | 2017-03-17 12:23:22 -0700 | [diff] [blame] | 353 | @Override |
| 354 | public void setResult(int resultCode, Intent intent, int notUsed) { |
| 355 | setResult(resultCode, intent); |
| 356 | } |
| 357 | |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 358 | public static PickActivity get(Fragment fragment) { |
| 359 | return (PickActivity) fragment.getActivity(); |
Steve McKay | b68dd22 | 2015-04-20 17:18:15 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 362 | @Override |
| 363 | public Injector<ActionHandler<PickActivity>> getInjector() { |
| 364 | return mInjector; |
| 365 | } |
Jeff Sharkey | e22d02e | 2013-04-26 16:54:55 -0700 | [diff] [blame] | 366 | } |