OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.appmenu; | 5 package org.chromium.chrome.browser.appmenu; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
10 import android.view.KeyEvent; | 10 import android.view.KeyEvent; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler
handler, | 58 AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler
handler, |
59 Resources res) { | 59 Resources res) { |
60 mMenu = menu; | 60 mMenu = menu; |
61 | 61 |
62 mItemRowHeight = itemRowHeight; | 62 mItemRowHeight = itemRowHeight; |
63 assert mItemRowHeight > 0; | 63 assert mItemRowHeight > 0; |
64 | 64 |
65 mHandler = handler; | 65 mHandler = handler; |
66 | 66 |
67 mItemDividerHeight = itemDividerHeight; | 67 mItemDividerHeight = itemDividerHeight; |
68 assert mItemDividerHeight > 0; | 68 assert mItemDividerHeight >= 0; |
69 | 69 |
70 mAdditionalVerticalOffset = res.getDimensionPixelSize(R.dimen.menu_verti
cal_offset); | 70 mAdditionalVerticalOffset = res.getDimensionPixelSize(R.dimen.menu_verti
cal_offset); |
71 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_
fade_distance); | 71 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_
fade_distance); |
72 } | 72 } |
73 | 73 |
74 /** | 74 /** |
75 * Creates and shows the app menu anchored to the specified view. | 75 * Creates and shows the app menu anchored to the specified view. |
76 * | 76 * |
77 * @param context The context of the AppMenu (ensure the proper
theme is set on | 77 * @param context The context of the AppMenu (ensure the proper
theme is set on |
78 * this context). | 78 * this context). |
(...skipping 13 matching lines...) Expand all Loading... |
92 @Override | 92 @Override |
93 public void onDismiss() { | 93 public void onDismiss() { |
94 if (mPopup.getAnchorView() instanceof ImageButton) { | 94 if (mPopup.getAnchorView() instanceof ImageButton) { |
95 ((ImageButton) mPopup.getAnchorView()).setSelected(false); | 95 ((ImageButton) mPopup.getAnchorView()).setSelected(false); |
96 } | 96 } |
97 mHandler.onMenuVisibilityChanged(false); | 97 mHandler.onMenuVisibilityChanged(false); |
98 } | 98 } |
99 }); | 99 }); |
100 mPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.men
u_width)); | 100 mPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.men
u_width)); |
101 | 101 |
| 102 // Need to explicitly set the background here. Relying on it being set
in the style caused |
| 103 // an incorrectly drawn background. |
| 104 mPopup.setBackgroundDrawable(context.getResources().getDrawable(R.drawab
le.menu_bg)); |
| 105 |
102 mCurrentScreenRotation = screenRotation; | 106 mCurrentScreenRotation = screenRotation; |
103 mIsByHardwareButton = isByHardwareButton; | 107 mIsByHardwareButton = isByHardwareButton; |
104 | 108 |
105 // Extract visible items from the Menu. | 109 // Extract visible items from the Menu. |
106 int numItems = mMenu.size(); | 110 int numItems = mMenu.size(); |
107 List<MenuItem> menuItems = new ArrayList<MenuItem>(); | 111 List<MenuItem> menuItems = new ArrayList<MenuItem>(); |
108 for (int i = 0; i < numItems; ++i) { | 112 for (int i = 0; i < numItems; ++i) { |
109 MenuItem item = mMenu.getItem(i); | 113 MenuItem item = mMenu.getItem(i); |
110 if (item.isVisible()) { | 114 if (item.isVisible()) { |
111 menuItems.add(item); | 115 menuItems.add(item); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 padding.top + padding.bottom); | 258 padding.top + padding.bottom); |
255 } else { | 259 } else { |
256 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa
rtialItem + | 260 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa
rtialItem + |
257 padding.top + padding.bottom); | 261 padding.top + padding.bottom); |
258 } | 262 } |
259 } else { | 263 } else { |
260 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | 264 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
261 } | 265 } |
262 } | 266 } |
263 } | 267 } |
OLD | NEW |