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