18262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns/*
28262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * Copyright (C) 2013 The Android Open Source Project
38262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns *
48262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * Licensed under the Apache License, Version 2.0 (the "License");
58262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * you may not use this file except in compliance with the License.
68262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * You may obtain a copy of the License at
78262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns *
88262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns *      http://www.apache.org/licenses/LICENSE-2.0
98262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns *
108262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * Unless required by applicable law or agreed to in writing, software
118262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * distributed under the License is distributed on an "AS IS" BASIS,
128262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * See the License for the specific language governing permissions and
148262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * limitations under the License.
158262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns */
168262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
17da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownpackage android.support.v7.internal.view.menu;
188262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
198262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johnsimport android.content.Context;
20da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuBuilder;
21da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuBuilder.ItemInvoker;
22da10fdd1400ecfd8d7f2e55651dd528d0614dfc5Jeff Brownimport android.support.v7.internal.view.menu.MenuView;
238262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johnsimport android.util.AttributeSet;
248262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johnsimport android.view.View;
258262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johnsimport android.widget.AdapterView;
268262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johnsimport android.widget.AdapterView.OnItemClickListener;
278262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johnsimport android.widget.ListView;
288262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
298262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns/**
308262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * The expanded menu view is a list-like menu with all of the available menu items.  It is opened
318262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns * by the user clicking no the 'More' button on the icon menu view.
3289208232f3b5d1451408d787872504a190bc7ee0Chris Banes *
3389208232f3b5d1451408d787872504a190bc7ee0Chris Banes * @hide
348262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns */
35b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brownpublic final class ExpandedMenuView extends ListView
36b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brown        implements ItemInvoker, MenuView, OnItemClickListener {
378262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    private MenuBuilder mMenu;
388262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
398262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    /** Default animations for this menu */
408262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    private int mAnimations;
418262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
428262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    public ExpandedMenuView(Context context, AttributeSet attrs) {
438262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        super(context, attrs);
448262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        setOnItemClickListener(this);
458262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    }
468262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
47b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brown    @Override
488262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    public void initialize(MenuBuilder menu) {
498262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        mMenu = menu;
508262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    }
518262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
528262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    @Override
538262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    protected void onDetachedFromWindow() {
548262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        super.onDetachedFromWindow();
558262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
568262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        // Clear the cached bitmaps of children
578262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        setChildrenDrawingCacheEnabled(false);
588262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    }
598262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
60b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brown    @Override
618262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    public boolean invokeItem(MenuItemImpl item) {
628262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        return mMenu.performItemAction(item, 0);
638262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    }
648262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
65b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brown    @Override
66b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brown    @SuppressWarnings("rawtypes")
678262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    public void onItemClick(AdapterView parent, View v, int position, long id) {
688262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        invokeItem((MenuItemImpl) getAdapter().getItem(position));
698262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    }
708262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
71b79bd8bd1afdf165068ddafdc5fa0667f7ec4a70Jeff Brown    @Override
728262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    public int getWindowAnimations() {
738262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns        return mAnimations;
748262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns    }
758262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns
768262949c1a6b7e191020b31fc914972bb0b58ab0Trevor Johns}
77