blob: 723ece43a173db914603159e7a9abcbf3c326b91 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Adam Powell696cba52011-03-29 10:38:16 -070020import com.android.internal.view.menu.MenuBuilder.ItemInvoker;
21
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.res.TypedArray;
24import android.util.AttributeSet;
25import android.view.View;
26import android.widget.AdapterView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.widget.AdapterView.OnItemClickListener;
Adam Powell696cba52011-03-29 10:38:16 -070028import android.widget.ListView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
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
Adam Powell696cba52011-03-29 10:38:16 -070054 public void initialize(MenuBuilder menu) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 mMenu = menu;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 }
57
58 @Override
59 protected void onDetachedFromWindow() {
60 super.onDetachedFromWindow();
61
62 // Clear the cached bitmaps of children
63 setChildrenDrawingCacheEnabled(false);
64 }
65
66 @Override
67 protected boolean recycleOnMeasure() {
68 return false;
69 }
70
71 public boolean invokeItem(MenuItemImpl item) {
72 return mMenu.performItemAction(item, 0);
73 }
74
75 public void onItemClick(AdapterView parent, View v, int position, long id) {
76 invokeItem((MenuItemImpl) getAdapter().getItem(position));
77 }
78
79 public int getWindowAnimations() {
80 return mAnimations;
81 }
82
83}