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