use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by crdroidandroid.
the class Toolbar method ensureMenu.
private void ensureMenu() {
ensureMenuView();
if (mMenuView.peekMenu() == null) {
// Initialize a new menu for the first time.
final MenuBuilder menu = (MenuBuilder) mMenuView.getMenu();
if (mExpandedMenuPresenter == null) {
mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
}
mMenuView.setExpandedActionViewsExclusive(true);
menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
}
}
use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by crdroidandroid.
the class PhoneWindow method initializePanelMenu.
/**
* Initializes the menu associated with the given panel feature state. You
* must at the very least set PanelFeatureState.menu to the Menu to be
* associated with the given panel state. The default implementation creates
* a new menu for the panel state.
*
* @param st The panel whose menu is being initialized.
* @return Whether the initialization was successful.
*/
protected boolean initializePanelMenu(final PanelFeatureState st) {
Context context = getContext();
// If we have an action bar, initialize the menu with the right theme.
if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR) && mDecorContentParent != null) {
final TypedValue outValue = new TypedValue();
final Theme baseTheme = context.getTheme();
baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
Theme widgetTheme = null;
if (outValue.resourceId != 0) {
widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(baseTheme);
widgetTheme.applyStyle(outValue.resourceId, true);
widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
} else {
baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
}
if (outValue.resourceId != 0) {
if (widgetTheme == null) {
widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(baseTheme);
}
widgetTheme.applyStyle(outValue.resourceId, true);
}
if (widgetTheme != null) {
context = new ContextThemeWrapper(context, 0);
context.getTheme().setTo(widgetTheme);
}
}
final MenuBuilder menu = new MenuBuilder(context);
menu.setCallback(this);
st.setMenu(menu);
return true;
}
use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by crdroidandroid.
the class ActionBarContextView method initForMode.
public void initForMode(final ActionMode mode) {
if (mClose == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
mClose = inflater.inflate(mCloseItemLayout, this, false);
addView(mClose);
} else if (mClose.getParent() == null) {
addView(mClose);
}
View closeButton = mClose.findViewById(R.id.action_mode_close_button);
closeButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mode.finish();
}
});
final MenuBuilder menu = (MenuBuilder) mode.getMenu();
if (mActionMenuPresenter != null) {
mActionMenuPresenter.dismissPopupMenus();
}
mActionMenuPresenter = new ActionMenuPresenter(mContext);
mActionMenuPresenter.setReserveOverflow(true);
final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
if (!mSplitActionBar) {
menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackground(null);
addView(mMenuView, layoutParams);
} else {
// Allow full screen width in split mode.
mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
// No limit to the item count; use whatever will fit.
mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
// Span the whole width
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = mContentHeight;
menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(mSplitBackground);
mSplitView.addView(mMenuView, layoutParams);
}
}
use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by crdroidandroid.
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 android_frameworks_base by crdroidandroid.
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