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