MenuWrapperFactory.java revision 66698bb15ba0f873aa1c2290cc50d6bb839a474a
1/*
2 * Copyright (C) 2012 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 android.support.v7.view.menu;
18
19import android.content.Context;
20import android.os.Build;
21import android.support.v4.internal.view.SupportMenu;
22import android.support.v4.internal.view.SupportMenuItem;
23import android.support.v4.internal.view.SupportSubMenu;
24import android.view.Menu;
25import android.view.MenuItem;
26import android.view.SubMenu;
27
28/**
29 * @hide
30 */
31public final class MenuWrapperFactory {
32    private MenuWrapperFactory() {
33    }
34
35    public static Menu wrapSupportMenu(Context context, SupportMenu supportMenu) {
36        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
37            return new MenuWrapperICS(context, supportMenu);
38        }
39        throw new UnsupportedOperationException();
40    }
41
42    public static MenuItem wrapSupportMenuItem(Context context, SupportMenuItem supportMenuItem) {
43        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
44            return new MenuItemWrapperJB(context, supportMenuItem);
45        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
46            return new MenuItemWrapperICS(context, supportMenuItem);
47        }
48        throw new UnsupportedOperationException();
49    }
50
51    public static SubMenu wrapSupportSubMenu(Context context, SupportSubMenu supportSubMenu) {
52        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
53            return new SubMenuWrapperICS(context, supportSubMenu);
54        }
55        throw new UnsupportedOperationException();
56    }
57}
58