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 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 19 | import android.view.KeyboardShortcutGroup; |
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 | |
Tony Huang | fdbab1a | 2019-04-08 18:10:27 +0800 | [diff] [blame] | 25 | import androidx.annotation.VisibleForTesting; |
| 26 | import androidx.fragment.app.Fragment; |
| 27 | |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 28 | import com.android.documentsui.base.DocumentInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 29 | import com.android.documentsui.base.Menus; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 30 | import com.android.documentsui.base.RootInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 31 | import com.android.documentsui.base.State; |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 32 | import com.android.documentsui.dirlist.DirectoryFragment; |
Steve McKay | 3a26823 | 2016-10-19 11:15:47 -0700 | [diff] [blame] | 33 | import com.android.documentsui.queries.SearchViewManager; |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 34 | import com.android.documentsui.sidebar.RootsFragment; |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 35 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 36 | import java.util.List; |
| 37 | import java.util.function.IntFunction; |
| 38 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 39 | public abstract class MenuManager { |
shawnlin | dbfc9c2 | 2018-09-25 14:26:52 +0800 | [diff] [blame] | 40 | private final static String TAG = "MenuManager"; |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 41 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 42 | final protected SearchViewManager mSearchManager; |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 43 | final protected State mState; |
| 44 | final protected DirectoryDetails mDirDetails; |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 45 | |
shawnlin | dbfc9c2 | 2018-09-25 14:26:52 +0800 | [diff] [blame] | 46 | protected Menu mOptionMenu; |
| 47 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 48 | public MenuManager( |
| 49 | SearchViewManager searchManager, |
| 50 | State displayState, |
| 51 | DirectoryDetails dirDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 52 | mSearchManager = searchManager; |
| 53 | mState = displayState; |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 54 | mDirDetails = dirDetails; |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 57 | /** @see ActionModeController */ |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 58 | public void updateActionMenu(Menu menu, SelectionDetails selection) { |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 59 | updateOpenWith(menu.findItem(R.id.action_menu_open_with), selection); |
| 60 | updateDelete(menu.findItem(R.id.action_menu_delete), selection); |
| 61 | updateShare(menu.findItem(R.id.action_menu_share), selection); |
| 62 | updateRename(menu.findItem(R.id.action_menu_rename), selection); |
Bill Lin | fd235cf | 2018-05-23 18:48:31 +0800 | [diff] [blame] | 63 | updateSelect(menu.findItem(R.id.action_menu_select), selection); |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 64 | updateSelectAll(menu.findItem(R.id.action_menu_select_all)); |
| 65 | updateMoveTo(menu.findItem(R.id.action_menu_move_to), selection); |
| 66 | updateCopyTo(menu.findItem(R.id.action_menu_copy_to), selection); |
| 67 | updateCompress(menu.findItem(R.id.action_menu_compress), selection); |
| 68 | updateExtractTo(menu.findItem(R.id.action_menu_extract_to), selection); |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 69 | updateInspect(menu.findItem(R.id.action_menu_inspect), selection); |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 70 | updateViewInOwner(menu.findItem(R.id.action_menu_view_in_owner), selection); |
Tony Huang | 243cf9c | 2018-10-16 16:15:18 +0800 | [diff] [blame] | 71 | updateSort(menu.findItem(R.id.action_menu_sort)); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 72 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 73 | Menus.disableHiddenItems(menu); |
| 74 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 75 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 76 | /** @see BaseActivity#onPrepareOptionsMenu */ |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 77 | public void updateOptionMenu(Menu menu) { |
shawnlin | dbfc9c2 | 2018-09-25 14:26:52 +0800 | [diff] [blame] | 78 | mOptionMenu = menu; |
| 79 | updateOptionMenu(); |
| 80 | } |
| 81 | |
| 82 | public void updateOptionMenu() { |
| 83 | if (mOptionMenu == null) { |
| 84 | return; |
| 85 | } |
| 86 | updateCreateDir(mOptionMenu.findItem(R.id.option_menu_create_dir)); |
| 87 | updateSettings(mOptionMenu.findItem(R.id.option_menu_settings)); |
| 88 | updateSelectAll(mOptionMenu.findItem(R.id.option_menu_select_all)); |
| 89 | updateNewWindow(mOptionMenu.findItem(R.id.option_menu_new_window)); |
shawnlin | dbfc9c2 | 2018-09-25 14:26:52 +0800 | [diff] [blame] | 90 | updateAdvanced(mOptionMenu.findItem(R.id.option_menu_advanced)); |
| 91 | updateDebug(mOptionMenu.findItem(R.id.option_menu_debug)); |
| 92 | updateInspect(mOptionMenu.findItem(R.id.option_menu_inspect)); |
Tony Huang | 243cf9c | 2018-10-16 16:15:18 +0800 | [diff] [blame] | 93 | updateSort(mOptionMenu.findItem(R.id.option_menu_sort)); |
| 94 | |
shawnlin | dbfc9c2 | 2018-09-25 14:26:52 +0800 | [diff] [blame] | 95 | Menus.disableHiddenItems(mOptionMenu); |
shawnlin | 142e27b | 2018-10-03 16:40:24 +0800 | [diff] [blame] | 96 | mSearchManager.updateMenu(); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 97 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 98 | |
Tony Huang | adce72b | 2019-01-31 15:21:55 +0800 | [diff] [blame] | 99 | public void updateSubMenu(Menu menu) { |
| 100 | updateModePicker(menu.findItem(R.id.sub_menu_grid), menu.findItem(R.id.sub_menu_list)); |
| 101 | } |
| 102 | |
Tony Huang | 166cd7c | 2019-03-11 16:31:57 +0800 | [diff] [blame] | 103 | public void updateModel(Model model) {} |
| 104 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 105 | /** |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 106 | * Called when we needs {@link MenuManager} to ask Android to show context menu for us. |
| 107 | * {@link MenuManager} can choose to defeat this request. |
| 108 | * |
| 109 | * {@link #inflateContextMenuForDocs} and {@link #inflateContextMenuForContainer} are called |
| 110 | * afterwards when Android asks us to provide the content of context menus, so they're not |
| 111 | * correct locations to suppress context menus. |
| 112 | */ |
| 113 | public void showContextMenu(Fragment f, View v, float x, float y) { |
| 114 | // Pickers don't have any context menu at this moment. |
| 115 | } |
| 116 | |
Steve McKay | c6d6324 | 2017-08-14 11:29:42 -0700 | [diff] [blame] | 117 | public void inflateContextMenuForContainer(Menu menu, MenuInflater inflater) { |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 118 | throw new UnsupportedOperationException("Pickers don't allow context menu."); |
| 119 | } |
| 120 | |
| 121 | public void inflateContextMenuForDocs( |
| 122 | Menu menu, MenuInflater inflater, SelectionDetails selectionDetails) { |
| 123 | throw new UnsupportedOperationException("Pickers don't allow context menu."); |
| 124 | } |
| 125 | |
| 126 | /** |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 127 | * @see DirectoryFragment#onCreateContextMenu |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 128 | * |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 129 | * Called when user tries to generate a context menu anchored to a file when the selection |
| 130 | * doesn't contain any folder. |
| 131 | * |
| 132 | * @param selectionDetails |
| 133 | * containsFiles may return false because this may be called when user right clicks on an |
| 134 | * unselectable item in pickers |
| 135 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 136 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 137 | public void updateContextMenuForFiles(Menu menu, SelectionDetails selectionDetails) { |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 138 | assert selectionDetails != null; |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 139 | |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 140 | MenuItem share = menu.findItem(R.id.dir_menu_share); |
| 141 | MenuItem open = menu.findItem(R.id.dir_menu_open); |
| 142 | MenuItem openWith = menu.findItem(R.id.dir_menu_open_with); |
| 143 | MenuItem rename = menu.findItem(R.id.dir_menu_rename); |
| 144 | MenuItem viewInOwner = menu.findItem(R.id.dir_menu_view_in_owner); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 145 | |
| 146 | updateShare(share, selectionDetails); |
| 147 | updateOpenInContextMenu(open, selectionDetails); |
| 148 | updateOpenWith(openWith, selectionDetails); |
| 149 | updateRename(rename, selectionDetails); |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 150 | updateViewInOwner(viewInOwner, selectionDetails); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 151 | |
| 152 | updateContextMenu(menu, selectionDetails); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @see DirectoryFragment#onCreateContextMenu |
| 157 | * |
| 158 | * Called when user tries to generate a context menu anchored to a folder when the selection |
| 159 | * doesn't contain any file. |
| 160 | * |
| 161 | * @param selectionDetails |
| 162 | * containDirectories may return false because this may be called when user right clicks on |
| 163 | * an unselectable item in pickers |
| 164 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 165 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 166 | public void updateContextMenuForDirs(Menu menu, SelectionDetails selectionDetails) { |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 167 | assert selectionDetails != null; |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 168 | |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 169 | MenuItem openInNewWindow = menu.findItem(R.id.dir_menu_open_in_new_window); |
| 170 | MenuItem rename = menu.findItem(R.id.dir_menu_rename); |
| 171 | MenuItem pasteInto = menu.findItem(R.id.dir_menu_paste_into_folder); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 172 | |
| 173 | updateOpenInNewWindow(openInNewWindow, selectionDetails); |
| 174 | updateRename(rename, selectionDetails); |
| 175 | updatePasteInto(pasteInto, selectionDetails); |
| 176 | |
| 177 | updateContextMenu(menu, selectionDetails); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * @see DirectoryFragment#onCreateContextMenu |
| 182 | * |
| 183 | * Update shared context menu items of both files and folders context menus. |
| 184 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 185 | @VisibleForTesting |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 186 | public void updateContextMenu(Menu menu, SelectionDetails selectionDetails) { |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 187 | assert selectionDetails != null; |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 188 | |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 189 | MenuItem cut = menu.findItem(R.id.dir_menu_cut_to_clipboard); |
| 190 | MenuItem copy = menu.findItem(R.id.dir_menu_copy_to_clipboard); |
| 191 | MenuItem delete = menu.findItem(R.id.dir_menu_delete); |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 192 | MenuItem inspect = menu.findItem(R.id.dir_menu_inspect); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 193 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 194 | final boolean canCopy = |
| 195 | selectionDetails.size() > 0 && !selectionDetails.containsPartialFiles(); |
| 196 | final boolean canDelete = selectionDetails.canDelete(); |
| 197 | cut.setEnabled(canCopy && canDelete); |
| 198 | copy.setEnabled(canCopy); |
| 199 | delete.setEnabled(canDelete); |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 200 | |
| 201 | inspect.setEnabled(selectionDetails.size() == 1); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 204 | /** |
| 205 | * @see DirectoryFragment#onCreateContextMenu |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 206 | * |
| 207 | * 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] | 208 | */ |
Garfield Tan | 239ab97 | 2016-09-16 13:33:48 -0700 | [diff] [blame] | 209 | @VisibleForTesting |
Steve McKay | c6d6324 | 2017-08-14 11:29:42 -0700 | [diff] [blame] | 210 | public void updateContextMenuForContainer(Menu menu) { |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 211 | MenuItem paste = menu.findItem(R.id.dir_menu_paste_from_clipboard); |
| 212 | MenuItem selectAll = menu.findItem(R.id.dir_menu_select_all); |
| 213 | MenuItem createDir = menu.findItem(R.id.dir_menu_create_dir); |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 214 | MenuItem inspect = menu.findItem(R.id.dir_menu_inspect); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 215 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 216 | paste.setEnabled(mDirDetails.hasItemsToPaste() && mDirDetails.canCreateDoc()); |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 217 | updateSelectAll(selectAll); |
Garfield Tan | d330727 | 2016-10-10 13:33:25 -0700 | [diff] [blame] | 218 | updateCreateDir(createDir); |
Steve McKay | c6d6324 | 2017-08-14 11:29:42 -0700 | [diff] [blame] | 219 | updateInspect(inspect); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 220 | } |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 221 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 222 | /** |
| 223 | * @see RootsFragment#onCreateContextMenu |
| 224 | */ |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 225 | public void updateRootContextMenu(Menu menu, RootInfo root, DocumentInfo docInfo) { |
Ben Lin | ff7f3ae | 2017-04-25 16:08:52 -0700 | [diff] [blame] | 226 | MenuItem eject = menu.findItem(R.id.root_menu_eject_root); |
| 227 | MenuItem pasteInto = menu.findItem(R.id.root_menu_paste_into_folder); |
| 228 | MenuItem openInNewWindow = menu.findItem(R.id.root_menu_open_in_new_window); |
| 229 | MenuItem settings = menu.findItem(R.id.root_menu_settings); |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 230 | |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 231 | updateEject(eject, root); |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 232 | updatePasteInto(pasteInto, root, docInfo); |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 233 | updateOpenInNewWindow(openInNewWindow, root); |
| 234 | updateSettings(settings, root); |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 237 | public abstract void updateKeyboardShortcutsMenu( |
| 238 | List<KeyboardShortcutGroup> data, IntFunction<String> stringSupplier); |
| 239 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 240 | protected void updateModePicker(MenuItem grid, MenuItem list) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 241 | grid.setVisible(mState.derivedMode != State.MODE_GRID); |
| 242 | list.setVisible(mState.derivedMode != State.MODE_LIST); |
| 243 | } |
| 244 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 245 | protected void updateAdvanced(MenuItem advanced) { |
Steve McKay | 01996bc | 2016-10-21 13:38:49 -0700 | [diff] [blame] | 246 | advanced.setVisible(mState.showDeviceStorageOption); |
| 247 | advanced.setTitle(mState.showDeviceStorageOption && mState.showAdvanced |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 248 | ? R.string.menu_advanced_hide : R.string.menu_advanced_show); |
| 249 | } |
| 250 | |
Tony Huang | 243cf9c | 2018-10-16 16:15:18 +0800 | [diff] [blame] | 251 | protected void updateSort(MenuItem sort) { |
| 252 | sort.setVisible(true); |
| 253 | } |
| 254 | |
Jon Mann | eb1d11b | 2017-04-01 15:36:59 -0700 | [diff] [blame] | 255 | protected void updateDebug(MenuItem debug) { |
| 256 | debug.setVisible(mState.debugMode); |
| 257 | } |
| 258 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 259 | protected void updateSettings(MenuItem settings) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 260 | settings.setVisible(false); |
| 261 | } |
| 262 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 263 | protected void updateSettings(MenuItem settings, RootInfo root) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 264 | settings.setVisible(false); |
| 265 | } |
| 266 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 267 | protected void updateEject(MenuItem eject, RootInfo root) { |
Ben Lin | 5668b86 | 2016-06-28 17:12:52 -0700 | [diff] [blame] | 268 | eject.setVisible(false); |
| 269 | } |
| 270 | |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 271 | protected void updateNewWindow(MenuItem newWindow) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 272 | newWindow.setVisible(false); |
| 273 | } |
| 274 | |
Bill Lin | fd235cf | 2018-05-23 18:48:31 +0800 | [diff] [blame] | 275 | protected void updateSelect(MenuItem select, SelectionDetails selectionDetails) { |
| 276 | select.setVisible(false); |
| 277 | } |
| 278 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 279 | protected void updateOpenWith(MenuItem openWith, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 280 | openWith.setVisible(false); |
| 281 | } |
| 282 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 283 | protected void updateOpenInNewWindow( |
| 284 | MenuItem openInNewWindow, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 285 | openInNewWindow.setVisible(false); |
| 286 | } |
| 287 | |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 288 | protected void updateOpenInNewWindow( |
| 289 | MenuItem openInNewWindow, RootInfo root) { |
| 290 | openInNewWindow.setVisible(false); |
| 291 | } |
| 292 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 293 | protected void updateShare(MenuItem share, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 294 | share.setVisible(false); |
| 295 | } |
| 296 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 297 | protected void updateDelete(MenuItem delete, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 298 | delete.setVisible(false); |
| 299 | } |
| 300 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 301 | protected void updateRename(MenuItem rename, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 302 | rename.setVisible(false); |
| 303 | } |
| 304 | |
Steve McKay | efd10ac | 2017-07-25 13:33:57 -0700 | [diff] [blame] | 305 | /** |
| 306 | * This method is called for standard activity option menu as opposed |
| 307 | * to when there is a selection. |
| 308 | */ |
Steve McKay | c6d6324 | 2017-08-14 11:29:42 -0700 | [diff] [blame] | 309 | protected void updateInspect(MenuItem inspector) { |
Steve McKay | efd10ac | 2017-07-25 13:33:57 -0700 | [diff] [blame] | 310 | inspector.setVisible(false); |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * This method is called for action mode, when a selection exists. |
| 315 | */ |
Steve McKay | 0c7ad03 | 2017-08-09 11:50:10 -0700 | [diff] [blame] | 316 | protected void updateInspect(MenuItem inspect, SelectionDetails selectionDetails) { |
| 317 | inspect.setVisible(false); |
Dooper | 3975fa2 | 2017-06-02 10:32:00 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 320 | protected void updateViewInOwner(MenuItem view, SelectionDetails selectionDetails) { |
| 321 | view.setVisible(false); |
| 322 | } |
| 323 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 324 | protected void updateMoveTo(MenuItem moveTo, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 325 | moveTo.setVisible(false); |
| 326 | } |
| 327 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 328 | protected void updateCopyTo(MenuItem copyTo, SelectionDetails selectionDetails) { |
Ben Lin | 2567991 | 2016-06-17 11:48:57 -0700 | [diff] [blame] | 329 | copyTo.setVisible(false); |
| 330 | } |
| 331 | |
Tomasz Mikolajewski | 26640ab | 2017-02-06 10:37:59 +0900 | [diff] [blame] | 332 | protected void updateCompress(MenuItem compress, SelectionDetails selectionDetails) { |
| 333 | compress.setVisible(false); |
| 334 | } |
| 335 | |
Tomasz Mikolajewski | 5a8e378 | 2017-01-24 12:40:55 +0900 | [diff] [blame] | 336 | protected void updateExtractTo(MenuItem extractTo, SelectionDetails selectionDetails) { |
| 337 | extractTo.setVisible(false); |
| 338 | } |
| 339 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 340 | protected void updatePasteInto(MenuItem pasteInto, SelectionDetails selectionDetails) { |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 341 | pasteInto.setVisible(false); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Ben Lin | 8e91258 | 2016-09-23 14:25:14 -0700 | [diff] [blame] | 344 | protected void updatePasteInto(MenuItem pasteInto, RootInfo root, DocumentInfo docInfo) { |
Garfield Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 345 | pasteInto.setVisible(false); |
| 346 | } |
| 347 | |
wilsonshih | 08d4d05 | 2018-05-16 14:36:56 +0800 | [diff] [blame] | 348 | protected void updateOpenInContextMenu(MenuItem open, SelectionDetails selectionDetails) { |
| 349 | open.setVisible(false); |
| 350 | } |
| 351 | |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 352 | protected abstract void updateSelectAll(MenuItem selectAll); |
Steve McKay | e5d6ca2 | 2016-09-19 20:27:24 -0700 | [diff] [blame] | 353 | protected abstract void updateCreateDir(MenuItem createDir); |
Ben Lin | 7c35b03 | 2016-05-31 13:24:01 -0700 | [diff] [blame] | 354 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 355 | /** |
| 356 | * Access to meta data about the selection. |
| 357 | */ |
| 358 | public interface SelectionDetails { |
| 359 | boolean containsDirectories(); |
| 360 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 361 | boolean containsFiles(); |
| 362 | |
| 363 | int size(); |
| 364 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 365 | boolean containsPartialFiles(); |
| 366 | |
Ben Lin | 7f7ee10 | 2017-05-26 14:22:58 -0700 | [diff] [blame] | 367 | boolean containsFilesInArchive(); |
| 368 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 369 | // TODO: Update these to express characteristics instead of answering concrete questions, |
| 370 | // since the answer to those questions is (or can be) activity specific. |
| 371 | boolean canDelete(); |
| 372 | |
| 373 | boolean canRename(); |
Ben Lin | b2dfa12 | 2016-08-11 17:42:57 -0700 | [diff] [blame] | 374 | |
| 375 | boolean canPasteInto(); |
Tomasz Mikolajewski | 5a8e378 | 2017-01-24 12:40:55 +0900 | [diff] [blame] | 376 | |
| 377 | boolean canExtract(); |
Tomasz Mikolajewski | ac3e63e | 2017-02-13 10:08:58 +0900 | [diff] [blame] | 378 | |
| 379 | boolean canOpenWith(); |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 380 | |
| 381 | boolean canViewInOwner(); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | public static class DirectoryDetails { |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 385 | private final BaseActivity mActivity; |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 386 | |
Steve McKay | 92ae43d | 2016-11-08 12:06:58 -0800 | [diff] [blame] | 387 | public DirectoryDetails(BaseActivity activity) { |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 388 | mActivity = activity; |
| 389 | } |
| 390 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 391 | public boolean hasRootSettings() { |
| 392 | return mActivity.getCurrentRoot().hasSettings(); |
| 393 | } |
| 394 | |
| 395 | public boolean hasItemsToPaste() { |
| 396 | return false; |
| 397 | } |
| 398 | |
Garfield Tan | 06c4b11 | 2016-09-14 11:05:58 -0700 | [diff] [blame] | 399 | public boolean canCreateDoc() { |
| 400 | return isInRecents() ? false : mActivity.getCurrentDirectory().isCreateSupported(); |
| 401 | } |
| 402 | |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 403 | public boolean isInRecents() { |
Tony Huang | fdbab1a | 2019-04-08 18:10:27 +0800 | [diff] [blame] | 404 | return mActivity.isInRecents(); |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | public boolean canCreateDirectory() { |
| 408 | return mActivity.canCreateDirectory(); |
| 409 | } |
Takamasa Kuramitsu | 5971052 | 2018-06-29 18:42:21 +0900 | [diff] [blame] | 410 | |
| 411 | public boolean canInspectDirectory() { |
Tony Huang | fdbab1a | 2019-04-08 18:10:27 +0800 | [diff] [blame] | 412 | return mActivity.canInspectDirectory() && !isInRecents(); |
Takamasa Kuramitsu | 5971052 | 2018-06-29 18:42:21 +0900 | [diff] [blame] | 413 | } |
Ben Lin | ebf2a17 | 2016-06-03 13:46:52 -0700 | [diff] [blame] | 414 | } |
| 415 | } |