1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/menu/MenuPopup.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 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.graphics.Color; 1.15 +import android.graphics.drawable.ColorDrawable; 1.16 +import android.view.LayoutInflater; 1.17 +import android.view.View; 1.18 +import android.view.ViewGroup; 1.19 +import android.widget.LinearLayout; 1.20 +import android.widget.PopupWindow; 1.21 + 1.22 +/** 1.23 + * A popup to show the inflated MenuPanel. 1.24 + */ 1.25 +public class MenuPopup extends PopupWindow { 1.26 + private LinearLayout mPanel; 1.27 + 1.28 + private int mYOffset; 1.29 + private int mPopupWidth; 1.30 + 1.31 + public MenuPopup(Context context) { 1.32 + super(context); 1.33 + 1.34 + setFocusable(true); 1.35 + 1.36 + mYOffset = context.getResources().getDimensionPixelSize(R.dimen.menu_popup_offset); 1.37 + mPopupWidth = context.getResources().getDimensionPixelSize(R.dimen.menu_popup_width); 1.38 + 1.39 + // Setting a null background makes the popup to not close on touching outside. 1.40 + setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 1.41 + setWindowLayoutMode(View.MeasureSpec.makeMeasureSpec(mPopupWidth, View.MeasureSpec.AT_MOST), 1.42 + ViewGroup.LayoutParams.WRAP_CONTENT); 1.43 + 1.44 + LayoutInflater inflater = LayoutInflater.from(context); 1.45 + mPanel = (LinearLayout) inflater.inflate(R.layout.menu_popup, null); 1.46 + setContentView(mPanel); 1.47 + 1.48 + setAnimationStyle(R.style.PopupAnimation); 1.49 + } 1.50 + 1.51 + /** 1.52 + * Adds the panel with the menu to its content. 1.53 + * 1.54 + * @param view The panel view with the menu to be shown. 1.55 + */ 1.56 + public void setPanelView(View view) { 1.57 + view.setLayoutParams(new LinearLayout.LayoutParams(mPopupWidth, 1.58 + LinearLayout.LayoutParams.WRAP_CONTENT)); 1.59 + 1.60 + mPanel.removeAllViews(); 1.61 + mPanel.addView(view); 1.62 + } 1.63 + 1.64 + /** 1.65 + * A small little offset. 1.66 + */ 1.67 + @Override 1.68 + public void showAsDropDown(View anchor) { 1.69 + showAsDropDown(anchor, 0, -mYOffset); 1.70 + } 1.71 +}