1/* 2 * Copyright (C) 2013 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.support.annotation.RestrictTo; 21import android.support.v7.view.menu.MenuBuilder.ItemInvoker; 22import android.support.v7.widget.TintTypedArray; 23import android.util.AttributeSet; 24import android.view.View; 25import android.widget.AdapterView; 26import android.widget.AdapterView.OnItemClickListener; 27import android.widget.ListView; 28 29import static android.support.annotation.RestrictTo.Scope.GROUP_ID; 30 31/** 32 * The expanded menu view is a list-like menu with all of the available menu items. It is opened 33 * by the user clicking no the 'More' button on the icon menu view. 34 * 35 * @hide 36 */ 37@RestrictTo(GROUP_ID) 38public final class ExpandedMenuView extends ListView 39 implements ItemInvoker, MenuView, OnItemClickListener { 40 41 private static final int[] TINT_ATTRS = { 42 android.R.attr.background, 43 android.R.attr.divider 44 }; 45 46 private MenuBuilder mMenu; 47 48 /** Default animations for this menu */ 49 private int mAnimations; 50 51 public ExpandedMenuView(Context context, AttributeSet attrs) { 52 this(context, attrs, android.R.attr.listViewStyle); 53 } 54 55 public ExpandedMenuView(Context context, AttributeSet attrs, int defStyleAttr) { 56 super(context, attrs); 57 setOnItemClickListener(this); 58 59 TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, TINT_ATTRS, 60 defStyleAttr, 0); 61 if (a.hasValue(0)) { 62 setBackgroundDrawable(a.getDrawable(0)); 63 } 64 if (a.hasValue(1)) { 65 setDivider(a.getDrawable(1)); 66 } 67 a.recycle(); 68 } 69 70 @Override 71 public void initialize(MenuBuilder menu) { 72 mMenu = menu; 73 } 74 75 @Override 76 protected void onDetachedFromWindow() { 77 super.onDetachedFromWindow(); 78 79 // Clear the cached bitmaps of children 80 setChildrenDrawingCacheEnabled(false); 81 } 82 83 @Override 84 public boolean invokeItem(MenuItemImpl item) { 85 return mMenu.performItemAction(item, 0); 86 } 87 88 @Override 89 @SuppressWarnings("rawtypes") 90 public void onItemClick(AdapterView parent, View v, int position, long id) { 91 invokeItem((MenuItemImpl) getAdapter().getItem(position)); 92 } 93 94 @Override 95 public int getWindowAnimations() { 96 return mAnimations; 97 } 98 99} 100