Java Code Examples for android.view.MenuItem#isVisible()

The following examples show how to use android.view.MenuItem#isVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileActionsDialogFragment.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * calculates a parcelable list of MenuItemParcelable based on the given menu and the visibility of the menu items.
 *
 * @param menu the menu to be displayed
 * @return a filtered List of parcelables based on the menu
 */
private static List<MenuItemParcelable> calculateMenuParcel(Menu menu) {
    int index = 0;
    boolean hasNext = true;
    List<MenuItemParcelable> itemList = new ArrayList<MenuItemParcelable>();
    MenuParcelable menuParcelable = new MenuParcelable();
    try {
        while (hasNext) {
            MenuItem item = menu.getItem(index);
            if (item.isVisible()) {
                itemList.add(new MenuItemParcelable(item));
            }
            index++;
        }
    } catch (IndexOutOfBoundsException iobe) {
        // reach the end of the item list
    }

    return itemList;
}
 
Example 2
Source File: GoogleCastDelegate.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
public void showIntroductoryOverlay(@NonNull Activity activity, @Nullable final MenuItem mediaRouteMenuItem) {
    if (castContext.getCastState() != CastState.NO_DEVICES_AVAILABLE) {
        if (introductoryOverlay != null) {
            introductoryOverlay.remove();
        }
        if (mediaRouteMenuItem != null && mediaRouteMenuItem.isVisible()) {
            new Handler().post(() -> {
                introductoryOverlay = new IntroductoryOverlay.Builder(
                        activity, mediaRouteMenuItem)
                        .setTitleText(context.getString(R.string.introducing_cast_text))
                        .setSingleTime()
                        .setOnOverlayDismissedListener(
                                () -> introductoryOverlay = null)
                        .build();
                introductoryOverlay.show();
            });
        }
    }
}
 
Example 3
Source File: SweetSheet.java    From AndroidSweetSheet with Apache License 2.0 6 votes vote down vote up
/**
 * 当前只处理一级的菜单
 *
 * @param menu
 * @return
 */
private List<MenuEntity> getMenuEntityFormMenuRes(Menu menu) {

    List<MenuEntity> list = new ArrayList<>();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);

        if (item.isVisible()) {
            MenuEntity itemEntity = new MenuEntity();
            itemEntity.title = item.getTitle().toString();
            itemEntity.icon = item.getIcon();
            list.add(itemEntity);
        }
    }
    return list;
}
 
Example 4
Source File: ConversationActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
  if (menu == null) {
    return super.onMenuOpened(featureId, null);
  }

  if (!SignalStore.uiHints().hasSeenGroupSettingsMenuToast()) {
    MenuItem settingsMenuItem = menu.findItem(R.id.menu_group_settings);

    if (settingsMenuItem != null && settingsMenuItem.isVisible()) {
      Toast toast = Toast.makeText(this, R.string.ConversationActivity__more_options_now_in_group_settings, Toast.LENGTH_SHORT);

      toast.setGravity(Gravity.CENTER, 0, 0);
      toast.show();

      SignalStore.uiHints().markHasSeenGroupSettingsMenuToast();
    }
  }

  return super.onMenuOpened(featureId, menu);
}
 
Example 5
Source File: FabSpeedDial.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void addMenuItems() {
    ViewCompat.setAlpha(menuItemsLayout, 1f);
    for (int i = 0; i < navigationMenu.size(); i++) {
        MenuItem menuItem = navigationMenu.getItem(i);
        if (menuItem.isVisible()) {
            menuItemsLayout.addView(createFabMenuItem(menuItem));
        }
    }
    animateFabMenuItemsIn();
}
 
Example 6
Source File: FabSpeedDial.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void addMenuItems() {
    ViewCompat.setAlpha(menuItemsLayout, 1f);
    for (int i = 0; i < navigationMenu.size(); i++) {
        MenuItem menuItem = navigationMenu.getItem(i);
        if (menuItem.isVisible()) {
            menuItemsLayout.addView(createFabMenuItem(menuItem));
        }
    }
    animateFabMenuItemsIn();
}
 
Example 7
Source File: FabSpeedDial.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void addMenuItems() {
    ViewCompat.setAlpha(menuItemsLayout, 1f);
    for (int i = 0; i < navigationMenu.size(); i++) {
        MenuItem menuItem = navigationMenu.getItem(i);
        if (menuItem.isVisible()) {
            menuItemsLayout.addView(createFabMenuItem(menuItem));
        }
    }
    animateFabMenuItemsIn();
}
 
Example 8
Source File: AppMenuPropertiesDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
private void disableEnableMenuItem(
        Menu menu, int id, boolean visible, boolean enabled, boolean managed) {
    for (int i = 0; i < menu.size(); ++i) {
        MenuItem item = menu.getItem(i);
        if (item.getItemId() == id && item.isVisible()) {
            item.setVisible(visible);
            item.setEnabled(enabled);
            if (managed) {
                item.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
            } else {
                item.setIcon(null);
            }
        }
    }
}
 
Example 9
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private List<MenuItem> getVisibleAndEnabledMenuItems(Menu menu) {
    List<MenuItem> menuItems = new ArrayList<>();
    for (int i = 0; (menu != null) && (i < menu.size()); i++) {
        MenuItem menuItem = menu.getItem(i);
        if (menuItem.isVisible() && menuItem.isEnabled()) {
            Menu subMenu = menuItem.getSubMenu();
            if (subMenu != null) {
                menuItems.addAll(getVisibleAndEnabledMenuItems(subMenu));
            } else {
                menuItems.add(menuItem);
            }
        }
    }
    return menuItems;
}
 
Example 10
Source File: AppMenuPropertiesDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void disableEnableMenuItem(
        Menu menu, int id, boolean visible, boolean enabled, boolean managed) {
    for (int i = 0; i < menu.size(); ++i) {
        MenuItem item = menu.getItem(i);
        if (item.getItemId() == id && item.isVisible()) {
            item.setVisible(visible);
            item.setEnabled(enabled);
            if (managed) {
                item.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
            } else {
                item.setIcon(null);
            }
        }
    }
}
 
Example 11
Source File: FabSpeedDial.java    From fab-speed-dial with Apache License 2.0 5 votes vote down vote up
private void addMenuItems() {
    ViewCompat.setAlpha(menuItemsLayout, 1f);
    for (int i = 0; i < navigationMenu.size(); i++) {
        MenuItem menuItem = navigationMenu.getItem(i);
        if (menuItem.isVisible()) {
            menuItemsLayout.addView(createFabMenuItem(menuItem));
        }
    }
    animateFabMenuItemsIn();
}
 
Example 12
Source File: FabSpeedDial.java    From fab-speed-dial with Apache License 2.0 5 votes vote down vote up
private void addMenuItems() {
    ViewCompat.setAlpha(menuItemsLayout, 1f);
    for (int i = 0; i < navigationMenu.size(); i++) {
        MenuItem menuItem = navigationMenu.getItem(i);
        if (menuItem.isVisible()) {
            menuItemsLayout.addView(createFabMenuItem(menuItem));
        }
    }
    animateFabMenuItemsIn();
}
 
Example 13
Source File: ContextMenu.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasVisibleItems() {
  for (MenuItem item : items) {
    if (item.isVisible()) {
      return true;
    }
  }

  return false;
}
 
Example 14
Source File: EditAccountActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
    if (showMoreInfo.isVisible()) {
        showMoreInfo.setChecked(binding.serverInfoMore.getVisibility() == View.VISIBLE);
    }
    return super.onPrepareOptionsMenu(menu);
}
 
Example 15
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private List<MenuItem> getVisibleAndEnabledMenuItems(Menu menu) {
    List<MenuItem> menuItems = new ArrayList<>();
    for (int i = 0; (menu != null) && (i < menu.size()); i++) {
        MenuItem menuItem = menu.getItem(i);
        if (menuItem.isVisible() && menuItem.isEnabled()) {
            Menu subMenu = menuItem.getSubMenu();
            if (subMenu != null) {
                menuItems.addAll(getVisibleAndEnabledMenuItems(subMenu));
            } else {
                menuItems.add(menuItem);
            }
        }
    }
    return menuItems;
}
 
Example 16
Source File: ActionMenuPresenter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (!subMenu.hasVisibleItems()) return false;

    SubMenuBuilder topSubMenu = subMenu;
    while (topSubMenu.getParentMenu() != mMenu) {
        topSubMenu = (SubMenuBuilder) topSubMenu.getParentMenu();
    }
    View anchor = findViewForItem(topSubMenu.getItem());
    if (anchor == null) {
        // This means the submenu was opened from an overflow menu item, indicating the
        // MenuPopupHelper will handle opening the submenu via its MenuPopup. Return false to
        // ensure that the MenuPopup acts as presenter for the submenu, and acts on its
        // responsibility to display the new submenu.
        return false;
    }

    mOpenSubMenuId = subMenu.getItem().getItemId();

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

    mActionButtonPopup = new ActionButtonSubmenu(mContext, subMenu, anchor);
    mActionButtonPopup.setForceShowIcon(preserveIconSpacing);
    mActionButtonPopup.show();

    super.onSubMenuSelected(subMenu);
    return true;
}
 
Example 17
Source File: MainActivity.java    From revolution-irc with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean hasChanges = false;
    if (getCurrentFragment() instanceof ChatFragment) {
        ChatFragment fragment = ((ChatFragment) getCurrentFragment());
        ServerConnectionApi api = ((ServerConnectionApi) fragment.getConnectionInfo().getApiInstance());
        boolean connected = fragment.getConnectionInfo().isConnected();
        boolean wasConnected = !menu.findItem(R.id.action_reconnect).isVisible();
        if (connected != wasConnected) {
            if (connected) {
                menu.findItem(R.id.action_reconnect).setVisible(false);
                menu.findItem(R.id.action_close).setVisible(false);
                menu.findItem(R.id.action_disconnect).setVisible(true);
                menu.findItem(R.id.action_disconnect_and_close).setVisible(true);
            } else {
                menu.findItem(R.id.action_reconnect).setVisible(true);
                menu.findItem(R.id.action_close).setVisible(true);
                menu.findItem(R.id.action_disconnect).setVisible(false);
                menu.findItem(R.id.action_disconnect_and_close).setVisible(false);
            }
            hasChanges = true;
        }
        if (fragment.getSendMessageHelper().hasSendMessageTextSelection() !=
                menu.findItem(R.id.action_format).isVisible()) {
            menu.findItem(R.id.action_format).setVisible(fragment.getSendMessageHelper()
                    .hasSendMessageTextSelection());
            hasChanges = true;
        }
        MenuItem partItem = menu.findItem(R.id.action_part_channel);
        boolean inDirectChat = false;
        if (fragment.getCurrentChannel() == null) {
            if (partItem.isVisible())
                hasChanges = true;
            partItem.setVisible(false);
        } else if (fragment.getCurrentChannel().length() > 0 && !api.getServerConnectionData()
                .getSupportList().getSupportedChannelTypes().contains(fragment.getCurrentChannel().charAt(0))) {
            if (partItem.isVisible() || !partItem.getTitle().equals(getString(R.string.action_close_direct)))
                hasChanges = true;
            partItem.setVisible(true);
            partItem.setTitle(R.string.action_close_direct);
            inDirectChat = true;
        } else {
            if (partItem.isVisible() || !partItem.getTitle().equals(getString(R.string.action_part_channel)))
                hasChanges = true;
            partItem.setVisible(true);
            partItem.setTitle(R.string.action_part_channel);
        }
        boolean wasDccSendVisible = menu.findItem(R.id.action_dcc_send).isVisible();
        boolean dccSendVisible = ChatSettings.isDccSendVisible() && connected && inDirectChat;
        if (dccSendVisible != wasDccSendVisible) {
            menu.findItem(R.id.action_dcc_send).setVisible(dccSendVisible);
            hasChanges = true;
        }
    }
    return super.onPrepareOptionsMenu(menu) | hasChanges;
}
 
Example 18
Source File: BottomSheetAdapterBuilder.java    From BottomSheetBuilder with Apache License 2.0 4 votes vote down vote up
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
                                                 int itemTextColor, int itemBackground,
                                                 int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();
    mTitles = 0;

    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");
                    }
                    items.add(new BottomSheetDivider(dividerBackground));
                }

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

                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;
}
 
Example 19
Source File: MenuSheetView.java    From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Flattens the visible menu items of {@link #menu} into {@link #items},
 * while inserting separators between items when necessary.
 *
 * Adapted from the Design support library's NavigationMenuPresenter implementation
 */
private void prepareMenuItems() {
    items.clear();
    int currentGroupId = 0;

    // Iterate over the menu items
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                // Flatten the submenu
                SubMenu subMenu = item.getSubMenu();
                if (subMenu.hasVisibleItems()) {
                    if (menuType == LIST) {
                        items.add(SheetMenuItem.SEPARATOR);

                        // Add a header item if it has text
                        if (!TextUtils.isEmpty(item.getTitle())) {
                            items.add(SheetMenuItem.of(item));
                        }
                    }

                    // Add the sub-items
                    for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
                        MenuItem subMenuItem = subMenu.getItem(subI);
                        if (subMenuItem.isVisible()) {
                            items.add(SheetMenuItem.of(subMenuItem));
                        }
                    }

                    // Add one more separator to the end to close it off if we have more items
                    if (menuType == LIST && i != menu.size() - 1) {
                        items.add(SheetMenuItem.SEPARATOR);
                    }
                }
            } else {
                int groupId = item.getGroupId();
                if (groupId != currentGroupId && menuType == LIST) {
                    items.add(SheetMenuItem.SEPARATOR);
                }
                items.add(SheetMenuItem.of(item));
                currentGroupId = groupId;
            }
        }
    }
}
 
Example 20
Source File: MenuSheetView.java    From bottomsheet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Flattens the visible menu items of {@link #menu} into {@link #items},
 * while inserting separators between items when necessary.
 *
 * Adapted from the Design support library's NavigationMenuPresenter implementation
 */
private void prepareMenuItems() {
    items.clear();
    int currentGroupId = 0;

    // Iterate over the menu items
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                // Flatten the submenu
                SubMenu subMenu = item.getSubMenu();
                if (subMenu.hasVisibleItems()) {
                    if (menuType == LIST) {
                        items.add(SheetMenuItem.SEPARATOR);

                        // Add a header item if it has text
                        if (!TextUtils.isEmpty(item.getTitle())) {
                            items.add(SheetMenuItem.of(item));
                        }
                    }

                    // Add the sub-items
                    for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
                        MenuItem subMenuItem = subMenu.getItem(subI);
                        if (subMenuItem.isVisible()) {
                            items.add(SheetMenuItem.of(subMenuItem));
                        }
                    }

                    // Add one more separator to the end to close it off if we have more items
                    if (menuType == LIST && i != menu.size() - 1) {
                        items.add(SheetMenuItem.SEPARATOR);
                    }
                }
            } else {
                int groupId = item.getGroupId();
                if (groupId != currentGroupId && menuType == LIST) {
                    items.add(SheetMenuItem.SEPARATOR);
                }
                items.add(SheetMenuItem.of(item));
                currentGroupId = groupId;
            }
        }
    }
}