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