Bug 818229: Support a GeckoPopupMenu for the custom menu. [r=mfinkle]
--HG-- rename : mobile/android/base/resources/drawable-hdpi-v11/menu.png => mobile/android/base/resources/drawable-hdpi/menu.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_item_check.png => mobile/android/base/resources/drawable-hdpi/menu_item_check.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_item_more.png => mobile/android/base/resources/drawable-hdpi/menu_item_more.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_item_uncheck.png => mobile/android/base/resources/drawable-hdpi/menu_item_uncheck.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_panel_bg.9.png => mobile/android/base/resources/drawable-hdpi/menu_panel_bg.9.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_pb.png => mobile/android/base/resources/drawable-hdpi/menu_pb.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_popup_arrow.png => mobile/android/base/resources/drawable-hdpi/menu_popup_arrow.png rename : mobile/android/base/resources/drawable-hdpi-v11/menu_popup_bg.9.png => mobile/android/base/resources/drawable-hdpi/menu_popup_bg.9.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu.png => mobile/android/base/resources/drawable-xhdpi/menu.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_item_check.png => mobile/android/base/resources/drawable-xhdpi/menu_item_check.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_item_more.png => mobile/android/base/resources/drawable-xhdpi/menu_item_more.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_item_uncheck.png => mobile/android/base/resources/drawable-xhdpi/menu_item_uncheck.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_panel_bg.9.png => mobile/android/base/resources/drawable-xhdpi/menu_panel_bg.9.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_pb.png => mobile/android/base/resources/drawable-xhdpi/menu_pb.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_popup_arrow.png => mobile/android/base/resources/drawable-xhdpi/menu_popup_arrow.png rename : mobile/android/base/resources/drawable-xhdpi-v11/menu_popup_bg.9.png => mobile/android/base/resources/drawable-xhdpi/menu_popup_bg.9.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu.png => mobile/android/base/resources/drawable/menu.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_item_check.png => mobile/android/base/resources/drawable/menu_item_check.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_item_more.png => mobile/android/base/resources/drawable/menu_item_more.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_item_uncheck.png => mobile/android/base/resources/drawable/menu_item_uncheck.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_panel_bg.9.png => mobile/android/base/resources/drawable/menu_panel_bg.9.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_pb.png => mobile/android/base/resources/drawable/menu_pb.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_popup_arrow.png => mobile/android/base/resources/drawable/menu_popup_arrow.png rename : mobile/android/base/resources/drawable-mdpi-v11/menu_popup_bg.9.png => mobile/android/base/resources/drawable/menu_popup_bg.9.png extra : rebase_source : ffd0e90fd625b66b999bdf655d3848144e062e05
159
mobile/android/base/GeckoPopupMenu.java
Normal file
@ -0,0 +1,159 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* A PopupMenu that uses the custom GeckoMenu. This menu is
|
||||
* usually tied to an anchor, and show as a dropdrown from the anchor.
|
||||
*/
|
||||
public class GeckoPopupMenu implements GeckoMenu.Callback,
|
||||
GeckoMenu.MenuPresenter {
|
||||
|
||||
// An interface for listeners for dismissal.
|
||||
public static interface OnDismissListener {
|
||||
public boolean onDismiss(GeckoMenu menu);
|
||||
}
|
||||
|
||||
// An interface for listeners for menu item click events.
|
||||
public static interface OnMenuItemClickListener {
|
||||
public boolean onMenuItemClick(MenuItem item);
|
||||
}
|
||||
|
||||
private View mAnchor;
|
||||
|
||||
private MenuPopup mMenuPopup;
|
||||
private MenuPanel mMenuPanel;
|
||||
|
||||
private GeckoMenu mMenu;
|
||||
private GeckoMenuInflater mMenuInflater;
|
||||
|
||||
private OnDismissListener mDismissListener;
|
||||
private OnMenuItemClickListener mClickListener;
|
||||
|
||||
public GeckoPopupMenu(Context context) {
|
||||
initialize(context, null);
|
||||
}
|
||||
|
||||
public GeckoPopupMenu(Context context, View anchor) {
|
||||
initialize(context, anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates an empty menu and attaches the necessary listeners.
|
||||
* If an anchor is supplied, it is stored as well.
|
||||
*/
|
||||
private void initialize(Context context, View anchor) {
|
||||
mMenu = new GeckoMenu(context, null);
|
||||
mMenu.setCallback(this);
|
||||
mMenu.setMenuPresenter(this);
|
||||
mMenuInflater = new GeckoMenuInflater(context);
|
||||
|
||||
mMenuPopup = new MenuPopup(context);
|
||||
mMenuPanel = new MenuPanel(context, null);
|
||||
|
||||
setAnchor(anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the menu that is current being shown.
|
||||
*
|
||||
* @return The menu being shown.
|
||||
*/
|
||||
public Menu getMenu() {
|
||||
return mMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the menu inflater that was used to create the menu.
|
||||
*
|
||||
* @return The menu inflater used.
|
||||
*/
|
||||
public MenuInflater getMenuInflater() {
|
||||
return mMenuInflater;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inflates a menu resource to the menu using the menu inflater.
|
||||
*
|
||||
* @param menuRes The menu resource to be inflated.
|
||||
*/
|
||||
public void inflate(int menuRes) {
|
||||
mMenuInflater.inflate(menuRes, mMenu);
|
||||
|
||||
mMenuPanel.addView(mMenu);
|
||||
mMenuPopup.setPanelView(mMenuPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a different anchor after the menu is inflated.
|
||||
*
|
||||
* @param anchor The new anchor for the popup.
|
||||
*/
|
||||
public void setAnchor(View anchor) {
|
||||
mAnchor = anchor;
|
||||
}
|
||||
|
||||
public void setOnDismissListener(OnDismissListener listener) {
|
||||
mDismissListener = listener;
|
||||
}
|
||||
|
||||
public void setOnMenuItemClickListener(OnMenuItemClickListener listener) {
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the inflated menu.
|
||||
*/
|
||||
public void show() {
|
||||
if (!mMenuPopup.isShowing())
|
||||
mMenuPopup.showAsDropDown(mAnchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the inflated menu.
|
||||
*/
|
||||
public void dismiss() {
|
||||
if (mMenuPopup.isShowing()) {
|
||||
mMenuPopup.dismiss();
|
||||
|
||||
if (mDismissListener != null)
|
||||
mDismissListener.onDismiss(mMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(MenuItem item) {
|
||||
if (mClickListener != null)
|
||||
return mClickListener.onMenuItemClick(item);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openMenu() {
|
||||
show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMenu(View menu) {
|
||||
mMenuPanel.removeAllViews();
|
||||
mMenuPanel.addView(menu);
|
||||
|
||||
openMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeMenu() {
|
||||
dismiss();
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@ FENNEC_JAVA_FILES = \
|
||||
GeckoSubMenu.java \
|
||||
GeckoPreferences.java \
|
||||
GeckoProfile.java \
|
||||
GeckoPopupMenu.java \
|
||||
GeckoThread.java \
|
||||
GlobalHistory.java \
|
||||
GeckoViewsFactory.java \
|
||||
@ -559,7 +560,14 @@ RES_DRAWABLE_BASE = \
|
||||
res/drawable/find_prev.png \
|
||||
res/drawable/larry_blue.png \
|
||||
res/drawable/larry_green.png \
|
||||
res/drawable/menu.xml \
|
||||
res/drawable/menu.png \
|
||||
res/drawable/menu_pb.png \
|
||||
res/drawable/menu_panel_bg.9.png \
|
||||
res/drawable/menu_popup_bg.9.png \
|
||||
res/drawable/menu_popup_arrow.png \
|
||||
res/drawable/menu_item_check.png \
|
||||
res/drawable/menu_item_more.png \
|
||||
res/drawable/menu_item_uncheck.png \
|
||||
res/drawable/site_security_identified.png \
|
||||
res/drawable/site_security_verified.png \
|
||||
res/drawable/urlbar_stop.png \
|
||||
@ -636,6 +644,14 @@ RES_DRAWABLE_HDPI = \
|
||||
res/drawable-hdpi/find_prev.png \
|
||||
res/drawable-hdpi/larry_blue.png \
|
||||
res/drawable-hdpi/larry_green.png \
|
||||
res/drawable-hdpi/menu.png \
|
||||
res/drawable-hdpi/menu_pb.png \
|
||||
res/drawable-hdpi/menu_panel_bg.9.png \
|
||||
res/drawable-hdpi/menu_popup_bg.9.png \
|
||||
res/drawable-hdpi/menu_popup_arrow.png \
|
||||
res/drawable-hdpi/menu_item_check.png \
|
||||
res/drawable-hdpi/menu_item_more.png \
|
||||
res/drawable-hdpi/menu_item_uncheck.png \
|
||||
res/drawable-hdpi/site_security_identified.png \
|
||||
res/drawable-hdpi/site_security_verified.png \
|
||||
res/drawable-hdpi/urlbar_stop.png \
|
||||
@ -705,6 +721,14 @@ RES_DRAWABLE_XHDPI = \
|
||||
res/drawable-xhdpi/reading_list.png \
|
||||
res/drawable-xhdpi/larry_blue.png \
|
||||
res/drawable-xhdpi/larry_green.png \
|
||||
res/drawable-xhdpi/menu.png \
|
||||
res/drawable-xhdpi/menu_pb.png \
|
||||
res/drawable-xhdpi/menu_panel_bg.9.png \
|
||||
res/drawable-xhdpi/menu_popup_bg.9.png \
|
||||
res/drawable-xhdpi/menu_popup_arrow.png \
|
||||
res/drawable-xhdpi/menu_item_check.png \
|
||||
res/drawable-xhdpi/menu_item_more.png \
|
||||
res/drawable-xhdpi/menu_item_uncheck.png \
|
||||
res/drawable-xhdpi/remote_tabs_off.png \
|
||||
res/drawable-xhdpi/remote_tabs_on.png \
|
||||
res/drawable-xhdpi/site_security_identified.png \
|
||||
@ -742,14 +766,6 @@ RES_DRAWABLE_MDPI_V11 = \
|
||||
res/drawable-mdpi-v11/ic_menu_tools.png \
|
||||
res/drawable-mdpi-v11/ic_menu_quit.png \
|
||||
res/drawable-mdpi-v11/ic_status_logo.png \
|
||||
res/drawable-mdpi-v11/menu.png \
|
||||
res/drawable-mdpi-v11/menu_pb.png \
|
||||
res/drawable-mdpi-v11/menu_panel_bg.9.png \
|
||||
res/drawable-mdpi-v11/menu_popup_bg.9.png \
|
||||
res/drawable-mdpi-v11/menu_popup_arrow.png \
|
||||
res/drawable-mdpi-v11/menu_item_check.png \
|
||||
res/drawable-mdpi-v11/menu_item_more.png \
|
||||
res/drawable-mdpi-v11/menu_item_uncheck.png \
|
||||
$(NULL)
|
||||
|
||||
RES_DRAWABLE_HDPI_V11 = \
|
||||
@ -777,14 +793,6 @@ RES_DRAWABLE_HDPI_V11 = \
|
||||
res/drawable-hdpi-v11/ic_menu_tools.png \
|
||||
res/drawable-hdpi-v11/ic_menu_quit.png \
|
||||
res/drawable-hdpi-v11/ic_status_logo.png \
|
||||
res/drawable-hdpi-v11/menu.png \
|
||||
res/drawable-hdpi-v11/menu_pb.png \
|
||||
res/drawable-hdpi-v11/menu_panel_bg.9.png \
|
||||
res/drawable-hdpi-v11/menu_popup_bg.9.png \
|
||||
res/drawable-hdpi-v11/menu_popup_arrow.png \
|
||||
res/drawable-hdpi-v11/menu_item_check.png \
|
||||
res/drawable-hdpi-v11/menu_item_more.png \
|
||||
res/drawable-hdpi-v11/menu_item_uncheck.png \
|
||||
$(NULL)
|
||||
|
||||
RES_DRAWABLE_XHDPI_V11 = \
|
||||
@ -812,14 +820,6 @@ RES_DRAWABLE_XHDPI_V11 = \
|
||||
res/drawable-xhdpi-v11/ic_menu_tools.png \
|
||||
res/drawable-xhdpi-v11/ic_menu_quit.png \
|
||||
res/drawable-xhdpi-v11/ic_status_logo.png \
|
||||
res/drawable-xhdpi-v11/menu.png \
|
||||
res/drawable-xhdpi-v11/menu_pb.png \
|
||||
res/drawable-xhdpi-v11/menu_panel_bg.9.png \
|
||||
res/drawable-xhdpi-v11/menu_popup_bg.9.png \
|
||||
res/drawable-xhdpi-v11/menu_popup_arrow.png \
|
||||
res/drawable-xhdpi-v11/menu_item_check.png \
|
||||
res/drawable-xhdpi-v11/menu_item_more.png \
|
||||
res/drawable-xhdpi-v11/menu_item_uncheck.png \
|
||||
$(NULL)
|
||||
|
||||
RES_DRAWABLE_LAND_V14 = \
|
||||
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 855 B After Width: | Height: | Size: 855 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 984 B After Width: | Height: | Size: 984 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 606 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 658 B After Width: | Height: | Size: 658 B |