Merge "Add style support to PopupMenu, clean up constructor javadoc" into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8afc90fd71
@@ -38125,6 +38125,7 @@ package android.widget {
|
||||
public class PopupMenu {
|
||||
ctor public PopupMenu(android.content.Context, android.view.View);
|
||||
ctor public PopupMenu(android.content.Context, android.view.View, int);
|
||||
ctor public PopupMenu(android.content.Context, android.view.View, int, int, int);
|
||||
method public void dismiss();
|
||||
method public android.view.View.OnTouchListener getDragToOpenListener();
|
||||
method public android.view.Menu getMenu();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.widget;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.view.menu.MenuBuilder;
|
||||
import com.android.internal.view.menu.MenuPopupHelper;
|
||||
import com.android.internal.view.menu.MenuPresenter;
|
||||
@@ -37,10 +38,11 @@ import android.widget.ListPopupWindow.ForwardingListener;
|
||||
* of the popup will dismiss it.
|
||||
*/
|
||||
public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback {
|
||||
private Context mContext;
|
||||
private MenuBuilder mMenu;
|
||||
private View mAnchor;
|
||||
private MenuPopupHelper mPopup;
|
||||
private final Context mContext;
|
||||
private final MenuBuilder mMenu;
|
||||
private final View mAnchor;
|
||||
private final MenuPopupHelper mPopup;
|
||||
|
||||
private OnMenuItemClickListener mMenuItemClickListener;
|
||||
private OnDismissListener mDismissListener;
|
||||
private OnTouchListener mDragListener;
|
||||
@@ -58,31 +60,56 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new PopupMenu.
|
||||
* Constructor to create a new popup menu with an anchor view.
|
||||
*
|
||||
* @param context Context for the PopupMenu.
|
||||
* @param anchor Anchor view for this popup. The popup will appear below the anchor if there
|
||||
* is room, or above it if there is not.
|
||||
* @param context Context the popup menu is running in, through which it
|
||||
* can access the current theme, resources, etc.
|
||||
* @param anchor Anchor view for this popup. The popup will appear below
|
||||
* the anchor if there is room, or above it if there is not.
|
||||
*/
|
||||
public PopupMenu(Context context, View anchor) {
|
||||
this(context, anchor, Gravity.NO_GRAVITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new PopupMenu.
|
||||
* Constructor to create a new popup menu with an anchor view and alignment
|
||||
* gravity.
|
||||
*
|
||||
* @param context Context for the PopupMenu.
|
||||
* @param anchor Anchor view for this popup. The popup will appear below the anchor if there
|
||||
* is room, or above it if there is not.
|
||||
* @param gravity The {@link Gravity} value for aligning the popup with its anchor
|
||||
* @param context Context the popup menu is running in, through which it
|
||||
* can access the current theme, resources, etc.
|
||||
* @param anchor Anchor view for this popup. The popup will appear below
|
||||
* the anchor if there is room, or above it if there is not.
|
||||
* @param gravity The {@link Gravity} value for aligning the popup with its
|
||||
* anchor.
|
||||
*/
|
||||
public PopupMenu(Context context, View anchor, int gravity) {
|
||||
// TODO Theme?
|
||||
this(context, anchor, gravity, R.attr.popupMenuStyle, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor a create a new popup menu with a specific style.
|
||||
*
|
||||
* @param context Context the popup menu is running in, through which it
|
||||
* can access the current theme, resources, etc.
|
||||
* @param anchor Anchor view for this popup. The popup will appear below
|
||||
* the anchor if there is room, or above it if there is not.
|
||||
* @param gravity The {@link Gravity} value for aligning the popup with its
|
||||
* anchor.
|
||||
* @param popupStyleAttr An attribute in the current theme that contains a
|
||||
* reference to a style resource that supplies default values for
|
||||
* the popup window. Can be 0 to not look for defaults.
|
||||
* @param popupStyleRes A resource identifier of a style resource that
|
||||
* supplies default values for the popup window, used only if
|
||||
* popupStyleAttr is 0 or can not be found in the theme. Can be 0
|
||||
* to not look for defaults.
|
||||
*/
|
||||
public PopupMenu(Context context, View anchor, int gravity, int popupStyleAttr,
|
||||
int popupStyleRes) {
|
||||
mContext = context;
|
||||
mMenu = new MenuBuilder(context);
|
||||
mMenu.setCallback(this);
|
||||
mAnchor = anchor;
|
||||
mPopup = new MenuPopupHelper(context, mMenu, anchor);
|
||||
mPopup = new MenuPopupHelper(context, mMenu, anchor, false, popupStyleAttr, popupStyleRes);
|
||||
mPopup.setGravity(gravity);
|
||||
mPopup.setCallback(this);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
|
||||
private final boolean mOverflowOnly;
|
||||
private final int mPopupMaxWidth;
|
||||
private final int mPopupStyleAttr;
|
||||
private final int mPopupStyleRes;
|
||||
|
||||
private View mAnchorView;
|
||||
private ListPopupWindow mPopup;
|
||||
@@ -73,21 +74,27 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
|
||||
private int mDropDownGravity = Gravity.NO_GRAVITY;
|
||||
|
||||
public MenuPopupHelper(Context context, MenuBuilder menu) {
|
||||
this(context, menu, null, false, com.android.internal.R.attr.popupMenuStyle);
|
||||
this(context, menu, null, false, com.android.internal.R.attr.popupMenuStyle, 0);
|
||||
}
|
||||
|
||||
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView) {
|
||||
this(context, menu, anchorView, false, com.android.internal.R.attr.popupMenuStyle);
|
||||
this(context, menu, anchorView, false, com.android.internal.R.attr.popupMenuStyle, 0);
|
||||
}
|
||||
|
||||
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView,
|
||||
boolean overflowOnly, int popupStyleAttr) {
|
||||
this(context, menu, anchorView, overflowOnly, popupStyleAttr, 0);
|
||||
}
|
||||
|
||||
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView,
|
||||
boolean overflowOnly, int popupStyleAttr, int popupStyleRes) {
|
||||
mContext = context;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mMenu = menu;
|
||||
mAdapter = new MenuAdapter(mMenu);
|
||||
mOverflowOnly = overflowOnly;
|
||||
mPopupStyleAttr = popupStyleAttr;
|
||||
mPopupStyleRes = popupStyleRes;
|
||||
|
||||
final Resources res = context.getResources();
|
||||
mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2,
|
||||
@@ -122,7 +129,7 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
|
||||
}
|
||||
|
||||
public boolean tryShow() {
|
||||
mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr);
|
||||
mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
|
||||
mPopup.setOnDismissListener(this);
|
||||
mPopup.setOnItemClickListener(this);
|
||||
mPopup.setAdapter(mAdapter);
|
||||
|
||||
Reference in New Issue
Block a user