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 17package com.android.documentsui.picker; 18 19import static com.android.documentsui.base.State.ACTION_CREATE; 20import static com.android.documentsui.base.State.ACTION_GET_CONTENT; 21import static com.android.documentsui.base.State.ACTION_OPEN; 22import static com.android.documentsui.base.State.ACTION_OPEN_TREE; 23import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION; 24 25import android.view.KeyboardShortcutGroup; 26import android.view.Menu; 27import android.view.MenuItem; 28 29import com.android.documentsui.base.State; 30import com.android.documentsui.queries.SearchViewManager; 31 32import java.util.List; 33import java.util.function.IntFunction; 34 35public final class MenuManager extends com.android.documentsui.MenuManager { 36 37 public MenuManager(SearchViewManager searchManager, State displayState, DirectoryDetails dirDetails) { 38 super(searchManager, displayState, dirDetails); 39 40 } 41 42 @Override 43 public void updateKeyboardShortcutsMenu( 44 List<KeyboardShortcutGroup> data, IntFunction<String> stringSupplier) { 45 // None as of yet. 46 } 47 48 private boolean picking() { 49 return mState.action == ACTION_CREATE 50 || mState.action == ACTION_OPEN_TREE 51 || mState.action == ACTION_PICK_COPY_DESTINATION; 52 } 53 54 @Override 55 public void updateOptionMenu(Menu menu) { 56 super.updateOptionMenu(menu); 57 if (picking()) { 58 // May already be hidden because the root 59 // doesn't support search. 60 mSearchManager.showMenu(null); 61 } 62 } 63 64 @Override 65 protected void updateModePicker(MenuItem grid, MenuItem list) { 66 // No display options in recent directories 67 if (picking() && mDirDetails.isInRecents()) { 68 grid.setVisible(false); 69 list.setVisible(false); 70 } else { 71 super.updateModePicker(grid, list); 72 } 73 } 74 75 @Override 76 protected void updateSelectAll(MenuItem selectAll) { 77 boolean enabled = mState.allowMultiple; 78 selectAll.setVisible(enabled); 79 selectAll.setEnabled(enabled); 80 } 81 82 @Override 83 protected void updateCreateDir(MenuItem createDir) { 84 createDir.setVisible(picking()); 85 createDir.setEnabled(picking() && mDirDetails.canCreateDirectory()); 86 } 87 88 @Override 89 protected void updateOpenInActionMode(MenuItem open, SelectionDetails selectionDetails) { 90 updateOpen(open, selectionDetails); 91 } 92 93 @Override 94 protected void updateOpenInContextMenu(MenuItem open, SelectionDetails selectionDetails) { 95 updateOpen(open, selectionDetails); 96 } 97 98 private void updateOpen(MenuItem open, SelectionDetails selectionDetails) { 99 open.setVisible(mState.action == ACTION_GET_CONTENT 100 || mState.action == ACTION_OPEN); 101 open.setEnabled(selectionDetails.size() > 0); 102 } 103} 104