The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.internal.view.menu; |
| 18 | |
| 19 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 20 | import com.android.internal.view.menu.MenuBuilder.ItemInvoker; |
| 21 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.res.TypedArray; |
| 24 | import android.util.AttributeSet; |
| 25 | import android.view.View; |
| 26 | import android.widget.AdapterView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.widget.AdapterView.OnItemClickListener; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 28 | import android.widget.ListView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | */ |
| 34 | public 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 Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 54 | public void initialize(MenuBuilder menu) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | mMenu = menu; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | @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 | } |