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.util.AttributeSet;
24import android.view.View;
25import android.widget.AdapterView;
26import android.widget.AdapterView.OnItemClickListener;
27import android.widget.ListView;
28
29/**
30 * The expanded menu view is a list-like menu with all of the available menu items.  It is opened
31 * by the user clicking no the 'More' button on the icon menu view.
32 *
33 * @hide
34 */
35public final class ExpandedMenuView extends ListView
36        implements ItemInvoker, MenuView, OnItemClickListener {
37    private MenuBuilder mMenu;
38
39    /** Default animations for this menu */
40    private int mAnimations;
41
42    public ExpandedMenuView(Context context, AttributeSet attrs) {
43        super(context, attrs);
44        setOnItemClickListener(this);
45    }
46
47    @Override
48    public void initialize(MenuBuilder menu) {
49        mMenu = menu;
50    }
51
52    @Override
53    protected void onDetachedFromWindow() {
54        super.onDetachedFromWindow();
55
56        // Clear the cached bitmaps of children
57        setChildrenDrawingCacheEnabled(false);
58    }
59
60    @Override
61    public boolean invokeItem(MenuItemImpl item) {
62        return mMenu.performItemAction(item, 0);
63    }
64
65    @Override
66    @SuppressWarnings("rawtypes")
67    public void onItemClick(AdapterView parent, View v, int position, long id) {
68        invokeItem((MenuItemImpl) getAdapter().getItem(position));
69    }
70
71    @Override
72    public int getWindowAnimations() {
73        return mAnimations;
74    }
75
76}
77