NavigationSubMenu.java revision 6c72ea0134a3309ff8197f0862aad8d7bc712b55
1/* 2 * Copyright (C) 2015 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 android.content.Context; 20import android.support.v7.internal.view.menu.MenuBuilder; 21import android.support.v7.internal.view.menu.MenuItemImpl; 22import android.support.v7.internal.view.menu.SubMenuBuilder; 23import android.view.MenuItem; 24 25/** 26 * This is a {@link SubMenuBuilder} that it notifies the parent {@link NavigationMenu} of its menu 27 * updates. 28 * 29 * @hide 30 */ 31public class NavigationSubMenu extends SubMenuBuilder { 32 33 public NavigationSubMenu(Context context, NavigationMenu menu, MenuItemImpl item) { 34 super(context, menu, item); 35 } 36 37 @Override 38 public MenuItem add(CharSequence title) { 39 MenuItem item = super.add(title); 40 notifyParent(); 41 return item; 42 } 43 44 @Override 45 public MenuItem add(int titleRes) { 46 MenuItem item = super.add(titleRes); 47 notifyParent(); 48 return item; 49 } 50 51 @Override 52 public MenuItem add(int groupId, int itemId, int order, CharSequence title) { 53 MenuItem item = super.add(groupId, itemId, order, title); 54 notifyParent(); 55 return item; 56 } 57 58 @Override 59 public MenuItem add(int groupId, int itemId, int order, int titleRes) { 60 MenuItem item = super.add(groupId, itemId, order, titleRes); 61 notifyParent(); 62 return item; 63 } 64 65 private void notifyParent() { 66 ((MenuBuilder) getParentMenu()).onItemsChanged(true); 67 } 68 69} 70