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.Animator.AnimatorListener; | 8 import android.animation.Animator.AnimatorListener; |
9 import android.animation.AnimatorSet; | 9 import android.animation.AnimatorSet; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.res.Resources; | 11 import android.content.res.Resources; |
12 import android.graphics.Rect; | 12 import android.graphics.Rect; |
13 import android.graphics.drawable.Drawable; | 13 import android.graphics.drawable.Drawable; |
14 import android.os.Build; | 14 import android.os.Build; |
| 15 import android.support.annotation.IdRes; |
15 import android.view.KeyEvent; | 16 import android.view.KeyEvent; |
16 import android.view.LayoutInflater; | 17 import android.view.LayoutInflater; |
17 import android.view.Menu; | 18 import android.view.Menu; |
18 import android.view.MenuItem; | 19 import android.view.MenuItem; |
19 import android.view.Surface; | 20 import android.view.Surface; |
20 import android.view.View; | 21 import android.view.View; |
21 import android.view.View.MeasureSpec; | 22 import android.view.View.MeasureSpec; |
22 import android.view.View.OnKeyListener; | 23 import android.view.View.OnKeyListener; |
23 import android.view.ViewGroup; | 24 import android.view.ViewGroup; |
24 import android.widget.AdapterView; | 25 import android.widget.AdapterView; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 View view = list.getChildAt(index - startIndex); | 122 View view = list.getChildAt(index - startIndex); |
122 if (view == null) return; | 123 if (view == null) return; |
123 | 124 |
124 // Cause the Adapter to re-populate the View. | 125 // Cause the Adapter to re-populate the View. |
125 list.getAdapter().getView(index, view, list); | 126 list.getAdapter().getView(index, view, list); |
126 } | 127 } |
127 | 128 |
128 /** | 129 /** |
129 * Creates and shows the app menu anchored to the specified view. | 130 * Creates and shows the app menu anchored to the specified view. |
130 * | 131 * |
131 * @param context The context of the AppMenu (ensure the proper theme is set
on this context). | 132 * @param context The context of the AppMenu (ensure the proper
theme is set on this |
132 * @param anchorView The anchor {@link View} of the {@link ListPopupWindow}. | 133 * context). |
| 134 * @param anchorView The anchor {@link View} of the {@link ListPopu
pWindow}. |
133 * @param isByPermanentButton Whether or not permanent hardware button trigg
ered it. (oppose to | 135 * @param isByPermanentButton Whether or not permanent hardware button trigg
ered it. (oppose to |
134 * software button or keyboard). | 136 * software button or keyboard). |
135 * @param screenRotation Current device screen rotation. | 137 * @param screenRotation Current device screen rotation. |
136 * @param visibleDisplayFrame The display area rect in which AppMenu is supp
osed to fit in. | 138 * @param visibleDisplayFrame The display area rect in which AppMenu is supp
osed to fit in. |
137 * @param screenHeight Current device screen height. | 139 * @param screenHeight Current device screen height. |
138 * @param footerResourceId The resource id for a view to add to the end of t
he menu list. | 140 * @param footerResourceId The resource id for a view to add to the end o
f the menu list. Can |
139 * Can be 0 if no such view is required. | 141 * be 0 if no such view is required. |
| 142 * @param highlightedItemId The resource id of the menu item that should b
e highlighted. Can |
| 143 * be 0 if no item should be highlighted. |
140 */ | 144 */ |
141 void show(Context context, View anchorView, boolean isByPermanentButton, int
screenRotation, | 145 void show(Context context, View anchorView, boolean isByPermanentButton, int
screenRotation, |
142 Rect visibleDisplayFrame, int screenHeight, int footerResourceId) { | 146 Rect visibleDisplayFrame, int screenHeight, @IdRes int footerResourc
eId, |
| 147 @IdRes int highlightedItemId) { |
143 mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyl
e); | 148 mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyl
e); |
144 mPopup.setModal(true); | 149 mPopup.setModal(true); |
145 mPopup.setAnchorView(anchorView); | 150 mPopup.setAnchorView(anchorView); |
146 mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); | 151 mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); |
147 | 152 |
148 int footerHeight = 0; | 153 int footerHeight = 0; |
149 if (footerResourceId != 0) { | 154 if (footerResourceId != 0) { |
150 mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW); | 155 mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW); |
151 View promptView = LayoutInflater.from(context).inflate(footerResourc
eId, null); | 156 View promptView = LayoutInflater.from(context).inflate(footerResourc
eId, null); |
152 mPopup.setPromptView(promptView); | 157 mPopup.setPromptView(promptView); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 Rect sizingPadding = new Rect(bgPadding); | 219 Rect sizingPadding = new Rect(bgPadding); |
215 if (isByPermanentButton && originalBgDrawable != null) { | 220 if (isByPermanentButton && originalBgDrawable != null) { |
216 Rect originalPadding = new Rect(); | 221 Rect originalPadding = new Rect(); |
217 originalBgDrawable.getPadding(originalPadding); | 222 originalBgDrawable.getPadding(originalPadding); |
218 sizingPadding.top = originalPadding.top; | 223 sizingPadding.top = originalPadding.top; |
219 sizingPadding.bottom = originalPadding.bottom; | 224 sizingPadding.bottom = originalPadding.bottom; |
220 } | 225 } |
221 | 226 |
222 // A List adapter for visible items in the Menu. The first row is added
as a header to the | 227 // A List adapter for visible items in the Menu. The first row is added
as a header to the |
223 // list view. | 228 // list view. |
224 mAdapter = new AppMenuAdapter(this, menuItems, LayoutInflater.from(conte
xt)); | 229 mAdapter = new AppMenuAdapter( |
| 230 this, menuItems, LayoutInflater.from(context), highlightedItemId
); |
225 mPopup.setAdapter(mAdapter); | 231 mPopup.setAdapter(mAdapter); |
226 | 232 |
227 setMenuHeight( | 233 setMenuHeight( |
228 menuItems.size(), visibleDisplayFrame, screenHeight, sizingPaddi
ng, footerHeight); | 234 menuItems.size(), visibleDisplayFrame, screenHeight, sizingPaddi
ng, footerHeight); |
229 setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizi
ngPadding); | 235 setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizi
ngPadding); |
230 mPopup.setOnItemClickListener(this); | 236 mPopup.setOnItemClickListener(this); |
231 mPopup.show(); | 237 mPopup.show(); |
232 mPopup.getListView().setItemsCanFocus(true); | 238 mPopup.getListView().setItemsCanFocus(true); |
233 mPopup.getListView().setOnKeyListener(this); | 239 mPopup.getListView().setOnKeyListener(this); |
234 | 240 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } else { | 434 } else { |
429 builder.with((Animator) animatorObject); | 435 builder.with((Animator) animatorObject); |
430 } | 436 } |
431 } | 437 } |
432 } | 438 } |
433 | 439 |
434 mMenuItemEnterAnimator.addListener(mAnimationHistogramRecorder); | 440 mMenuItemEnterAnimator.addListener(mAnimationHistogramRecorder); |
435 mMenuItemEnterAnimator.start(); | 441 mMenuItemEnterAnimator.start(); |
436 } | 442 } |
437 } | 443 } |
OLD | NEW |