| 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 20 matching lines...) Expand all Loading... |
| 31 import java.util.ArrayList; | 31 import java.util.ArrayList; |
| 32 import java.util.List; | 32 import java.util.List; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Shows a popup of menuitems anchored to a host view. When a item is selected w
e call | 35 * Shows a popup of menuitems anchored to a host view. When a item is selected w
e call |
| 36 * Activity.onOptionsItemSelected with the appropriate MenuItem. | 36 * Activity.onOptionsItemSelected with the appropriate MenuItem. |
| 37 * - Only visible MenuItems are shown. | 37 * - Only visible MenuItems are shown. |
| 38 * - Disabled items are grayed out. | 38 * - Disabled items are grayed out. |
| 39 */ | 39 */ |
| 40 public class AppMenu implements OnItemClickListener, OnKeyListener { | 40 public class AppMenu implements OnItemClickListener, OnKeyListener { |
| 41 /** Whether or not to show the software menu button in the menu. */ | |
| 42 private static final boolean SHOW_SW_MENU_BUTTON = true; | |
| 43 | 41 |
| 44 private static final float LAST_ITEM_SHOW_FRACTION = 0.5f; | 42 private static final float LAST_ITEM_SHOW_FRACTION = 0.5f; |
| 45 | 43 |
| 46 private final Menu mMenu; | 44 private final Menu mMenu; |
| 47 private final int mItemRowHeight; | 45 private final int mItemRowHeight; |
| 48 private final int mItemDividerHeight; | 46 private final int mItemDividerHeight; |
| 49 private final int mVerticalFadeDistance; | 47 private final int mVerticalFadeDistance; |
| 50 private final int mNegativeSoftwareVerticalOffset; | 48 private final int mNegativeSoftwareVerticalOffset; |
| 51 private ListPopupWindow mPopup; | 49 private ListPopupWindow mPopup; |
| 52 private AppMenuAdapter mAdapter; | 50 private AppMenuAdapter mAdapter; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 145 } |
| 148 | 146 |
| 149 Rect sizingPadding = new Rect(bgPadding); | 147 Rect sizingPadding = new Rect(bgPadding); |
| 150 if (isByHardwareButton && originalBgDrawable != null) { | 148 if (isByHardwareButton && originalBgDrawable != null) { |
| 151 Rect originalPadding = new Rect(); | 149 Rect originalPadding = new Rect(); |
| 152 originalBgDrawable.getPadding(originalPadding); | 150 originalBgDrawable.getPadding(originalPadding); |
| 153 sizingPadding.top = originalPadding.top; | 151 sizingPadding.top = originalPadding.top; |
| 154 sizingPadding.bottom = originalPadding.bottom; | 152 sizingPadding.bottom = originalPadding.bottom; |
| 155 } | 153 } |
| 156 | 154 |
| 157 boolean showMenuButton = !mIsByHardwareButton; | |
| 158 if (!SHOW_SW_MENU_BUTTON) showMenuButton = false; | |
| 159 // A List adapter for visible items in the Menu. The first row is added
as a header to the | 155 // A List adapter for visible items in the Menu. The first row is added
as a header to the |
| 160 // list view. | 156 // list view. |
| 161 mAdapter = new AppMenuAdapter( | 157 mAdapter = new AppMenuAdapter( |
| 162 this, menuItems, LayoutInflater.from(context), | 158 this, menuItems, LayoutInflater.from(context), |
| 163 showMenuButton, menuButtonStartPaddingPx); | 159 false, menuButtonStartPaddingPx); |
| 164 mPopup.setAdapter(mAdapter); | 160 mPopup.setAdapter(mAdapter); |
| 165 | 161 |
| 166 setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizin
gPadding); | 162 setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizin
gPadding); |
| 167 setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizi
ngPadding); | 163 setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizi
ngPadding); |
| 168 mPopup.setOnItemClickListener(this); | 164 mPopup.setOnItemClickListener(this); |
| 169 mPopup.show(); | 165 mPopup.show(); |
| 170 mPopup.getListView().setItemsCanFocus(true); | 166 mPopup.getListView().setItemsCanFocus(true); |
| 171 mPopup.getListView().setOnKeyListener(this); | 167 mPopup.getListView().setOnKeyListener(this); |
| 172 | 168 |
| 173 mHandler.onMenuVisibilityChanged(true); | 169 mHandler.onMenuVisibilityChanged(true); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 builder = animation.play((Animator) animatorObject); | 335 builder = animation.play((Animator) animatorObject); |
| 340 } else { | 336 } else { |
| 341 builder.with((Animator) animatorObject); | 337 builder.with((Animator) animatorObject); |
| 342 } | 338 } |
| 343 } | 339 } |
| 344 } | 340 } |
| 345 | 341 |
| 346 animation.start(); | 342 animation.start(); |
| 347 } | 343 } |
| 348 } | 344 } |
| OLD | NEW |