1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/menu/MenuPanel.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.menu; 1.10 + 1.11 +import org.mozilla.gecko.R; 1.12 + 1.13 +import android.content.Context; 1.14 +import android.os.Build; 1.15 +import android.util.AttributeSet; 1.16 +import android.util.DisplayMetrics; 1.17 +import android.view.ViewGroup; 1.18 +import android.view.accessibility.AccessibilityEvent; 1.19 +import android.widget.LinearLayout; 1.20 + 1.21 +/** 1.22 + * The outer container for the custom menu. On phones with h/w menu button, 1.23 + * this is given to Android which inflates it to the right panel. On phones 1.24 + * with s/w menu button, this is added to a MenuPopup. 1.25 + */ 1.26 +public class MenuPanel extends LinearLayout { 1.27 + public MenuPanel(Context context, AttributeSet attrs) { 1.28 + super(context, attrs); 1.29 + 1.30 + int width = (int) context.getResources().getDimension(R.dimen.menu_item_row_width); 1.31 + setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT)); 1.32 + } 1.33 + 1.34 + @Override 1.35 + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 1.36 + super.onMeasure(widthMeasureSpec, heightMeasureSpec); 1.37 + 1.38 + // Restrict the height to 75% of the screen-height. heightPixels changes during rotation. 1.39 + DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); 1.40 + int restrictedHeightSpec = MeasureSpec.makeMeasureSpec((int) (0.75 * metrics.heightPixels), MeasureSpec.AT_MOST); 1.41 + 1.42 + super.onMeasure(widthMeasureSpec, restrictedHeightSpec); 1.43 + } 1.44 + 1.45 + @Override 1.46 + public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event) { 1.47 + if (Build.VERSION.SDK_INT >= 14) // Build.VERSION_CODES.ICE_CREAM_SANDWICH 1.48 + onPopulateAccessibilityEvent(event); 1.49 + return true; 1.50 + } 1.51 +}