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

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

mercurial