1/* 2 * Copyright (C) 2006 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 com.android.internal.view.menu; 18 19 20import com.android.internal.view.menu.MenuBuilder.ItemInvoker; 21 22import android.content.Context; 23import android.content.res.TypedArray; 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 */ 34public final class ExpandedMenuView extends ListView implements ItemInvoker, MenuView, OnItemClickListener { 35 private MenuBuilder mMenu; 36 37 /** Default animations for this menu */ 38 private int mAnimations; 39 40 /** 41 * Instantiates the ExpandedMenuView that is linked with the provided MenuBuilder. 42 * @param menu The model for the menu which this MenuView will display 43 */ 44 public ExpandedMenuView(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 47 TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.MenuView, 0, 0); 48 mAnimations = a.getResourceId(com.android.internal.R.styleable.MenuView_windowAnimationStyle, 0); 49 a.recycle(); 50 51 setOnItemClickListener(this); 52 } 53 54 public void initialize(MenuBuilder menu) { 55 mMenu = menu; 56 } 57 58 @Override 59 protected void onDetachedFromWindow() { 60 super.onDetachedFromWindow(); 61 62 // Clear the cached bitmaps of children 63 setChildrenDrawingCacheEnabled(false); 64 } 65 66 public boolean invokeItem(MenuItemImpl item) { 67 return mMenu.performItemAction(item, 0); 68 } 69 70 public void onItemClick(AdapterView parent, View v, int position, long id) { 71 invokeItem((MenuItemImpl) getAdapter().getItem(position)); 72 } 73 74 public int getWindowAnimations() { 75 return mAnimations; 76 } 77 78} 79