BottomNavigationMenu.java revision 69557a3a037e4124ecbc98560e84fa89472b3bf4
1/* 2 * Copyright (C) 2016 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.design.internal; 18 19import static android.support.annotation.RestrictTo.Scope.GROUP_ID; 20 21import android.content.Context; 22import android.support.annotation.RestrictTo; 23import android.support.v7.view.menu.MenuBuilder; 24import android.support.v7.view.menu.MenuItemImpl; 25import android.view.MenuItem; 26import android.view.SubMenu; 27 28/** 29 * @hide 30 */ 31@RestrictTo(GROUP_ID) 32public final class BottomNavigationMenu extends MenuBuilder { 33 public static final int MAX_ITEM_COUNT = 5; 34 35 public BottomNavigationMenu(Context context) { 36 super(context); 37 } 38 39 @Override 40 public SubMenu addSubMenu(int group, int id, int categoryOrder, CharSequence title) { 41 throw new UnsupportedOperationException("BottomNavigationView does not support submenus"); 42 } 43 44 @Override 45 protected MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) { 46 if (size() + 1 > MAX_ITEM_COUNT) { 47 throw new IllegalArgumentException( 48 "Maximum number of items supported by BottomNavigationView is " + MAX_ITEM_COUNT 49 + ". Limit can be checked with BottomNavigationView#getMaxItemCount()"); 50 } 51 stopDispatchingItemsChanged(); 52 final MenuItem item = super.addInternal(group, id, categoryOrder, title); 53 if (item instanceof MenuItemImpl) { 54 ((MenuItemImpl) item).setExclusiveCheckable(true); 55 } 56 startDispatchingItemsChanged(); 57 return item; 58 } 59} 60