2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.support.v2.view;
19 import android.view.MenuItem;
22 * Helper for accessing newer features in menus.
24 public class MenuCompat {
26 * Interface for the full API.
28 interface MenuVersionImpl {
29 public boolean setShowAsAction(MenuItem item, int actionEnum);
33 * Interface implementation that doesn't use anything about v4 APIs.
35 static class BaseMenuVersionImpl implements MenuVersionImpl {
37 public boolean setShowAsAction(MenuItem item, int actionEnum) {
43 * Interface implementation for devices with at least v11 APIs.
45 static class HoneycombMenuVersionImpl implements MenuVersionImpl {
47 public boolean setShowAsAction(MenuItem item, int actionEnum) {
48 MenuCompatHoneycomb.setShowAsAction(item, actionEnum);
54 * Select the correct implementation to use for the current platform.
56 static final MenuVersionImpl IMPL;
58 //v4 if (android.os.Build.VERSION.SDK_INT >= 11) {
59 if (android.support.v2.os.Build.VERSION.SDK_INT >= 11) {
60 IMPL = new HoneycombMenuVersionImpl();
62 IMPL = new BaseMenuVersionImpl();
66 // -------------------------------------------------------------------
69 * Call {@link MenuItem#setShowAsAction(int) MenuItem.setShowAsAction()}.
70 * If running on a pre-{@android.os.Build.VERSION_CODES#HONEYCOMB} device,
71 * does nothing and returns false. Otherwise returns true.
73 public static boolean setShowAsAction(MenuItem item, int actionEnum) {
74 return IMPL.setShowAsAction(item, actionEnum);