1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/util/MenuUtils.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.util; 1.10 + 1.11 +import android.view.Menu; 1.12 +import android.view.MenuItem; 1.13 + 1.14 +public class MenuUtils { 1.15 + /* 1.16 + * This method looks for a menuitem and sets it's visible state, if 1.17 + * it exists. 1.18 + */ 1.19 + public static void safeSetVisible(Menu menu, int id, boolean visible) { 1.20 + MenuItem item = menu.findItem(id); 1.21 + if (item != null) { 1.22 + item.setVisible(visible); 1.23 + } 1.24 + } 1.25 + 1.26 + /* 1.27 + * This method looks for a menuitem and sets it's enabled state, if 1.28 + * it exists. 1.29 + */ 1.30 + public static void safeSetEnabled(Menu menu, int id, boolean enabled) { 1.31 + MenuItem item = menu.findItem(id); 1.32 + if (item != null) { 1.33 + item.setEnabled(enabled); 1.34 + } 1.35 + } 1.36 +}