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