mobile/android/base/menu/MenuPanel.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial