Steve McKay | e980927 | 2015-10-01 11:39:24 -0700 | [diff] [blame] | 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; |
| 18 | |
| 19 | import android.view.Menu; |
| 20 | import android.view.MenuItem; |
| 21 | |
Steve McKay | dad3e16 | 2015-10-27 15:57:53 -0700 | [diff] [blame] | 22 | public final class Menus { |
Steve McKay | e980927 | 2015-10-01 11:39:24 -0700 | [diff] [blame] | 23 | |
| 24 | private Menus() {} |
| 25 | |
| 26 | /** |
| 27 | * Disables hidden menu items so that they are not invokable via command shortcuts |
| 28 | */ |
Steve McKay | dad3e16 | 2015-10-27 15:57:53 -0700 | [diff] [blame] | 29 | public static void disableHiddenItems(Menu menu, MenuItem... exclusions) { |
Steve McKay | e980927 | 2015-10-01 11:39:24 -0700 | [diff] [blame] | 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 | |
| 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 | } |