|
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 package org.mozilla.gecko.menu; |
|
7 |
|
8 import org.mozilla.gecko.R; |
|
9 |
|
10 import android.content.Context; |
|
11 import android.os.Build; |
|
12 import android.util.AttributeSet; |
|
13 import android.util.DisplayMetrics; |
|
14 import android.view.ViewGroup; |
|
15 import android.view.accessibility.AccessibilityEvent; |
|
16 import android.widget.LinearLayout; |
|
17 |
|
18 /** |
|
19 * The outer container for the custom menu. On phones with h/w menu button, |
|
20 * this is given to Android which inflates it to the right panel. On phones |
|
21 * with s/w menu button, this is added to a MenuPopup. |
|
22 */ |
|
23 public class MenuPanel extends LinearLayout { |
|
24 public MenuPanel(Context context, AttributeSet attrs) { |
|
25 super(context, attrs); |
|
26 |
|
27 int width = (int) context.getResources().getDimension(R.dimen.menu_item_row_width); |
|
28 setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT)); |
|
29 } |
|
30 |
|
31 @Override |
|
32 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|
33 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
|
34 |
|
35 // Restrict the height to 75% of the screen-height. heightPixels changes during rotation. |
|
36 DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); |
|
37 int restrictedHeightSpec = MeasureSpec.makeMeasureSpec((int) (0.75 * metrics.heightPixels), MeasureSpec.AT_MOST); |
|
38 |
|
39 super.onMeasure(widthMeasureSpec, restrictedHeightSpec); |
|
40 } |
|
41 |
|
42 @Override |
|
43 public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event) { |
|
44 if (Build.VERSION.SDK_INT >= 14) // Build.VERSION_CODES.ICE_CREAM_SANDWICH |
|
45 onPopulateAccessibilityEvent(event); |
|
46 return true; |
|
47 } |
|
48 } |