Example usage for android.view MenuItem isVisible

List of usage examples for android.view MenuItem isVisible

Introduction

In this page you can find the example usage for android.view MenuItem isVisible.

Prototype

public boolean isVisible();

Source Link

Document

Return the visibility of the menu item.

Usage

From source file:android.support.v7.view.menu.MenuPopup.java

/**
 * Returns whether icon spacing needs to be preserved for the given menu, based on whether any
 * of its items contains an icon./* ww  w. ja v a 2  s. c  om*/
 *
 * NOTE: This should only be used for non-overflow-only menus, because this method does not
 * take into account whether the menu items are being shown as part of the popup or or being
 * shown as actions in the action bar.
 *
 * @param menu
 * @return Whether to preserve icon spacing.
 */
protected static boolean shouldPreserveIconSpacing(MenuBuilder menu) {
    boolean preserveIconSpacing = false;
    final int count = menu.size();

    for (int i = 0; i < count; i++) {
        MenuItem childItem = menu.getItem(i);
        if (childItem.isVisible() && childItem.getIcon() != null) {
            preserveIconSpacing = true;
            break;
        }
    }

    return preserveIconSpacing;
}

From source file:com.github.rubensousa.bottomsheetbuilder.adapter.BottomSheetAdapterBuilder.java

private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor, int itemTextColor,
        int itemBackground, int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();

    boolean addedSubMenu = false;

    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);

        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                SubMenu subMenu = item.getSubMenu();

                if (i != 0 && addedSubMenu) {
                    if (mMode == BottomSheetBuilder.MODE_GRID) {
                        throw new IllegalArgumentException(
                                "MODE_GRID can't have submenus." + " Use MODE_LIST instead");
                    }/* w  ww . j a v a 2  s. c o  m*/
                    items.add(new BottomSheetDivider(dividerBackground));
                }

                CharSequence title = item.getTitle();
                if (title != null && !title.equals("")) {
                    items.add(new BottomSheetHeader(title.toString(), titleTextColor));
                }

                for (int j = 0; j < subMenu.size(); j++) {
                    MenuItem subItem = subMenu.getItem(j);
                    if (subItem.isVisible()) {
                        items.add(new BottomSheetMenuItem(subItem, itemTextColor, itemBackground, tintColor));
                        addedSubMenu = true;
                    }
                }
            } else {
                items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
            }
        }
    }

    return items;
}

From source file:com.google.android.apps.iosched.util.actionmodecompat.ActionModeBase.java

/**{@inheritDoc}*/
@Override//from w  w w  .j ava  2 s.c om
public void invalidate() {
    mMenuItemArrayAdapter.clear();
    List<MenuItem> items = new ArrayList<MenuItem>();
    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);
        if (item.isVisible()) {
            items.add(item);
        }
    }
    Collections.sort(items, new Comparator<MenuItem>() {
        @Override
        public int compare(MenuItem a, MenuItem b) {
            return a.getOrder() - b.getOrder();
        }
    });
    for (MenuItem item : items) {
        mMenuItemArrayAdapter.add(item);
    }
}

From source file:com.boardgamegeek.util.actionmodecompat.ActionModeBase.java

/**
 * {@inheritDoc}//w  ww  . java  2  s  .  co  m
 */
@Override
public void invalidate() {
    mMenuItemArrayAdapter.clear();
    List<MenuItem> items = new ArrayList<>();
    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);
        if (item.isVisible()) {
            items.add(item);
        }
    }
    Collections.sort(items, new Comparator<MenuItem>() {
        @Override
        public int compare(MenuItem a, MenuItem b) {
            return a.getOrder() - b.getOrder();
        }
    });
    for (MenuItem item : items) {
        mMenuItemArrayAdapter.add(item);
    }
}

From source file:com.btmura.android.reddit.app.MessageThreadListController.java

private void prepareAuthorActionItem(Menu menu, int checkedCount, int position) {
    String author = adapter.getAuthor(position);
    boolean show = checkedCount == 1 && MenuHelper.isUserItemVisible(author);
    MenuItem item = menu.findItem(R.id.menu_author);
    item.setVisible(show);/*from  w w  w.  j a v a2 s . co  m*/
    if (item.isVisible()) {
        item.setTitle(MenuHelper.getUserTitle(context, author));
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void wrapMenuIcon(ActionMenuView view, int... excludeGroups) {
    final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
    final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(),
            view.getPopupTheme());/*from ww w .j  a v a  2  s  .  c  o  m*/
    final Resources resources = view.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight);
    final Menu menu = view.getMenu();
    final int childCount = view.getChildCount();
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }

}

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

private CharSequence[] getItemsFromMenu(Menu menu) {
    int size = menu.size();
    List<CharSequence> items = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        MenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled() && item.isVisible()) {
            items.add(item.getTitle());/*from   w  w w .  j a  v a  2 s .com*/
        }
    }

    return items.toArray(new CharSequence[items.size()]);
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void wrapMenuIcon(Context context, int backgroundColor, int popupBackgroundColor, Menu menu,
        int... excludeGroups) {
    final Resources resources = context.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupBackgroundColor, colorDark, colorLight);
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }// w  ww  . j  ava2 s.  c  om
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void wrapMenuIcon(ActionMenuView view, int... excludeGroups) {
    final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
    final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(),
            view.getPopupTheme());// w ww  .j a  va  2  s  .co  m
    final Resources resources = view.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight);
    final Menu menu = view.getMenu();
    final int childCount = view.getChildCount();
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:org.dmfs.webcal.NavbarActivity.java

protected void setupNavbar() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // this is a hack to get a Menu
    Menu menu = new PopupMenu(this, null).getMenu();
    getMenuInflater().inflate(R.menu.side_navigation, menu);

    // remove invisible menu items
    int itemCount = menu.size();
    int i = 0;//from  w  ww  .  ja v  a2  s .c o  m
    while (i < itemCount) {
        MenuItem item = menu.getItem(i);
        if (!item.isVisible()) {
            menu.removeItem(item.getItemId());
            --itemCount;
        } else {
            ++i;
        }
    }

    MenuAdapter menuAdapter = new MenuAdapter(this, R.layout.navdrawer_item, android.R.id.title, menu);
    mDrawerList.setAdapter(menuAdapter);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            String activityTitle = getActivityTitle();
            setTitle(activityTitle);
            invalidateOptionsMenu();
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            setTitle(R.string.app_name);
            invalidateOptionsMenu();
            super.onDrawerOpened(drawerView);
        }
    };
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerList.setOnItemClickListener(this);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
}