Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java

Issue 203173008: Cleanup Icon Row custom code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.app.Activity;
8 import android.content.Context; 7 import android.content.Context;
9 import android.content.res.Resources; 8 import android.content.res.Resources;
10 import android.graphics.Rect; 9 import android.graphics.Rect;
11 import android.view.KeyEvent;
12 import android.view.LayoutInflater; 10 import android.view.LayoutInflater;
13 import android.view.Menu; 11 import android.view.Menu;
14 import android.view.MenuItem; 12 import android.view.MenuItem;
15 import android.view.Surface; 13 import android.view.Surface;
16 import android.view.View; 14 import android.view.View;
17 import android.view.View.OnClickListener;
18 import android.view.View.OnKeyListener;
19 import android.view.ViewGroup; 15 import android.view.ViewGroup;
20 import android.widget.AdapterView;
21 import android.widget.HeaderViewListAdapter;
22 import android.widget.ImageButton; 16 import android.widget.ImageButton;
23 import android.widget.ListPopupWindow; 17 import android.widget.ListPopupWindow;
24 import android.widget.ListView; 18 import android.widget.ListView;
25 import android.widget.ListView.FixedViewInfo;
26 import android.widget.PopupWindow; 19 import android.widget.PopupWindow;
27 import android.widget.PopupWindow.OnDismissListener; 20 import android.widget.PopupWindow.OnDismissListener;
28 21
29 import com.google.common.annotations.VisibleForTesting; 22 import com.google.common.annotations.VisibleForTesting;
30 23
31 import org.chromium.chrome.R; 24 import org.chromium.chrome.R;
32 import org.chromium.chrome.browser.BookmarksBridge;
33 import org.chromium.chrome.browser.util.KeyNavigationUtil;
34 25
35 import java.util.ArrayList; 26 import java.util.ArrayList;
36 import java.util.List; 27 import java.util.List;
37 28
38 /** 29 /**
39 * Shows a popup of menuitems anchored to a host view. When a item is selected w e call 30 * Shows a popup of menuitems anchored to a host view. When a item is selected w e call
40 * Activity.onOptionsItemSelected with the appropriate MenuItem. 31 * Activity.onOptionsItemSelected with the appropriate MenuItem.
41 * - Only visible MenuItems are shown. 32 * - Only visible MenuItems are shown.
42 * - Disabled items are grayed out. 33 * - Disabled items are grayed out.
43 */ 34 */
44 public class AppMenu implements AdapterView.OnItemClickListener, OnKeyListener { 35 public class AppMenu {
45 private static final float LAST_ITEM_SHOW_FRACTION = 0.5f; 36 private static final float LAST_ITEM_SHOW_FRACTION = 0.5f;
46 private static final int DIVIDER_HEIGHT_DP = 1; 37 private static final int DIVIDER_HEIGHT_DP = 1;
47 38
48 private final Menu mMenu; 39 private final Menu mMenu;
49 private final Activity mActivity;
50 private final int mItemRowHeight; 40 private final int mItemRowHeight;
51 private final int mItemDividerHeight; 41 private final int mItemDividerHeight;
52 private final int mVerticalFadeDistance; 42 private final int mVerticalFadeDistance;
53 private final int mAdditionalVerticalOffset; 43 private final int mAdditionalVerticalOffset;
54 private ListPopupWindow mPopup; 44 private ListPopupWindow mPopup;
55 private LayoutInflater mInflater;
56 private boolean mShowIconRow;
57 private AppMenuAdapter mAdapter; 45 private AppMenuAdapter mAdapter;
58 private View mIconRowView;
59 private AppMenuHandler mHandler; 46 private AppMenuHandler mHandler;
60 private int mCurrentScreenRotation = -1; 47 private int mCurrentScreenRotation = -1;
61 private boolean mIsByHardwareButton; 48 private boolean mIsByHardwareButton;
62 49
63 /** 50 /**
64 * Creates and sets up the App Menu. 51 * Creates and sets up the App Menu.
65 * @param activity Activity that will handle app menu callbacks.
66 * @param menu Original menu created by the framework. 52 * @param menu Original menu created by the framework.
67 * @param itemRowHeight Desired height for each app menu row. 53 * @param itemRowHeight Desired height for each app menu row.
David Trainor- moved to gerrit 2014/03/19 07:03:38 Update javadoc
aurimas (slooooooooow) 2014/03/19 18:32:53 Done.
68 */ 54 */
69 AppMenu(Activity activity, Menu menu, int itemRowHeight, AppMenuHandler hand ler) { 55 AppMenu(Menu menu, int itemRowHeight, AppMenuHandler handler, Resources res) {
70 mActivity = activity;
71 mMenu = menu; 56 mMenu = menu;
72 57
73 mItemRowHeight = itemRowHeight; 58 mItemRowHeight = itemRowHeight;
74 assert mItemRowHeight > 0; 59 assert mItemRowHeight > 0;
75 60
76 mHandler = handler; 61 mHandler = handler;
77 Resources res = mActivity.getResources();
78 62
79 final float dpToPx = res.getDisplayMetrics().density; 63 final float dpToPx = res.getDisplayMetrics().density;
80 mItemDividerHeight = (int) (DIVIDER_HEIGHT_DP * dpToPx); 64 mItemDividerHeight = (int) (DIVIDER_HEIGHT_DP * dpToPx);
81 65
82 mAdditionalVerticalOffset = res.getDimensionPixelSize(R.dimen.menu_verti cal_offset); 66 mAdditionalVerticalOffset = res.getDimensionPixelSize(R.dimen.menu_verti cal_offset);
83 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_ fade_distance); 67 mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_ fade_distance);
84 } 68 }
85 69
86 /** 70 /**
87 * Creates and shows the app menu anchored to the specified view. 71 * Creates and shows the app menu anchored to the specified view.
88 * 72 *
89 * @param context The context of the app popup (ensure the proper theme is set on 73 * @param context The context of the app popup (ensure the proper theme is set on
90 * this context). 74 * this context).
91 * @param anchorView The anchor {@link View} of the {@link ListPopup Window}. 75 * @param anchorView The anchor {@link View} of the {@link ListPopup Window}.
92 * @param showIconRow Whether or not the icon row should be shown,
93 * @param isByHardwareButton Whether or not hardware button triggered it. (o ppose to software 76 * @param isByHardwareButton Whether or not hardware button triggered it. (o ppose to software
David Trainor- moved to gerrit 2014/03/19 07:03:38 Update javadoc
aurimas (slooooooooow) 2014/03/19 18:32:53 Done.
94 * button) 77 * button)
95 */ 78 */
96 void show(Context context, View anchorView, boolean showIconRow, boolean isB yHardwareButton) { 79 void show(Context context, View anchorView, boolean isByHardwareButton, int screenRotation,
80 Rect visibleDisplayFrame) {
97 mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyl e); 81 mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyl e);
98 mInflater = LayoutInflater.from(context);
99 mPopup.setModal(true); 82 mPopup.setModal(true);
100 mPopup.setAnchorView(anchorView); 83 mPopup.setAnchorView(anchorView);
101 mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); 84 mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
102 mPopup.setOnDismissListener(new OnDismissListener() { 85 mPopup.setOnDismissListener(new OnDismissListener() {
103 @Override 86 @Override
104 public void onDismiss() { 87 public void onDismiss() {
105 if (mPopup.getAnchorView() instanceof ImageButton) { 88 if (mPopup.getAnchorView() instanceof ImageButton) {
106 ((ImageButton) mPopup.getAnchorView()).setSelected(false); 89 ((ImageButton) mPopup.getAnchorView()).setSelected(false);
107 } 90 }
108 mHandler.onMenuVisibilityChanged(false); 91 mHandler.onMenuVisibilityChanged(false);
109 } 92 }
110 }); 93 });
111 mPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.men u_width)); 94 mPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.men u_width));
112 95
113 mShowIconRow = showIconRow; 96 mCurrentScreenRotation = screenRotation;
114 mCurrentScreenRotation = mActivity.getWindowManager().getDefaultDisplay( ).getRotation();
115 mIsByHardwareButton = isByHardwareButton; 97 mIsByHardwareButton = isByHardwareButton;
116 98
117 // Extract visible items from the Menu. 99 // Extract visible items from the Menu.
118 int numItems = mMenu.size(); 100 int numItems = mMenu.size();
119 List<MenuItem> menuItems = new ArrayList<MenuItem>(); 101 List<MenuItem> menuItems = new ArrayList<MenuItem>();
120 for (int i = 0; i < numItems; ++i) { 102 for (int i = 0; i < numItems; ++i) {
121 MenuItem item = mMenu.getItem(i); 103 MenuItem item = mMenu.getItem(i);
122 if (item.isVisible()) { 104 if (item.isVisible()) {
123 menuItems.add(item); 105 menuItems.add(item);
124 } 106 }
125 } 107 }
126 108
127 // A List adapter for visible items in the Menu. The first row is added as a header to the 109 // A List adapter for visible items in the Menu. The first row is added as a header to the
128 // list view. 110 // list view.
129 mAdapter = new AppMenuAdapter(menuItems, mInflater); 111 mAdapter = new AppMenuAdapter(this, menuItems, LayoutInflater.from(conte xt));
130 if (mShowIconRow) { 112 mPopup.setAdapter(mAdapter);
131 mIconRowView = mInflater.inflate(R.layout.menu_icon_row, null);
132 // Add click handlers for the header icons.
133 setIconRowEventHandlers(mIconRowView);
134 updateBookmarkButton();
135 113
136 // Icon row goes into header of List view. 114 setMenuHeight(menuItems.size(), visibleDisplayFrame);
137 ArrayList<FixedViewInfo> headerInfoList = 115 setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame);
138 populateHeaderViewInfo(mActivity.getApplicationContext(), mI conRowView);
139
140 HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdap ter(
141 headerInfoList, null, mAdapter);
142 mPopup.setAdapter(headerViewListAdapter);
143 } else {
144 mPopup.setAdapter(mAdapter);
145 }
146
147 // Get the height and width of the display.
148 Rect appRect = new Rect();
149 mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(appRec t);
150
151 setMenuHeight(menuItems.size() + (mShowIconRow ? 1 : 0), appRect);
152 setPopupOffset(mPopup, mCurrentScreenRotation, appRect);
153 mPopup.setOnItemClickListener(this);
154 mPopup.show(); 116 mPopup.show();
155 mPopup.getListView().setDividerHeight(mItemDividerHeight); 117 mPopup.getListView().setDividerHeight(mItemDividerHeight);
118 mPopup.getListView().setItemsCanFocus(true);
156 119
157 mHandler.onMenuVisibilityChanged(true); 120 mHandler.onMenuVisibilityChanged(true);
158 121
159 if (mVerticalFadeDistance > 0) { 122 if (mVerticalFadeDistance > 0) {
160 mPopup.getListView().setVerticalFadingEdgeEnabled(true); 123 mPopup.getListView().setVerticalFadingEdgeEnabled(true);
161 mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance); 124 mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance);
162 } 125 }
163
164 mPopup.getListView().setOnKeyListener(this);
165 } 126 }
166 127
167 private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect appRect) { 128 private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect appRect) {
168 Rect paddingRect = new Rect(); 129 Rect paddingRect = new Rect();
169 popup.getBackground().getPadding(paddingRect); 130 popup.getBackground().getPadding(paddingRect);
170 int[] anchorLocation = new int[2]; 131 int[] anchorLocation = new int[2];
171 popup.getAnchorView().getLocationInWindow(anchorLocation); 132 popup.getAnchorView().getLocationInWindow(anchorLocation);
172 133
173 // If we have a hardware menu button, locate the app menu closer to the estimated 134 // If we have a hardware menu button, locate the app menu closer to the estimated
174 // hardware menu button location. 135 // hardware menu button location.
(...skipping 17 matching lines...) Expand all
192 // The menu is displayed above the anchored view, so shift the menu up by the top 153 // The menu is displayed above the anchored view, so shift the menu up by the top
193 // padding of the background. 154 // padding of the background.
194 popup.setVerticalOffset(mAdditionalVerticalOffset - paddingRect.bott om); 155 popup.setVerticalOffset(mAdditionalVerticalOffset - paddingRect.bott om);
195 } else { 156 } else {
196 // The menu is displayed below the anchored view, so shift the menu up by the top 157 // The menu is displayed below the anchored view, so shift the menu up by the top
197 // padding of the background. 158 // padding of the background.
198 popup.setVerticalOffset(mAdditionalVerticalOffset - paddingRect.top) ; 159 popup.setVerticalOffset(mAdditionalVerticalOffset - paddingRect.top) ;
199 } 160 }
200 } 161 }
201 162
202 @Override 163 void onItemClick(MenuItem menuItem) {
David Trainor- moved to gerrit 2014/03/19 07:03:38 Javadoc
aurimas (slooooooooow) 2014/03/19 18:32:53 Done.
203 public boolean onKey(View v, int keyCode, KeyEvent event) { 164 if (menuItem.isEnabled()) {
204 if (mPopup == null || mPopup.getListView() == null) return false;
205
206 ListView listView = mPopup.getListView();
207 if (KeyNavigationUtil.isGoUp(event)) {
208 int previousPosition = listView.getSelectedItemPosition();
209 boolean handled = mPopup.onKeyDown(keyCode, event);
210 if (listView.getSelectedItemPosition() == ListView.INVALID_POSITION) {
211 listView.setSelection(0);
212 }
213
214 if (mShowIconRow && previousPosition == 1) {
215 // Clearing the selection is required to move into the icon row.
216 mPopup.clearListSelection();
217 requestFocusToEnabledIconRowButton();
218 }
219 return handled;
220 } else if (KeyNavigationUtil.isGoDown(event)) {
221 boolean handled = mPopup.onKeyDown(keyCode, event);
222 if (listView.getSelectedItemPosition() == ListView.INVALID_POSITION) {
223 listView.setSelection(listView.getCount() - 1);
224 }
225 return handled;
226 } else if (KeyNavigationUtil.isEnter(event)) {
227 int position = getCurrentFocusedPosition();
228 if (mShowIconRow && position == 0) return false;
229
230 int adjustedPosition = mShowIconRow ? position - 1 : position;
231 MenuItem clickedItem = mAdapter.getItem(adjustedPosition);
232 dismiss(); 165 dismiss();
233 mHandler.onOptionsItemSelected(clickedItem); 166 mHandler.onOptionsItemSelected(menuItem);
234 return true;
235 } else if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
236 if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCoun t() == 0) {
237 event.startTracking();
238 v.getKeyDispatcherState().startTracking(event, this);
239 return true;
240 } else if (event.getAction() == KeyEvent.ACTION_UP) {
241 v.getKeyDispatcherState().handleUpEvent(event);
242 if (event.isTracking() && !event.isCanceled()) {
243 dismiss();
244 return true;
245 }
246 }
247 return false;
248 }
249
250 return false;
251 }
252
253 @Override
254 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
255 // Account for header. MenuAdapter does not know about header,
256 // but the 'position' includes the header.
257 int adjustedPosition = mShowIconRow ? position - 1 : position;
258 MenuItem clickedItem = mAdapter.getItem(adjustedPosition);
259 if (clickedItem.isEnabled()) {
260 dismiss();
261 mHandler.onOptionsItemSelected(clickedItem);
262 } 167 }
263 } 168 }
264 169
265 /** 170 /**
266 * Dismisses the app menu and cancels the drag-to-scroll if it is taking pla ce. 171 * Dismisses the app menu and cancels the drag-to-scroll if it is taking pla ce.
267 */ 172 */
268 void dismiss() { 173 void dismiss() {
269 mHandler.appMenudismiss(); 174 mHandler.appMenudismiss();
270 if (isShowing()) mPopup.dismiss(); 175 if (isShowing()) mPopup.dismiss();
271 } 176 }
(...skipping 11 matching lines...) Expand all
283 @VisibleForTesting 188 @VisibleForTesting
284 int getCount() { 189 int getCount() {
285 if (mPopup == null || mPopup.getListView() == null) return 0; 190 if (mPopup == null || mPopup.getListView() == null) return 0;
286 return mPopup.getListView().getCount(); 191 return mPopup.getListView().getCount();
287 } 192 }
288 193
289 ListPopupWindow getPopup() { 194 ListPopupWindow getPopup() {
290 return mPopup; 195 return mPopup;
291 } 196 }
292 197
293 boolean isShowingIconRow() {
294 return mShowIconRow;
295 }
296
297 View getIconRowView() {
298 return mIconRowView;
299 }
300
301 int getItemRowHeight() { 198 int getItemRowHeight() {
302 return mItemRowHeight; 199 return mItemRowHeight;
303 } 200 }
304 201
305 private void updateBookmarkButton() {
306 final MenuItem bookmarkMenuItem = mMenu.findItem(R.id.bookmark_this_page _id);
307 ImageButton bookmarkButton =
308 (ImageButton) mIconRowView.findViewById(R.id.menu_item_bookmark) ;
309 if (bookmarkMenuItem.isEnabled()) {
310 bookmarkButton.setImageResource(R.drawable.star);
311 bookmarkButton.setContentDescription(bookmarkButton.getContext().get String(
312 R.string.accessibility_menu_bookmark));
313 } else {
314 bookmarkButton.setImageResource(R.drawable.star_lit);
315 bookmarkButton.setContentDescription(bookmarkButton.getContext().get String(
316 R.string.accessibility_menu_edit_bookmark));
317 }
318 }
319
320 @VisibleForTesting 202 @VisibleForTesting
321 int getCurrentFocusedPosition() { 203 int getCurrentFocusedPosition() {
322 if (mPopup == null || mPopup.getListView() == null) return ListView.INVA LID_POSITION; 204 if (mPopup == null || mPopup.getListView() == null) return ListView.INVA LID_POSITION;
323 ListView listView = mPopup.getListView(); 205 ListView listView = mPopup.getListView();
324 int position = listView.getSelectedItemPosition(); 206 int position = listView.getSelectedItemPosition();
325 207 System.out.println("aurimas getCurrentFocusedPosition " + position);
David Trainor- moved to gerrit 2014/03/19 07:03:38 Remove
aurimas (slooooooooow) 2014/03/19 18:32:53 Done.
326 // Check if any of the icon row icons are focused.
327 if (mShowIconRow) {
328 if (mIconRowView.findViewById(R.id.menu_item_back).isFocused() ||
329 mIconRowView.findViewById(R.id.menu_item_forward).isFocused( ) ||
330 mIconRowView.findViewById(R.id.menu_item_bookmark).isFocused ()) {
331 return 0;
332 }
333 }
334 return position; 208 return position;
335 } 209 }
336 210
337 @VisibleForTesting 211 @VisibleForTesting
338 int getCurrentFocusedItemId() { 212 int getCurrentFocusedItemId() {
339 int position = getCurrentFocusedPosition(); 213 int position = getCurrentFocusedPosition();
340 if (position == ListView.INVALID_POSITION) return -1; 214 if (position == ListView.INVALID_POSITION) return -1;
341 if (mShowIconRow && position == 0) { 215 int adjustedPosition = position;
David Trainor- moved to gerrit 2014/03/19 07:03:38 Don't need this int anymore. Just pass in positio
aurimas (slooooooooow) 2014/03/19 18:32:53 Done.
342 if (mIconRowView.findViewById(R.id.menu_item_back).isFocused()) {
343 return R.id.back_menu_id;
344 } else if (mIconRowView.findViewById(R.id.menu_item_forward).isFocus ed()) {
345 return R.id.forward_menu_id;
346 } else if (mIconRowView.findViewById(R.id.menu_item_bookmark).isFocu sed()) {
347 return R.id.bookmark_this_page_id;
348 }
349 }
350 int adjustedPosition = mShowIconRow ? position - 1 : position;
351 return mAdapter.getItem(adjustedPosition).getItemId(); 216 return mAdapter.getItem(adjustedPosition).getItemId();
352 } 217 }
353 218
354 /**
355 * Adds click handlers for items in the icon row.
356 * Also disable/enable the view based on the menu item.
357 * We assume that we have Back, Forward and Bookmark-star icons in this view .
358 */
359 private void setIconRowEventHandlers(View iconRowView) {
360 OnKeyListener keyListener = new OnKeyListener() {
361 @Override
362 public boolean onKey(View v, int keyCode, KeyEvent event) {
363 if (isShowing() && v.isFocused()) {
364 if (keyCode == KeyEvent.KEYCODE_MENU) {
365 v.setSelected(false);
366 dismiss();
367 return true;
368 } else if (KeyNavigationUtil.isGoUp(event)) {
369 // Catch attempts to move out of bounds.
370 return true;
371 } else if (KeyNavigationUtil.isGoDown(event)) {
372 // Requesting focus on the mPopup.getListView().getChild At(0) does not work.
373 // Requesting the focus on the ListView focuses the firs t non-header item.
374 mPopup.getListView().requestFocus();
375 return true;
376 }
377 }
378 return false;
379 }
380 };
381
382 MenuItem menuItem = mMenu.findItem(R.id.back_menu_id);
383 setIconRowItemEventHandlers(menuItem, iconRowView.findViewById(R.id.menu _item_back),
384 keyListener, menuItem.isEnabled());
385
386 menuItem = mMenu.findItem(R.id.forward_menu_id);
387 setIconRowItemEventHandlers(menuItem, iconRowView.findViewById(R.id.menu _item_forward),
388 keyListener, menuItem.isEnabled());
389
390 menuItem = mMenu.findItem(R.id.bookmark_this_page_id);
391 setIconRowItemEventHandlers(menuItem, iconRowView.findViewById(R.id.menu _item_bookmark),
392 keyListener, BookmarksBridge.isEditBookmarksEnabled());
393 }
394
395 private void setIconRowItemEventHandlers(final MenuItem menuItem, View iconV iew,
396 OnKeyListener keyListener, boolean enabled) {
397 iconView.setEnabled(enabled);
398 iconView.setFocusable(enabled);
399 iconView.setOnKeyListener(keyListener);
400 iconView.setOnClickListener(new OnClickListener() {
401 @Override
402 public void onClick(View v) {
403 dismiss();
404 mHandler.onOptionsItemSelected(menuItem);
405 }
406 });
407 }
408
409 /**
410 * Requests focus whichever button in icon row is enabled from the left.
411 */
412 private void requestFocusToEnabledIconRowButton() {
413 View backView = mIconRowView.findViewById(R.id.menu_item_back);
414 View forwardView = mIconRowView.findViewById(R.id.menu_item_forward);
415 View bookmarkView = mIconRowView.findViewById(R.id.menu_item_bookmark);
416 if (backView.isFocusable()) {
417 backView.requestFocus();
418 } else if (forwardView.isFocusable()) {
419 forwardView.requestFocus();
420 } else {
421 bookmarkView.requestFocus();
422 }
423 }
424
425 private void setMenuHeight(int numMenuItems, Rect appDimensions) { 219 private void setMenuHeight(int numMenuItems, Rect appDimensions) {
426 assert mPopup.getAnchorView() != null; 220 assert mPopup.getAnchorView() != null;
427 View anchorView = mPopup.getAnchorView(); 221 View anchorView = mPopup.getAnchorView();
428 int[] anchorViewLocation = new int[2]; 222 int[] anchorViewLocation = new int[2];
429 anchorView.getLocationOnScreen(anchorViewLocation); 223 anchorView.getLocationOnScreen(anchorViewLocation);
430 anchorViewLocation[1] -= appDimensions.top; 224 anchorViewLocation[1] -= appDimensions.top;
431 225
432 int availableScreenSpace = Math.max(anchorViewLocation[1], 226 int availableScreenSpace = Math.max(anchorViewLocation[1],
433 appDimensions.height() - anchorViewLocation[1] - anchorView.getH eight()); 227 appDimensions.height() - anchorViewLocation[1] - anchorView.getH eight());
434 228
(...skipping 17 matching lines...) Expand all
452 mPopup.setHeight(spaceForFullItems + spaceForPartialItem + 246 mPopup.setHeight(spaceForFullItems + spaceForPartialItem +
453 padding.top + padding.bottom); 247 padding.top + padding.bottom);
454 } else { 248 } else {
455 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa rtialItem + 249 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa rtialItem +
456 padding.top + padding.bottom); 250 padding.top + padding.bottom);
457 } 251 }
458 } else { 252 } else {
459 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 253 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
460 } 254 }
461 } 255 }
462
463 private ArrayList<FixedViewInfo> populateHeaderViewInfo(Context context, Vie w headerView) {
464 ArrayList<FixedViewInfo> headerInfoList = new ArrayList<FixedViewInfo>() ;
465 ListView lv = new ListView(context);
466 FixedViewInfo viewInfo = lv.new FixedViewInfo();
467 viewInfo.view = headerView;
468 // Make header not selectable, we handle the clicks on our own.
469 viewInfo.isSelectable = false;
470 headerInfoList.add(viewInfo);
471 return headerInfoList;
472 }
473 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698