use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by AOSPA.
the class ActionMenuView method getMenu.
/**
* Returns the Menu object that this ActionMenuView is currently presenting.
*
* <p>Applications should use this method to obtain the ActionMenuView's Menu object
* and inflate or add content to it as necessary.</p>
*
* @return the Menu presented by this view
*/
public Menu getMenu() {
if (mMenu == null) {
final Context context = getContext();
mMenu = new MenuBuilder(context);
mMenu.setCallback(new MenuBuilderCallback());
mPresenter = new ActionMenuPresenter(context);
mPresenter.setReserveOverflow(true);
mPresenter.setCallback(mActionMenuPresenterCallback != null ? mActionMenuPresenterCallback : new ActionMenuPresenterCallback());
mMenu.addMenuPresenter(mPresenter, mPopupContext);
mPresenter.setMenuView(this);
}
return mMenu;
}
use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by AOSPA.
the class Toolbar method getCurrentContentInsetEnd.
/**
* Gets the content inset that will be used on the ending side of the bar in the current
* toolbar configuration.
*
* @return the current content inset end in pixels
*
* @see #getContentInsetEndWithActions()
*/
public int getCurrentContentInsetEnd() {
boolean hasActions = false;
if (mMenuView != null) {
final MenuBuilder mb = mMenuView.peekMenu();
hasActions = mb != null && mb.hasVisibleItems();
}
return hasActions ? Math.max(getContentInsetEnd(), Math.max(mContentInsetEndWithActions, 0)) : getContentInsetEnd();
}
use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by AOSPA.
the class Toolbar method setMenu.
/** @hide */
public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) {
if (menu == null && mMenuView == null) {
return;
}
ensureMenuView();
final MenuBuilder oldMenu = mMenuView.peekMenu();
if (oldMenu == menu) {
return;
}
if (oldMenu != null) {
oldMenu.removeMenuPresenter(mOuterActionMenuPresenter);
oldMenu.removeMenuPresenter(mExpandedMenuPresenter);
}
if (mExpandedMenuPresenter == null) {
mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
}
outerPresenter.setExpandedActionViewsExclusive(true);
if (menu != null) {
menu.addMenuPresenter(outerPresenter, mPopupContext);
menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
} else {
outerPresenter.initForMenu(mPopupContext, null);
mExpandedMenuPresenter.initForMenu(mPopupContext, null);
outerPresenter.updateMenuView(true);
mExpandedMenuPresenter.updateMenuView(true);
}
mMenuView.setPopupTheme(mPopupTheme);
mMenuView.setPresenter(outerPresenter);
mOuterActionMenuPresenter = outerPresenter;
}
use of com.android.internal.view.menu.MenuBuilder in project platform_frameworks_base by android.
the class FrameworkActionBar method createMenuPopup.
/**
* Creates a Popup and adds it to the content frame. It also adds another {@link FrameLayout} to
* the content frame which shall serve as the new content root.
*/
@Override
public void createMenuPopup() {
if (!isOverflowPopupNeeded()) {
return;
}
DisplayMetrics metrics = mBridgeContext.getMetrics();
MenuBuilder menu = mActionBar.getMenuBuilder();
OverflowMenuAdapter adapter = new OverflowMenuAdapter(menu, mActionBar.getPopupContext());
ListView listView = new ListView(mActionBar.getPopupContext(), null, R.attr.dropDownListViewStyle);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(measureContentWidth(adapter), LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
if (mActionBar.isSplit()) {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.bottomMargin = getActionBarHeight() + mActionBar.getMenuPopupMargin();
} else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.topMargin = getActionBarHeight() + mActionBar.getMenuPopupMargin();
}
layoutParams.setMarginEnd(getPixelValue("5dp", metrics));
listView.setLayoutParams(layoutParams);
listView.setAdapter(adapter);
final TypedArray a = mActionBar.getPopupContext().obtainStyledAttributes(null, R.styleable.PopupWindow, R.attr.popupMenuStyle, 0);
listView.setBackground(a.getDrawable(R.styleable.PopupWindow_popupBackground));
listView.setDivider(a.getDrawable(R.attr.actionBarDivider));
a.recycle();
listView.setElevation(mActionBar.getMenuPopupElevation());
assert mEnclosingLayout != null : "Unable to find view to attach ActionMenuPopup.";
mEnclosingLayout.addView(listView);
}
use of com.android.internal.view.menu.MenuBuilder in project platform_frameworks_base by android.
the class FrameworkActionBarWrapper method inflateMenus.
/**
* Gets the menus to add to the action bar from the callback, resolves them, inflates them and
* adds them to the action bar.
*/
protected void inflateMenus() {
MenuInflater inflater = new MenuInflater(getActionMenuContext());
MenuBuilder menuBuilder = getMenuBuilder();
for (String name : mCallback.getMenuIdNames()) {
int id;
if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
// Framework menu.
name = name.substring(ANDROID_NS_NAME_PREFIX.length());
id = mContext.getFrameworkResourceValue(MENU, name, -1);
} else {
// Project menu.
id = mContext.getProjectResourceValue(MENU, name, -1);
}
if (id > -1) {
inflater.inflate(id, menuBuilder);
}
}
}
Aggregations