michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.menu; michael@0: michael@0: import org.mozilla.gecko.R; michael@0: michael@0: import android.content.Context; michael@0: import android.os.Build; michael@0: import android.util.AttributeSet; michael@0: import android.util.DisplayMetrics; michael@0: import android.view.ViewGroup; michael@0: import android.view.accessibility.AccessibilityEvent; michael@0: import android.widget.LinearLayout; michael@0: michael@0: /** michael@0: * The outer container for the custom menu. On phones with h/w menu button, michael@0: * this is given to Android which inflates it to the right panel. On phones michael@0: * with s/w menu button, this is added to a MenuPopup. michael@0: */ michael@0: public class MenuPanel extends LinearLayout { michael@0: public MenuPanel(Context context, AttributeSet attrs) { michael@0: super(context, attrs); michael@0: michael@0: int width = (int) context.getResources().getDimension(R.dimen.menu_item_row_width); michael@0: setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT)); michael@0: } michael@0: michael@0: @Override michael@0: protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { michael@0: super.onMeasure(widthMeasureSpec, heightMeasureSpec); michael@0: michael@0: // Restrict the height to 75% of the screen-height. heightPixels changes during rotation. michael@0: DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); michael@0: int restrictedHeightSpec = MeasureSpec.makeMeasureSpec((int) (0.75 * metrics.heightPixels), MeasureSpec.AT_MOST); michael@0: michael@0: super.onMeasure(widthMeasureSpec, restrictedHeightSpec); michael@0: } michael@0: michael@0: @Override michael@0: public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event) { michael@0: if (Build.VERSION.SDK_INT >= 14) // Build.VERSION_CODES.ICE_CREAM_SANDWICH michael@0: onPopulateAccessibilityEvent(event); michael@0: return true; michael@0: } michael@0: }