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;
}
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;
}
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();
}
}
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);
}
};
}
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;
}
Aggregations