blob: 5277d2bb86e9d791c25a97eb996ce41ff6c1d973 [file] [log] [blame]
Steve McKaye9809272015-10-01 11:39:24 -07001/*
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
17package com.android.documentsui;
18
19import android.view.Menu;
20import android.view.MenuItem;
21
Steve McKaydad3e162015-10-27 15:57:53 -070022public final class Menus {
Steve McKaye9809272015-10-01 11:39:24 -070023
24 private Menus() {}
25
26 /**
27 * Disables hidden menu items so that they are not invokable via command shortcuts
28 */
Steve McKaydad3e162015-10-27 15:57:53 -070029 public static void disableHiddenItems(Menu menu, MenuItem... exclusions) {
Steve McKaye9809272015-10-01 11:39:24 -070030 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
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}