Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -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 | |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 19 | import android.app.Fragment; |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 20 | import android.view.Menu; |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 21 | import android.view.MenuInflater; |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 22 | import android.view.MenuItem; |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 23 | import android.view.View; |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 24 | |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 25 | import com.android.documentsui.base.DocumentInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 26 | import com.android.documentsui.base.Menus; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 27 | import com.android.documentsui.base.RootInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 28 | import com.android.documentsui.base.Shared; |
| 29 | import com.android.documentsui.base.State; |
Ben Lin | a867323 | 2016-09-28 15:40:04 -0700 | [diff] [blame] | 30 | import com.android.documentsui.dirlist.ActionModeController; |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 31 | import com.android.documentsui.dirlist.DirectoryFragment; |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 32 | import com.android.documentsui.sidebar.RootsFragment; |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 33 | import com.android.internal.annotations.VisibleForTesting; |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 34 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 35 | public abstract class MenuManager { |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 36 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 37 | final protected SearchViewManager mSearchManager; |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 38 | final protected State mState; |
| 39 | final protected DirectoryDetails mDirDetails; |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 40 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 41 | public MenuManager( |
| 42 | SearchViewManager searchManager, |
| 43 | State displayState, |
| 44 | DirectoryDetails dirDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 45 | mSearchManager = searchManager; |
| 46 | mState = displayState; |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 47 | mDirDetails = dirDetails; |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 50 | /** @see ActionModeController */ |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 51 | public void updateActionMenu(Menu menu, SelectionDetails selection) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 52 | updateOpenInActionMode(menu.findItem(R.id.menu_open), selection); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 53 | updateDelete(menu.findItem(R.id.menu_delete), selection); |
| 54 | updateShare(menu.findItem(R.id.menu_share), selection); |
| 55 | updateRename(menu.findItem(R.id.menu_rename), selection); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 56 | updateSelectAll(menu.findItem(R.id.menu_select_all)); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 57 | updateMoveTo(menu.findItem(R.id.menu_move_to), selection); |
| 58 | updateCopyTo(menu.findItem(R.id.menu_copy_to), selection); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 59 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 60 | Menus.disableHiddenItems(menu); |
| 61 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 62 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 63 | /** @see BaseActivity#onPrepareOptionsMenu */ |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 64 | public void updateOptionMenu(Menu menu) { |
| 65 | updateCreateDir(menu.findItem(R.id.menu_create_dir)); |
| 66 | updateSettings(menu.findItem(R.id.menu_settings)); |
| 67 | updateNewWindow(menu.findItem(R.id.menu_new_window)); |
| 68 | updateModePicker(menu.findItem(R.id.menu_grid), menu.findItem(R.id.menu_list)); |
Garfield, Tan | 11d2348 | 2016-08-05 09:33:29 -0700 | [diff] [blame] | 69 | // Sort menu item is managed by SortMenuManager |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 70 | updateAdvanced(menu.findItem(R.id.menu_advanced)); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 71 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 72 | Menus.disableHiddenItems(menu); |
| 73 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 74 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 75 | /** |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 76 | * Called when we needs {@link MenuManager} to ask Android to show context menu for us. |
| 77 | * {@link MenuManager} can choose to defeat this request. |
| 78 | * |
| 79 | * {@link #inflateContextMenuForDocs} and {@link #inflateContextMenuForContainer} are called |
| 80 | * afterwards when Android asks us to provide the content of context menus, so they're not |
| 81 | * correct locations to suppress context menus. |
| 82 | */ |
| 83 | public void showContextMenu(Fragment f, View v, float x, float y) { |
| 84 | // Pickers don't have any context menu at this moment. |
| 85 | } |
| 86 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 87 | public void inflateContextMenuForContainer(Menu menu, MenuInflater inflater) { |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 88 | throw new UnsupportedOperationException("Pickers don't allow context menu."); |
| 89 | } |
| 90 | |
| 91 | public void inflateContextMenuForDocs( |
| 92 | Menu menu, MenuInflater inflater, SelectionDetails selectionDetails) { |
| 93 | throw new UnsupportedOperationException("Pickers don't allow context menu."); |
| 94 | } |
| 95 | |
| 96 | /** |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 97 | * @see DirectoryFragment#onCreateContextMenu |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 98 | * |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 99 | * Called when user tries to generate a context menu anchored to a file when the selection |
| 100 | * doesn't contain any folder. |
| 101 | * |
| 102 | * @param selectionDetails |
| 103 | * containsFiles may return false because this may be called when user right clicks on an |
| 104 | * unselectable item in pickers |
| 105 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 106 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 107 | public void updateContextMenuForFiles(Menu menu, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 108 | assert(selectionDetails != null); |
| 109 | |
| 110 | MenuItem share = menu.findItem(R.id.menu_share); |
| 111 | MenuItem open = menu.findItem(R.id.menu_open); |
| 112 | MenuItem openWith = menu.findItem(R.id.menu_open_with); |
| 113 | MenuItem rename = menu.findItem(R.id.menu_rename); |
| 114 | |
| 115 | updateShare(share, selectionDetails); |
| 116 | updateOpenInContextMenu(open, selectionDetails); |
| 117 | updateOpenWith(openWith, selectionDetails); |
| 118 | updateRename(rename, selectionDetails); |
| 119 | |
| 120 | updateContextMenu(menu, selectionDetails); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @see DirectoryFragment#onCreateContextMenu |
| 125 | * |
| 126 | * Called when user tries to generate a context menu anchored to a folder when the selection |
| 127 | * doesn't contain any file. |
| 128 | * |
| 129 | * @param selectionDetails |
| 130 | * containDirectories may return false because this may be called when user right clicks on |
| 131 | * an unselectable item in pickers |
| 132 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 133 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 134 | public void updateContextMenuForDirs(Menu menu, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 135 | assert(selectionDetails != null); |
| 136 | |
| 137 | MenuItem openInNewWindow = menu.findItem(R.id.menu_open_in_new_window); |
| 138 | MenuItem rename = menu.findItem(R.id.menu_rename); |
| 139 | MenuItem pasteInto = menu.findItem(R.id.menu_paste_into_folder); |
| 140 | |
| 141 | updateOpenInNewWindow(openInNewWindow, selectionDetails); |
| 142 | updateRename(rename, selectionDetails); |
| 143 | updatePasteInto(pasteInto, selectionDetails); |
| 144 | |
| 145 | updateContextMenu(menu, selectionDetails); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @see DirectoryFragment#onCreateContextMenu |
| 150 | * |
| 151 | * Update shared context menu items of both files and folders context menus. |
| 152 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 153 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 154 | public void updateContextMenu(Menu menu, SelectionDetails selectionDetails) { |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 155 | assert(selectionDetails != null); |
| 156 | |
| 157 | MenuItem cut = menu.findItem(R.id.menu_cut_to_clipboard); |
| 158 | MenuItem copy = menu.findItem(R.id.menu_copy_to_clipboard); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 159 | MenuItem delete = menu.findItem(R.id.menu_delete); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 160 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 161 | final boolean canCopy = |
| 162 | selectionDetails.size() > 0 && !selectionDetails.containsPartialFiles(); |
| 163 | final boolean canDelete = selectionDetails.canDelete(); |
| 164 | cut.setEnabled(canCopy && canDelete); |
| 165 | copy.setEnabled(canCopy); |
| 166 | delete.setEnabled(canDelete); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 169 | /** |
| 170 | * @see DirectoryFragment#onCreateContextMenu |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 171 | * |
| 172 | * Called when user tries to generate a context menu anchored to an empty pane. |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 173 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 174 | @VisibleForTesting |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 175 | public void updateContextMenuForContainer(Menu menu) { |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 176 | MenuItem paste = menu.findItem(R.id.menu_paste_from_clipboard); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 177 | MenuItem selectAll = menu.findItem(R.id.menu_select_all); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 178 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 179 | paste.setEnabled(mDirDetails.hasItemsToPaste() && mDirDetails.canCreateDoc()); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 180 | updateSelectAll(selectAll); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 181 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 182 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 183 | /** |
| 184 | * @see RootsFragment#onCreateContextMenu |
| 185 | */ |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 186 | public void updateRootContextMenu(Menu menu, RootInfo root, DocumentInfo docInfo) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 187 | MenuItem eject = menu.findItem(R.id.menu_eject_root); |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 188 | MenuItem pasteInto = menu.findItem(R.id.menu_paste_into_folder); |
| 189 | MenuItem openInNewWindow = menu.findItem(R.id.menu_open_in_new_window); |
| 190 | MenuItem settings = menu.findItem(R.id.menu_settings); |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 191 | |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 192 | updateEject(eject, root); |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 193 | updatePasteInto(pasteInto, root, docInfo); |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 194 | updateOpenInNewWindow(openInNewWindow, root); |
| 195 | updateSettings(settings, root); |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 198 | protected void updateModePicker(MenuItem grid, MenuItem list) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 199 | grid.setVisible(mState.derivedMode != State.MODE_GRID); |
| 200 | list.setVisible(mState.derivedMode != State.MODE_LIST); |
| 201 | } |
| 202 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 203 | protected void updateAdvanced(MenuItem advanced) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 204 | advanced.setVisible(mState.showAdvancedOption); |
| 205 | advanced.setTitle(mState.showAdvancedOption && mState.showAdvanced |
| 206 | ? R.string.menu_advanced_hide : R.string.menu_advanced_show); |
| 207 | } |
| 208 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 209 | protected void updateSettings(MenuItem settings) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 210 | settings.setVisible(false); |
| 211 | } |
| 212 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 213 | protected void updateSettings(MenuItem settings, RootInfo root) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 214 | settings.setVisible(false); |
| 215 | } |
| 216 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 217 | protected void updateEject(MenuItem eject, RootInfo root) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 218 | eject.setVisible(false); |
| 219 | } |
| 220 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 221 | protected void updateNewWindow(MenuItem newWindow) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 222 | newWindow.setVisible(false); |
| 223 | } |
| 224 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 225 | protected void updateOpenInActionMode(MenuItem open, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 226 | open.setVisible(false); |
| 227 | } |
| 228 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 229 | protected void updateOpenWith(MenuItem openWith, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 230 | openWith.setVisible(false); |
| 231 | } |
| 232 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 233 | protected void updateOpenInNewWindow( |
| 234 | MenuItem openInNewWindow, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 235 | openInNewWindow.setVisible(false); |
| 236 | } |
| 237 | |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 238 | protected void updateOpenInNewWindow( |
| 239 | MenuItem openInNewWindow, RootInfo root) { |
| 240 | openInNewWindow.setVisible(false); |
| 241 | } |
| 242 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 243 | protected void updateShare(MenuItem share, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 244 | share.setVisible(false); |
| 245 | } |
| 246 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 247 | protected void updateDelete(MenuItem delete, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 248 | delete.setVisible(false); |
| 249 | } |
| 250 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 251 | protected void updateRename(MenuItem rename, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 252 | rename.setVisible(false); |
| 253 | } |
| 254 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 255 | protected void updateMoveTo(MenuItem moveTo, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 256 | moveTo.setVisible(false); |
| 257 | } |
| 258 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 259 | protected void updateCopyTo(MenuItem copyTo, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 260 | copyTo.setVisible(false); |
| 261 | } |
| 262 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 263 | protected void updatePasteInto(MenuItem pasteInto, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 264 | pasteInto.setVisible(false); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 267 | protected void updatePasteInto(MenuItem pasteInto, RootInfo root, DocumentInfo docInfo) { |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 268 | pasteInto.setVisible(false); |
| 269 | } |
| 270 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 271 | protected abstract void updateOpenInContextMenu( |
| 272 | MenuItem open, SelectionDetails selectionDetails); |
| 273 | protected abstract void updateSelectAll(MenuItem selectAll); |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 274 | protected abstract void updateCreateDir(MenuItem createDir); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 275 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 276 | /** |
| 277 | * Access to meta data about the selection. |
| 278 | */ |
| 279 | public interface SelectionDetails { |
| 280 | boolean containsDirectories(); |
| 281 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 282 | boolean containsFiles(); |
| 283 | |
| 284 | int size(); |
| 285 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 286 | boolean containsPartialFiles(); |
| 287 | |
| 288 | // TODO: Update these to express characteristics instead of answering concrete questions, |
| 289 | // since the answer to those questions is (or can be) activity specific. |
| 290 | boolean canDelete(); |
| 291 | |
| 292 | boolean canRename(); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 293 | |
| 294 | boolean canPasteInto(); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | public static class DirectoryDetails { |
| 298 | private final BaseActivity mActivity; |
| 299 | |
| 300 | public DirectoryDetails(BaseActivity activity) { |
| 301 | mActivity = activity; |
| 302 | } |
| 303 | |
| 304 | public boolean shouldShowFancyFeatures() { |
| 305 | return Shared.shouldShowFancyFeatures(mActivity); |
| 306 | } |
| 307 | |
| 308 | public boolean hasRootSettings() { |
| 309 | return mActivity.getCurrentRoot().hasSettings(); |
| 310 | } |
| 311 | |
| 312 | public boolean hasItemsToPaste() { |
| 313 | return false; |
| 314 | } |
| 315 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 316 | public boolean canCreateDoc() { |
| 317 | return isInRecents() ? false : mActivity.getCurrentDirectory().isCreateSupported(); |
| 318 | } |
| 319 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 320 | public boolean isInRecents() { |
| 321 | return mActivity.getCurrentDirectory() == null; |
| 322 | } |
| 323 | |
| 324 | public boolean canCreateDirectory() { |
| 325 | return mActivity.canCreateDirectory(); |
| 326 | } |
| 327 | } |
| 328 | } |