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.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorSet; | 8 import android.animation.AnimatorSet; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
(...skipping 28 matching lines...) Expand all Loading... |
39 public class AppMenu implements OnItemClickListener, OnKeyListener { | 39 public class AppMenu implements OnItemClickListener, OnKeyListener { |
40 /** Whether or not to show the software menu button in the menu. */ | 40 /** Whether or not to show the software menu button in the menu. */ |
41 private static final boolean SHOW_SW_MENU_BUTTON = true; | 41 private static final boolean SHOW_SW_MENU_BUTTON = true; |
42 | 42 |
43 private static final float LAST_ITEM_SHOW_FRACTION = 0.5f; | 43 private static final float LAST_ITEM_SHOW_FRACTION = 0.5f; |
44 | 44 |
45 private final Menu mMenu; | 45 private final Menu mMenu; |
46 private final int mItemRowHeight; | 46 private final int mItemRowHeight; |
47 private final int mItemDividerHeight; | 47 private final int mItemDividerHeight; |
48 private final int mVerticalFadeDistance; | 48 private final int mVerticalFadeDistance; |
49 private final int mAdditionalVerticalOffset; | 49 private final int mNegativeSoftwareVerticalOffset; |
50 private ListPopupWindow mPopup; | 50 private ListPopupWindow mPopup; |
51 private AppMenuAdapter mAdapter; | 51 private AppMenuAdapter mAdapter; |
52 private AppMenuHandler mHandler; | 52 private AppMenuHandler mHandler; |
53 private int mCurrentScreenRotation = -1; | 53 private int mCurrentScreenRotation = -1; |
54 private boolean mIsByHardwareButton; | 54 private boolean mIsByHardwareButton; |
55 | 55 |
56 /** | 56 /** |
57 * Creates and sets up the App Menu. | 57 * Creates and sets up the App Menu. |
58 * @param menu Original menu created by the framework. | 58 * @param menu Original menu created by the framework. |
59 * @param itemRowHeight Desired height for each app menu row. | 59 * @param itemRowHeight Desired height for each app menu row. |
60 * @param itemDividerHeight Desired height for the divider between app menu
items. | 60 * @param itemDividerHeight Desired height for the divider between app menu
items. |
61 * @param handler AppMenuHandler receives callbacks from AppMenu. | 61 * @param handler AppMenuHandler receives callbacks from AppMenu. |
62 * @param res Resources object used to get dimensions and style attributes. | 62 * @param res Resources object used to get dimensions and style attributes. |
63 */ | 63 */ |
64 AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler
handler, | 64 AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler
handler, |
65 Resources res) { | 65 Resources res) { |
66 mMenu = menu; | 66 mMenu = menu; |
67 | 67 |
68 mItemRowHeight = itemRowHeight; | 68 mItemRowHeight = itemRowHeight; |
69 assert mItemRowHeight > 0; | 69 assert mItemRowHeight > 0; |
70 | 70 |
71 mHandler = handler; | 71 mHandler = handler; |
72 | 72 |
73 mItemDividerHeight = itemDividerHeight; | 73 mItemDividerHeight = itemDividerHeight; |
74 assert mItemDividerHeight >= 0; | 74 assert mItemDividerHeight >= 0; |
75 | 75 |
76 mAdditionalVerticalOffset = | 76 mNegativeSoftwareVerticalOffset = |
77 res.getDimensionPixelSize(R.dimen.menu_software_vertical_offset)
; | 77 res.getDimensionPixelSize(R.dimen.menu_negative_software_vertica
l_offset); |
78 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_
fade_distance); | 78 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_
fade_distance); |
79 } | 79 } |
80 | 80 |
81 /** | 81 /** |
82 * Creates and shows the app menu anchored to the specified view. | 82 * Creates and shows the app menu anchored to the specified view. |
83 * | 83 * |
84 * @param context The context of the AppMenu (ensure the proper
theme is set on | 84 * @param context The context of the AppMenu (ensure the proper
theme is set on |
85 * this context). | 85 * this context). |
86 * @param anchorView The anchor {@link View} of the {@link ListPopu
pWindow}. | 86 * @param anchorView The anchor {@link View} of the {@link ListPopu
pWindow}. |
87 * @param isByHardwareButton Whether or not hardware button triggered it. (
oppose to software | 87 * @param isByHardwareButton Whether or not hardware button triggered it. (
oppose to software |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 assert false; | 200 assert false; |
201 break; | 201 break; |
202 } | 202 } |
203 popup.setHorizontalOffset(horizontalOffset); | 203 popup.setHorizontalOffset(horizontalOffset); |
204 // The menu is displayed above the anchored view, so shift the menu
up by the top | 204 // The menu is displayed above the anchored view, so shift the menu
up by the top |
205 // padding of the background. | 205 // padding of the background. |
206 popup.setVerticalOffset(-paddingRect.bottom); | 206 popup.setVerticalOffset(-paddingRect.bottom); |
207 } else { | 207 } else { |
208 // The menu is displayed over and below the anchored view, so shift
the menu up by the | 208 // The menu is displayed over and below the anchored view, so shift
the menu up by the |
209 // height of the anchor view. | 209 // height of the anchor view. |
210 popup.setVerticalOffset(mAdditionalVerticalOffset - anchorHeight); | 210 popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHei
ght); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 /** | 214 /** |
215 * Handles clicks on the AppMenu popup. | 215 * Handles clicks on the AppMenu popup. |
216 * @param menuItem The menu item in the popup that was clicked. | 216 * @param menuItem The menu item in the popup that was clicked. |
217 */ | 217 */ |
218 void onItemClick(MenuItem menuItem) { | 218 void onItemClick(MenuItem menuItem) { |
219 if (menuItem.isEnabled()) { | 219 if (menuItem.isEnabled()) { |
220 dismiss(); | 220 dismiss(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 builder = animation.play((Animator) animatorObject); | 325 builder = animation.play((Animator) animatorObject); |
326 } else { | 326 } else { |
327 builder.with((Animator) animatorObject); | 327 builder.with((Animator) animatorObject); |
328 } | 328 } |
329 } | 329 } |
330 } | 330 } |
331 | 331 |
332 animation.start(); | 332 animation.start(); |
333 } | 333 } |
334 } | 334 } |
OLD | NEW |