Search in sources :

Example 1 with MenuItemImpl

use of android.support.v7.view.menu.MenuItemImpl in project material-components-android by material-components.

the class NavigationMenu method addSubMenu.

@Override
public SubMenu addSubMenu(int group, int id, int categoryOrder, CharSequence title) {
    final MenuItemImpl item = (MenuItemImpl) addInternal(group, id, categoryOrder, title);
    final SubMenuBuilder subMenu = new NavigationSubMenu(getContext(), this, item);
    item.setSubMenu(subMenu);
    return subMenu;
}
Also used : SubMenuBuilder(android.support.v7.view.menu.SubMenuBuilder) MenuItemImpl(android.support.v7.view.menu.MenuItemImpl)

Example 2 with MenuItemImpl

use of android.support.v7.view.menu.MenuItemImpl in project iosched by google.

the class NavigationMenu method addSubMenu.

@Override
public SubMenu addSubMenu(int group, int id, int categoryOrder, CharSequence title) {
    final MenuItemImpl item = (MenuItemImpl) addInternal(group, id, categoryOrder, title);
    final SubMenuBuilder subMenu = new NavigationSubMenu(getContext(), this, item);
    item.setSubMenu(subMenu);
    return subMenu;
}
Also used : SubMenuBuilder(android.support.v7.view.menu.SubMenuBuilder) MenuItemImpl(android.support.v7.view.menu.MenuItemImpl)

Example 3 with MenuItemImpl

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

the class MenuView method hideIfRoomItems.

/**
 * Hides all the menu items flagged with "ifRoom"
 *
 * @param withAnim
 */
public void hideIfRoomItems(boolean withAnim) {
    if (mMenu == -1) {
        return;
    }
    mActionShowAlwaysItems.clear();
    cancelChildAnimListAndClear();
    List<MenuItemImpl> showAlwaysActionItems = filter(mMenuItems, new MenuItemImplPredicate() {

        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.getIcon() != null && menuItem.requiresActionButton();
        }
    });
    int actionItemIndex;
    for (actionItemIndex = 0; actionItemIndex < mActionItems.size() && actionItemIndex < showAlwaysActionItems.size(); actionItemIndex++) {
        final MenuItemImpl showAlwaysActionItem = showAlwaysActionItems.get(actionItemIndex);
        // reset action item image if needed
        if (mActionItems.get(actionItemIndex).getItemId() != showAlwaysActionItem.getItemId()) {
            ImageView action = (ImageView) getChildAt(actionItemIndex);
            action.setImageDrawable(showAlwaysActionItem.getIcon());
            Util.setIconColor(action, mOverflowIconColor);
            action.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (mMenuCallback != null) {
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, showAlwaysActionItem);
                    }
                }
            });
        }
        mActionShowAlwaysItems.add(showAlwaysActionItem);
    }
    final int diff = mActionItems.size() - actionItemIndex + (mHasOverflow ? 1 : 0);
    anims = new ArrayList<>();
    // add anims for moving showAlwaysItem views to the right
    for (int i = 0; i < actionItemIndex; i++) {
        final View currentChild = getChildAt(i);
        final float destTransX = (ACTION_DIMENSION_PX * diff) - (mHasOverflow ? Util.dpToPx(8) : 0);
        anims.add(ViewPropertyObjectAnimator.animate(currentChild).setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0).setInterpolator(new AccelerateInterpolator()).addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                currentChild.setTranslationX(destTransX);
            }
        }).translationXBy(destTransX).get());
    }
    // add anims for moving to right and/or zooming out previously shown items
    for (int i = actionItemIndex; i < (diff + actionItemIndex); i++) {
        final View currentView = getChildAt(i);
        currentView.setClickable(false);
        // move to right
        if (i != (getChildCount() - 1)) {
            anims.add(ViewPropertyObjectAnimator.animate(currentView).setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0).addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    currentView.setTranslationX(ACTION_DIMENSION_PX);
                }
            }).translationXBy(ACTION_DIMENSION_PX).get());
        }
        // scale and zoom out
        anims.add(ViewPropertyObjectAnimator.animate(currentView).setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0).addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                currentView.setScaleX(0.5f);
            }
        }).scaleX(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0).addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                currentView.setScaleY(0.5f);
            }
        }).scaleY(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0).addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                currentView.setAlpha(0.0f);
            }
        }).alpha(0.0f).get());
    }
    final int actionItemsCount = actionItemIndex;
    // finally, run animation
    if (!anims.isEmpty()) {
        AnimatorSet animSet = new AnimatorSet();
        if (!withAnim) {
            // temporary, from laziness
            animSet.setDuration(0);
        }
        animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
        animSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                if (mOnVisibleWidthChangedListener != null) {
                    mVisibleWidth = ((int) ACTION_DIMENSION_PX * actionItemsCount);
                    mOnVisibleWidthChangedListener.onItemsMenuVisibleWidthChanged(mVisibleWidth);
                }
            }
        });
        animSet.start();
    }
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) ViewPropertyObjectAnimator(com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView) View(android.view.View) MenuItemImpl(android.support.v7.view.menu.MenuItemImpl) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ViewPropertyObjectAnimator(com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView)

Example 4 with MenuItemImpl

use of android.support.v7.view.menu.MenuItemImpl in project material-components-android by material-components.

the class TestUtilsMatchers method isActionViewOf.

/**
   * Returns a matcher that matches the action view of the specified menu item.
   *
   * @param menu The menu
   * @param id The ID of the menu item
   */
public static Matcher<View> isActionViewOf(@NonNull final Menu menu, @IdRes final int id) {
    return new TypeSafeMatcher<View>() {

        private Resources resources;

        @Override
        protected boolean matchesSafely(View view) {
            resources = view.getResources();
            MenuItemImpl item = (MenuItemImpl) menu.findItem(id);
            return item != null && item.getActionView() == view;
        }

        @Override
        public void describeTo(Description description) {
            String name;
            if (resources != null) {
                name = resources.getResourceName(id);
            } else {
                name = Integer.toString(id);
            }
            description.appendText("is action view of menu item " + name);
        }
    };
}
Also used : MenuItemImpl(android.support.v7.view.menu.MenuItemImpl) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 5 with MenuItemImpl

use of android.support.v7.view.menu.MenuItemImpl in project material-components-android by material-components.

the class BottomNavigationMenu method addInternal.

@Override
protected MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) {
    if (size() + 1 > MAX_ITEM_COUNT) {
        throw new IllegalArgumentException("Maximum number of items supported by BottomNavigationView is " + MAX_ITEM_COUNT + ". Limit can be checked with BottomNavigationView#getMaxItemCount()");
    }
    stopDispatchingItemsChanged();
    final MenuItem item = super.addInternal(group, id, categoryOrder, title);
    if (item instanceof MenuItemImpl) {
        ((MenuItemImpl) item).setExclusiveCheckable(true);
    }
    startDispatchingItemsChanged();
    return item;
}
Also used : MenuItemImpl(android.support.v7.view.menu.MenuItemImpl) MenuItem(android.view.MenuItem)

Aggregations

MenuItemImpl (android.support.v7.view.menu.MenuItemImpl)7 View (android.view.View)5 ImageView (android.widget.ImageView)3 ActionMenuChildView (android.support.v7.internal.view.menu.ActionMenuView.ActionMenuChildView)2 SubMenuBuilder (android.support.v7.view.menu.SubMenuBuilder)2 MenuItem (android.view.MenuItem)2 ViewGroup (android.view.ViewGroup)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 Resources (android.content.res.Resources)1 MenuBuilder (android.support.v7.view.menu.MenuBuilder)1 SparseBooleanArray (android.util.SparseBooleanArray)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 TextView (android.widget.TextView)1 MenuPopupHelper (com.arlib.floatingsearchview.util.MenuPopupHelper)1 ViewPropertyObjectAnimator (com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator)1 ArrayList (java.util.ArrayList)1 Description (org.hamcrest.Description)1