| 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 ListPopupWindow mPopup; | 50 private ListPopupWindow mPopup; |
| 50 private AppMenuAdapter mAdapter; | 51 private AppMenuAdapter mAdapter; |
| 51 private AppMenuHandler mHandler; | 52 private AppMenuHandler mHandler; |
| 52 private int mCurrentScreenRotation = -1; | 53 private int mCurrentScreenRotation = -1; |
| 53 private boolean mIsByHardwareButton; | 54 private boolean mIsByHardwareButton; |
| 54 | 55 |
| 55 /** | 56 /** |
| 56 * Creates and sets up the App Menu. | 57 * Creates and sets up the App Menu. |
| 57 * @param menu Original menu created by the framework. | 58 * @param menu Original menu created by the framework. |
| 58 * @param itemRowHeight Desired height for each app menu row. | 59 * @param itemRowHeight Desired height for each app menu row. |
| 59 * @param itemDividerHeight Desired height for the divider between app menu
items. | 60 * @param itemDividerHeight Desired height for the divider between app menu
items. |
| 60 * @param handler AppMenuHandler receives callbacks from AppMenu. | 61 * @param handler AppMenuHandler receives callbacks from AppMenu. |
| 61 * @param res Resources object used to get dimensions and style attributes. | 62 * @param res Resources object used to get dimensions and style attributes. |
| 62 */ | 63 */ |
| 63 AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler
handler, | 64 AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler
handler, |
| 64 Resources res) { | 65 Resources res) { |
| 65 mMenu = menu; | 66 mMenu = menu; |
| 66 | 67 |
| 67 mItemRowHeight = itemRowHeight; | 68 mItemRowHeight = itemRowHeight; |
| 68 assert mItemRowHeight > 0; | 69 assert mItemRowHeight > 0; |
| 69 | 70 |
| 70 mHandler = handler; | 71 mHandler = handler; |
| 71 | 72 |
| 72 mItemDividerHeight = itemDividerHeight; | 73 mItemDividerHeight = itemDividerHeight; |
| 73 assert mItemDividerHeight >= 0; | 74 assert mItemDividerHeight >= 0; |
| 74 | 75 |
| 76 mAdditionalVerticalOffset = |
| 77 res.getDimensionPixelSize(R.dimen.menu_software_vertical_offset)
; |
| 75 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_
fade_distance); | 78 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_
fade_distance); |
| 76 } | 79 } |
| 77 | 80 |
| 78 /** | 81 /** |
| 79 * Creates and shows the app menu anchored to the specified view. | 82 * Creates and shows the app menu anchored to the specified view. |
| 80 * | 83 * |
| 81 * @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 |
| 82 * this context). | 85 * this context). |
| 83 * @param anchorView The anchor {@link View} of the {@link ListPopu
pWindow}. | 86 * @param anchorView The anchor {@link View} of the {@link ListPopu
pWindow}. |
| 84 * @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... |
| 197 assert false; | 200 assert false; |
| 198 break; | 201 break; |
| 199 } | 202 } |
| 200 popup.setHorizontalOffset(horizontalOffset); | 203 popup.setHorizontalOffset(horizontalOffset); |
| 201 // 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 |
| 202 // padding of the background. | 205 // padding of the background. |
| 203 popup.setVerticalOffset(-paddingRect.bottom); | 206 popup.setVerticalOffset(-paddingRect.bottom); |
| 204 } else { | 207 } else { |
| 205 // 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 |
| 206 // height of the anchor view. | 209 // height of the anchor view. |
| 207 popup.setVerticalOffset(-anchorHeight); | 210 popup.setVerticalOffset(mAdditionalVerticalOffset - anchorHeight); |
| 208 } | 211 } |
| 209 } | 212 } |
| 210 | 213 |
| 211 /** | 214 /** |
| 212 * Handles clicks on the AppMenu popup. | 215 * Handles clicks on the AppMenu popup. |
| 213 * @param menuItem The menu item in the popup that was clicked. | 216 * @param menuItem The menu item in the popup that was clicked. |
| 214 */ | 217 */ |
| 215 void onItemClick(MenuItem menuItem) { | 218 void onItemClick(MenuItem menuItem) { |
| 216 if (menuItem.isEnabled()) { | 219 if (menuItem.isEnabled()) { |
| 217 dismiss(); | 220 dismiss(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 builder = animation.play((Animator) animatorObject); | 325 builder = animation.play((Animator) animatorObject); |
| 323 } else { | 326 } else { |
| 324 builder.with((Animator) animatorObject); | 327 builder.with((Animator) animatorObject); |
| 325 } | 328 } |
| 326 } | 329 } |
| 327 } | 330 } |
| 328 | 331 |
| 329 animation.start(); | 332 animation.start(); |
| 330 } | 333 } |
| 331 } | 334 } |
| OLD | NEW |