Search in sources :

Example 1 with MenuPopupHelper

use of android.support.v7.view.menu.MenuPopupHelper in project gh4a by slapperwan.

the class ReactionBar method onClick.

@Override
public void onClick(View view) {
    if (mPopup != null && mPopup.isShowing()) {
        mPopup.dismiss();
        return;
    }
    if (view == mReactButton) {
        if (mAddReactionPopup == null) {
            PopupMenu popup = new PopupMenu(getContext(), mReactButton);
            popup.inflate(R.menu.reaction_menu);
            popup.setOnMenuItemClickListener(mAddReactionClickListener);
            mAddHelper = new AddReactionMenuHelper(getContext(), popup.getMenu(), mCallback, mReferenceItem, mDetailsCache);
            mAddReactionPopup = new MenuPopupHelper(getContext(), (MenuBuilder) popup.getMenu(), mReactButton);
            mAddReactionPopup.setForceShowIcon(true);
        }
        mAddHelper.startLoadingIfNeeded();
        mAddReactionPopup.show();
        return;
    }
    for (int i = 0; i < VIEW_IDS.length; i++) {
        if (view.getId() == VIEW_IDS[i]) {
            if (mPopup == null) {
                mPopup = new ReactionUserPopup(getContext(), mCallback, mReferenceItem, mDetailsCache);
            }
            mPopup.setAnchorView(view);
            mPopup.show(CONTENTS[i]);
        }
    }
}
Also used : MenuPopupHelper(android.support.v7.view.menu.MenuPopupHelper) MenuBuilder(android.support.v7.view.menu.MenuBuilder) PopupMenu(android.support.v7.widget.PopupMenu)

Example 2 with MenuPopupHelper

use of android.support.v7.view.menu.MenuPopupHelper in project Osmand by osmandapp.

the class IconPopupMenu method onOpenSubMenu.

public boolean onOpenSubMenu(MenuBuilder subMenu) {
    if (subMenu == null)
        return false;
    if (!subMenu.hasVisibleItems()) {
        return true;
    }
    // Current menu will be dismissed by the normal helper, submenu will be shown in its place.
    MenuPopupHelper menuPopupHelper = new MenuPopupHelper(mContext, subMenu, mAnchor);
    menuPopupHelper.show();
    return true;
}
Also used : MenuPopupHelper(android.support.v7.view.menu.MenuPopupHelper)

Example 3 with MenuPopupHelper

use of android.support.v7.view.menu.MenuPopupHelper in project floatingsearchview by arimorty.

the class MenuView method reset.

/**
 * Resets the the view to fit into a new
 * available width.
 * <p/>
 * <p>This clears and then re-inflates the menu items
 * , removes all of its associated action views, and re-creates
 * the menu and action items to fit in the new width.</p>
 *
 * @param availWidth the width available for the menu to use. If
 *                   there is room, menu items that are flagged with
 *                   android:showAsAction="ifRoom" or android:showAsAction="always"
 *                   will show as actions.
 */
public void reset(int menu, int availWidth) {
    mMenu = menu;
    if (mMenu == -1) {
        return;
    }
    mActionShowAlwaysItems = new ArrayList<>();
    mActionItems = new ArrayList<>();
    mMenuItems = new ArrayList<>();
    mMenuBuilder = new MenuBuilder(getContext());
    mMenuPopupHelper = new MenuPopupHelper(getContext(), mMenuBuilder, this);
    // clean view and re-inflate
    removeAllViews();
    getMenuInflater().inflate(mMenu, mMenuBuilder);
    mMenuItems = mMenuBuilder.getActionItems();
    mMenuItems.addAll(mMenuBuilder.getNonActionItems());
    Collections.sort(mMenuItems, new Comparator<MenuItemImpl>() {

        @Override
        public int compare(MenuItemImpl lhs, MenuItemImpl rhs) {
            return ((Integer) lhs.getOrder()).compareTo(rhs.getOrder());
        }
    });
    List<MenuItemImpl> localActionItems = filter(mMenuItems, new MenuItemImplPredicate() {

        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.getIcon() != null && (menuItem.requiresActionButton() || menuItem.requestsActionButton());
        }
    });
    int availItemRoom = availWidth / (int) ACTION_DIMENSION_PX;
    // determine if to show overflow menu
    boolean addOverflowAtTheEnd = false;
    if (((localActionItems.size() < mMenuItems.size()) || availItemRoom < localActionItems.size())) {
        addOverflowAtTheEnd = true;
        availItemRoom--;
    }
    ArrayList<Integer> actionItemsIds = new ArrayList<>();
    if (availItemRoom > 0) {
        for (int i = 0; i < localActionItems.size(); i++) {
            final MenuItemImpl menuItem = localActionItems.get(i);
            if (menuItem.getIcon() != null) {
                ImageView action = createActionView();
                action.setContentDescription(menuItem.getTitle());
                action.setImageDrawable(menuItem.getIcon());
                Util.setIconColor(action, mActionIconColor);
                addView(action);
                mActionItems.add(menuItem);
                actionItemsIds.add(menuItem.getItemId());
                action.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (mMenuCallback != null) {
                            mMenuCallback.onMenuItemSelected(mMenuBuilder, menuItem);
                        }
                    }
                });
                availItemRoom--;
                if (availItemRoom == 0) {
                    break;
                }
            }
        }
    }
    mHasOverflow = addOverflowAtTheEnd;
    if (addOverflowAtTheEnd) {
        ImageView overflowAction = getOverflowActionView();
        overflowAction.setImageResource(R.drawable.ic_more_vert_black_24dp);
        Util.setIconColor(overflowAction, mOverflowIconColor);
        addView(overflowAction);
        overflowAction.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mMenuPopupHelper.show();
            }
        });
        mMenuBuilder.setCallback(mMenuCallback);
    }
    // remove all menu items that will be shown as icons (the action items) from the overflow menu
    for (int id : actionItemsIds) {
        mMenuBuilder.removeItem(id);
    }
    actionItemsIds = null;
    if (mOnVisibleWidthChangedListener != null) {
        mVisibleWidth = ((int) ACTION_DIMENSION_PX * getChildCount()) - (mHasOverflow ? Util.dpToPx(8) : 0);
        mOnVisibleWidthChangedListener.onItemsMenuVisibleWidthChanged(mVisibleWidth);
    }
}
Also used : MenuPopupHelper(com.arlib.floatingsearchview.util.MenuPopupHelper) ArrayList(java.util.ArrayList) MenuBuilder(android.support.v7.view.menu.MenuBuilder) ImageView(android.widget.ImageView) View(android.view.View) MenuItemImpl(android.support.v7.view.menu.MenuItemImpl) ImageView(android.widget.ImageView)

Example 4 with MenuPopupHelper

use of android.support.v7.view.menu.MenuPopupHelper in project floatingsearchview by arimorty.

the class MenuView method init.

private void init() {
    mMenuBuilder = new MenuBuilder(getContext());
    mMenuPopupHelper = new MenuPopupHelper(getContext(), mMenuBuilder, this);
    mActionIconColor = Util.getColor(getContext(), R.color.gray_active_icon);
    mOverflowIconColor = Util.getColor(getContext(), R.color.gray_active_icon);
}
Also used : MenuPopupHelper(com.arlib.floatingsearchview.util.MenuPopupHelper) MenuBuilder(android.support.v7.view.menu.MenuBuilder)

Example 5 with MenuPopupHelper

use of android.support.v7.view.menu.MenuPopupHelper in project AisenWeiBo by wangdan.

the class CardMenuPresenter method hideOverflowMenu.

/**
 * Hide the overflow menu if it is currently showing.
 *
 * @return true if the overflow menu was hidden, false otherwise.
 */
public boolean hideOverflowMenu() {
    if (mPostedOpenRunnable != null && mMenuView != null) {
        ((View) mMenuView).removeCallbacks(mPostedOpenRunnable);
        mPostedOpenRunnable = null;
        return true;
    }
    MenuPopupHelper popup = mOverflowPopup;
    if (popup != null) {
        popup.dismiss();
        return true;
    }
    return false;
}
Also used : MenuPopupHelper(android.support.v7.view.menu.MenuPopupHelper) MenuView(android.support.v7.view.menu.MenuView) View(android.view.View)

Aggregations

MenuBuilder (android.support.v7.view.menu.MenuBuilder)3 MenuPopupHelper (android.support.v7.view.menu.MenuPopupHelper)3 View (android.view.View)2 MenuPopupHelper (com.arlib.floatingsearchview.util.MenuPopupHelper)2 MenuItemImpl (android.support.v7.view.menu.MenuItemImpl)1 MenuView (android.support.v7.view.menu.MenuView)1 PopupMenu (android.support.v7.widget.PopupMenu)1 ImageView (android.widget.ImageView)1 ArrayList (java.util.ArrayList)1