public boolean onPreparePanel(int paramInt, View paramView, Menu paramMenu) { MenuBuilder localMenuBuilder; boolean bool1; if ((paramMenu instanceof MenuBuilder)) { localMenuBuilder = (MenuBuilder)paramMenu; if ((paramInt != 0) || (localMenuBuilder != null)) { break label34; } bool1 = false; } label34: boolean bool2; do { return bool1; localMenuBuilder = null; break; if (localMenuBuilder != null) { localMenuBuilder.setOverrideVisibleItems(true); } bool2 = super.onPreparePanel(paramInt, paramView, paramMenu); bool1 = bool2; } while (localMenuBuilder == null); localMenuBuilder.setOverrideVisibleItems(false); return bool2; }
public void initForMode(final ActionMode mode) { if (mClose == null) { LayoutInflater inflater = LayoutInflater.from(getContext()); 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(getContext()); mActionMenuPresenter.setReserveOverflow(true); final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); menu.addMenuPresenter(mActionMenuPresenter, mPopupContext); mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(null); addView(mMenuView, layoutParams); }
public MenuItemImpl getItem(int position) { ArrayList<MenuItemImpl> items = mOverflowOnly ? mAdapterMenu.getNonActionItems() : mAdapterMenu.getVisibleItems(); if (mExpandedIndex >= 0 && position >= mExpandedIndex) { position++; } return items.get(position); }
public int getCount() { ArrayList<MenuItemImpl> items = mOverflowOnly ? mAdapterMenu.getNonActionItems() : mAdapterMenu.getVisibleItems(); if (mExpandedIndex < 0) { return items.size(); } return items.size() - 1; }
public void inflateMenu(int menu) { MenuInflater menuInflater = new SupportMenuInflater(getContext()); MenuBuilder menuBuilder = new MenuBuilder(getContext()); menuInflater.inflate(menu, menuBuilder); List<Item> items = new ArrayList<>(); for (int i = 0; i < menuBuilder.size(); i++) { MenuItem menuItem = menuBuilder.getItem(i); Item item = new Item(); item.setId(menuItem.getItemId()); item.setIcon(menuItem.getIcon()); item.setTitle(menuItem.getTitle().toString()); items.add(item); } addItems(items); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // If we've been given an exact size to match, apply special formatting during layout. final boolean wasFormatted = mFormatItems; mFormatItems = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; if (wasFormatted != mFormatItems) { mFormatItemsWidth = 0; // Reset this when switching modes } // Special formatting can change whether items can fit as action buttons. // Kick the menu and update presenters when this changes. final int widthSize = MeasureSpec.getSize(widthMeasureSpec); if (mFormatItems && mMenu != null && widthSize != mFormatItemsWidth) { mFormatItemsWidth = widthSize; mMenu.onItemsChanged(true); } final int childCount = getChildCount(); if (mFormatItems && childCount > 0) { onMeasureExactFormat(widthMeasureSpec, heightMeasureSpec); } else { // Previous measurement at exact format may have set margins - reset them. for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); lp.leftMargin = lp.rightMargin = 0; } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
public MenuPopupHelper( Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, int popupStyleAttr, int popupStyleRes, int direction) { mDirection = direction; 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, res.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth)); mAnchorView = anchorView; // Present the menu using our context, not the menu builder's context. menu.addMenuPresenter(this, context); }
/** * 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. * * @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; }
public void onDismiss() { mPopup = null; mMenu.close(); if (mTreeObserver != null) { if (!mTreeObserver.isAlive()) mTreeObserver = mAnchorView.getViewTreeObserver(); mTreeObserver.removeGlobalOnLayoutListener(this); mTreeObserver = null; } }
/** @hide */ @RestrictTo(GROUP_ID) public boolean invokeItem(MenuItemImpl item) { return mMenu.performItemAction(item, 0); }