ExpandedMenuView.java revision b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70
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 */
33public final class ExpandedMenuView extends ListView
34        implements ItemInvoker, MenuView, OnItemClickListener {
35    private MenuBuilder mMenu;
36
37    /** Default animations for this menu */
38    private int mAnimations;
39
40    public ExpandedMenuView(Context context, AttributeSet attrs) {
41        super(context, attrs);
42        setOnItemClickListener(this);
43    }
44
45    @Override
46    public void initialize(MenuBuilder menu) {
47        mMenu = menu;
48    }
49
50    @Override
51    protected void onDetachedFromWindow() {
52        super.onDetachedFromWindow();
53
54        // Clear the cached bitmaps of children
55        setChildrenDrawingCacheEnabled(false);
56    }
57
58    @Override
59    public boolean invokeItem(MenuItemImpl item) {
60        return mMenu.performItemAction(item, 0);
61    }
62
63    @Override
64    @SuppressWarnings("rawtypes")
65    public void onItemClick(AdapterView parent, View v, int position, long id) {
66        invokeItem((MenuItemImpl) getAdapter().getItem(position));
67    }
68
69    @Override
70    public int getWindowAnimations() {
71        return mAnimations;
72    }
73
74}
75