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