mobile/android/base/menu/MenuPopup.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 package org.mozilla.gecko.menu;
     8 import org.mozilla.gecko.R;
    10 import android.content.Context;
    11 import android.graphics.Color;
    12 import android.graphics.drawable.ColorDrawable;
    13 import android.view.LayoutInflater;
    14 import android.view.View;
    15 import android.view.ViewGroup;
    16 import android.widget.LinearLayout;
    17 import android.widget.PopupWindow;
    19 /**
    20  * A popup to show the inflated MenuPanel.
    21  */
    22 public class MenuPopup extends PopupWindow {
    23     private LinearLayout mPanel;
    25     private int mYOffset;
    26     private int mPopupWidth;
    28     public MenuPopup(Context context) {
    29         super(context);
    31         setFocusable(true);
    33         mYOffset = context.getResources().getDimensionPixelSize(R.dimen.menu_popup_offset);
    34         mPopupWidth = context.getResources().getDimensionPixelSize(R.dimen.menu_popup_width);
    36         // Setting a null background makes the popup to not close on touching outside.
    37         setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    38         setWindowLayoutMode(View.MeasureSpec.makeMeasureSpec(mPopupWidth, View.MeasureSpec.AT_MOST),
    39                             ViewGroup.LayoutParams.WRAP_CONTENT);
    41         LayoutInflater inflater = LayoutInflater.from(context);
    42         mPanel = (LinearLayout) inflater.inflate(R.layout.menu_popup, null);
    43         setContentView(mPanel);
    45         setAnimationStyle(R.style.PopupAnimation);
    46     }
    48     /**
    49      * Adds the panel with the menu to its content.
    50      *
    51      * @param view The panel view with the menu to be shown.
    52      */
    53     public void setPanelView(View view) {
    54         view.setLayoutParams(new LinearLayout.LayoutParams(mPopupWidth,
    55                                                            LinearLayout.LayoutParams.WRAP_CONTENT));
    57         mPanel.removeAllViews();
    58         mPanel.addView(view);
    59     }
    61     /**
    62      * A small little offset.
    63      */
    64     @Override
    65     public void showAsDropDown(View anchor) {
    66         showAsDropDown(anchor, 0, -mYOffset);
    67     }
    68 }

mercurial