1 /*
2  * Copyright (C) 2015 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.base;
18 
19 import android.view.Menu;
20 import android.view.MenuItem;
21 
22 public final class Menus {
23 
Menus()24     private Menus() {}
25 
26     /**
27      * Disables hidden menu items so that they are not invokable via command shortcuts
28      */
disableHiddenItems(Menu menu, MenuItem... exclusions)29     public static void disableHiddenItems(Menu menu, MenuItem... exclusions) {
30         for (int i = 0; i < menu.size(); i++) {
31             MenuItem item = menu.getItem(i);
32             if (item.isVisible()) {
33               continue;
34             }
35             if (contains(exclusions, item)) {
36                 continue;
37             }
38             item.setEnabled(false);
39         }
40     }
41 
contains(MenuItem[] exclusions, MenuItem item)42     private static boolean contains(MenuItem[] exclusions, MenuItem item) {
43         for (int x = 0; x < exclusions.length; x++) {
44             if (exclusions[x] == item) {
45                 return true;
46             }
47         }
48         return false;
49     }
50 }
51