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

The following examples show how to use android.view.MenuItem#getSubMenu() . 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: SearchBookActivity.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
private void initMenu(Menu menu) {
    if (menu == null) return;
    MenuItem item = menu.findItem(R.id.action_outer_source);
    SubMenu subMenu = item.getSubMenu();
    subMenu.removeGroup(R.id.book_source_group);
    if (BookSourceManager.getEnabledCount() > 0) {
        item.setVisible(true);
        item.setEnabled(true);
        MenuItem subItem = subMenu.add(R.id.book_source_group, Menu.NONE, Menu.NONE, R.string.book_all_source);
        if (group == null) {
            subItem.setChecked(true);
        }
        List<String> groupList = BookSourceManager.getEnableGroupList();
        for (String groupName : groupList) {
            subItem = subMenu.add(R.id.book_source_group, Menu.NONE, Menu.NONE, groupName);
            if (TextUtils.equals(group, subItem.getTitle())) {
                subItem.setChecked(true);
            }
        }
        subMenu.setGroupCheckable(R.id.book_source_group, true, true);
    } else {
        item.setVisible(false);
        item.setEnabled(false);
    }
}
 
Example 2
Source File: ActionMenuHelper.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
public static void setMenuParameters(final IActionController<?> c, final Menu menu,
        final IActionParameter... parameters) {
    for (int i = 0, n = menu.size(); i < n; i++) {
        final MenuItem item = menu.getItem(i);
        final SubMenu subMenu = item.getSubMenu();
        if (subMenu != null) {
            setMenuParameters(c, subMenu, parameters);
        } else {
            final int itemId = item.getItemId();
            final ActionEx action = c.getOrCreateAction(itemId);
            for (final IActionParameter p : parameters) {
                action.addParameter(p);
            }
        }
    }
}
 
Example 3
Source File: NavigatorActivity.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
	if (searchMode) {
		return true;
	}
	if (page != null && sendPrepareMenuToPage) {
		page.onPrepareOptionsMenu(menu);
	}
	MenuItem appearanceOptionsItem = menu.findItem(ListPage.OPTIONS_MENU_APPEARANCE);
	if (appearanceOptionsItem != null) {
		Menu appearanceOptionsMenu = appearanceOptionsItem.getSubMenu();
		appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_EXPANDED_SCREEN)
				.setChecked(Preferences.isExpandedScreen());
		appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_SPOILERS).setChecked(Preferences.isShowSpoilers());
		appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_MY_POSTS).setChecked(Preferences.isShowMyPosts());
		boolean lockable = ViewUtils.isDrawerLockable(getResources().getConfiguration());
		boolean locked = Preferences.isDrawerLocked();
		appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_DRAWER).setVisible(lockable).setChecked(locked);
		appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_THREADS_GRID)
				.setChecked(Preferences.isThreadsGridMode());
		appearanceOptionsMenu.findItem(ListPage.APPEARANCE_MENU_SFW_MODE).setChecked(Preferences.isSfwMode());
	}
	actionMenuConfigurator.onAfterPrepareOptionsMenu(menu);
	return true;
}
 
Example 4
Source File: BrowserActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected void createFileMenu(final ContextMenu menu, final String path) {
    final BookSettings bs = SettingsManager.getBookSettings(path);
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);
    menu.setHeaderTitle(path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(false);
    menu.findItem(R.id.bookmenu_openbookfolder).setVisible(false);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
        return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
        if (LengthUtils.isNotEmpty(bs.bookmarks)) {
            list.addAll(bs.bookmarks);
        }
        list.add(new Bookmark(true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
        addBookmarkMenuItem(osm, b);
    }
}
 
Example 5
Source File: ItemsListFragment.java    From tup.dota2recipe with Apache License 2.0 5 votes vote down vote up
/**
 * 创建英雄属性筛选子菜单
 * 
 * @param cMenu
 *            当前菜单项
 * @param cSubMenuKeysId
 *            当前菜单关联的子菜单项资源ID
 * @param menuItemClickListener
 *            创建后的子菜单单击监听
 */
private void createHeroOptionsSubMenu(MenuItem cMenu, int cMenuQueryKeyId,
        int cSubMenuKeysId,
        String[] cSubMenuValues,
        MenuItem.OnMenuItemClickListener menuItemClickListener) {
    if (cMenu == null || menuItemClickListener == null) {
        return;
    }

    final SubMenu cSubMenu = cMenu.getSubMenu();
    final String[] cSubMenuKeys = this.getResources().getStringArray(
            cSubMenuKeysId);
    MenuItem cMenuItem = null;
    int cIndex = 0;
    for (String cMenuKey : cSubMenuKeys) {
        cMenuItem = cSubMenu.add(0, cIndex++, 0, cMenuKey);
        cMenuItem.setOnMenuItemClickListener(menuItemClickListener);
    }

    // 设置菜单默认值
    final String queryKey = menu_items_query_keys[cMenuQueryKeyId];
    if (!queryKey.equals(KEY_MENU_ITEMS_QUERY_ALL) && cSubMenuKeys != null) {
        final int queryValueIndex = Utils.indexOf(cSubMenuValues, queryKey);
        if (queryValueIndex >= 0 && cSubMenuKeys.length > queryValueIndex) {
            cMenu.setTitle(cSubMenuKeys[queryValueIndex]);
        }
    }
}
 
Example 6
Source File: ViewUtils.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
public static MenuItem getSelectedMenu(@NonNull MenuItem menuItem) {
    if (menuItem.getSubMenu() == null || menuItem.getSubMenu().size() == 0) {
        return null;
    }
    MenuItem selected = null;
    for (int i = 0; i < menuItem.getSubMenu().size(); i++) {
        MenuItem item = menuItem.getSubMenu().getItem(i);
        if (item.isChecked()) {
            selected = item;
            break;
        }
    }
    return selected;
}
 
Example 7
Source File: GroupsViewFragment.java    From HomeGenie-Android with GNU General Public License v3.0 5 votes vote down vote up
public void UpdateJumpToGroupMenu(ArrayList<Group> groups) {
    StartActivity rootActivity = (StartActivity) getActivity();
    if (rootActivity != null) {
        Menu menu = rootActivity.getActionMenu();
        if (menu != null) {
            MenuItem jumpto = menu.findItem(R.id.action_jumpto);
            Menu submenu = jumpto.getSubMenu();
            if (submenu == null) return;
            //
            submenu.removeGroup(Menu.NONE);
            if (groups.size() > 0) {
                int gid = 0;
                for (Group group : groups) {
                    MenuItem grp = submenu.add(Menu.NONE, gid, gid, group.Name);
                    //prg.setIcon(R.drawable.ic_action_flash_on);
                    MenuCompat.setShowAsAction(grp, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                    grp.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            mIndicator.setCurrentItem(menuItem.getItemId());
                            return true;
                        }
                    });
                    gid++;
                }
            }
        }
    }
}
 
Example 8
Source File: RecentActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected void onCreateBookMenu(final ContextMenu menu, final BookNode node) {
    final BookSettings bs = node.settings;
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);

    menu.setHeaderTitle(node.path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);

    final BookShelfAdapter bookShelf = getController().getBookShelf(node);
    final BookShelfAdapter current = bookcaseView != null ? getController().getBookShelf(
            bookcaseView.getCurrentList()) : null;
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(
            bookShelf != null && current != null && bookShelf != current);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
        return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
        if (LengthUtils.isNotEmpty(bs.bookmarks)) {
            list.addAll(bs.bookmarks);
        }
        list.add(new Bookmark(true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
        addBookmarkMenuItem(osm, b);
    }
}
 
Example 9
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 10
Source File: ActionMenuHelper.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public static void setMenuSource(final IActionController<?> c, final Menu menu, final Object source) {
    for (int i = 0, n = menu.size(); i < n; i++) {
        final MenuItem item = menu.getItem(i);
        final SubMenu subMenu = item.getSubMenu();
        if (subMenu != null) {
            setMenuSource(c, subMenu, source);
        } else {
            setMenuItemSource(c, item, source);
        }
    }
}
 
Example 11
Source File: NavigatorActivity.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	if (searchMode) {
		currentMenu = null;
		menu.add(0, ListPage.OPTIONS_MENU_SEARCH_VIEW, 0, "").setActionView(getSearchView(true))
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	} else {
		currentMenu = menu;
		if (page != null) {
			page.onCreateOptionsMenu(menu);
			sendPrepareMenuToPage = true;
		}
		MenuItem appearanceOptionsItem = menu.findItem(ListPage.OPTIONS_MENU_APPEARANCE);
		if (appearanceOptionsItem != null) {
			Menu appearanceOptionsMenu = appearanceOptionsItem.getSubMenu();
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_CHANGE_THEME, 0,
					R.string.action_change_theme);
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_EXPANDED_SCREEN, 0,
					R.string.action_expanded_screen).setCheckable(true);
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_SPOILERS, 0,
					R.string.action_spoilers).setCheckable(true);
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_MY_POSTS, 0,
					R.string.action_my_posts).setCheckable(true);
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_DRAWER, 0,
					R.string.action_lock_drawer).setCheckable(true);
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_THREADS_GRID, 0,
					R.string.action_threads_grid).setCheckable(true);
			appearanceOptionsMenu.add(0, ListPage.APPEARANCE_MENU_SFW_MODE, 0,
					R.string.action_sfw_mode).setCheckable(true);
		}
		actionMenuConfigurator.onAfterCreateOptionsMenu(menu);
	}
	return true;
}
 
Example 12
Source File: UartActivity.java    From Bluefruit_LE_Connect_Android with MIT License 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_uart, menu);

    // Mqtt
    mMqttMenuItem = menu.findItem(R.id.action_mqttsettings);
    mMqttMenuItemAnimationHandler = new Handler();
    mMqttMenuItemAnimationRunnable.run();

    // DisplayMode
    MenuItem displayModeMenuItem = menu.findItem(R.id.action_displaymode);
    displayModeMenuItem.setTitle(String.format(getString(R.string.uart_action_displaymode_format), getString(mIsTimestampDisplayMode ? R.string.uart_displaymode_timestamp : R.string.uart_displaymode_text)));
    SubMenu displayModeSubMenu = displayModeMenuItem.getSubMenu();
    if (mIsTimestampDisplayMode) {
        MenuItem displayModeTimestampMenuItem = displayModeSubMenu.findItem(R.id.action_displaymode_timestamp);
        displayModeTimestampMenuItem.setChecked(true);
    } else {
        MenuItem displayModeTextMenuItem = displayModeSubMenu.findItem(R.id.action_displaymode_text);
        displayModeTextMenuItem.setChecked(true);
    }

    // DataMode
    MenuItem dataModeMenuItem = menu.findItem(R.id.action_datamode);
    dataModeMenuItem.setTitle(String.format(getString(R.string.uart_action_datamode_format), getString(mShowDataInHexFormat ? R.string.uart_format_hexadecimal : R.string.uart_format_ascii)));
    SubMenu dataModeSubMenu = dataModeMenuItem.getSubMenu();
    if (mShowDataInHexFormat) {
        MenuItem dataModeHexMenuItem = dataModeSubMenu.findItem(R.id.action_datamode_hex);
        dataModeHexMenuItem.setChecked(true);
    } else {
        MenuItem dataModeAsciiMenuItem = dataModeSubMenu.findItem(R.id.action_datamode_ascii);
        dataModeAsciiMenuItem.setChecked(true);
    }

    // Echo
    MenuItem echoMenuItem = menu.findItem(R.id.action_echo);
    echoMenuItem.setTitle(R.string.uart_action_echo);
    echoMenuItem.setChecked(mIsEchoEnabled);

    // Eol
    MenuItem eolMenuItem = menu.findItem(R.id.action_eol);
    eolMenuItem.setTitle(R.string.uart_action_eol);
    eolMenuItem.setChecked(mIsEolEnabled);

    // Eol Characters
    MenuItem eolModeMenuItem = menu.findItem(R.id.action_eolmode);
    eolModeMenuItem.setTitle(String.format(getString(R.string.uart_action_eolmode_format), getString(getEolCharactersStringId())));
    SubMenu eolModeSubMenu = eolModeMenuItem.getSubMenu();
    int selectedEolCharactersSubMenuId;
    switch (mEolCharactersId) {
        case 1:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_r;
            break;
        case 2:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_nr;
            break;
        case 3:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_rn;
            break;
        default:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_n;
            break;
    }
    MenuItem selectedEolCharacterMenuItem = eolModeSubMenu.findItem(selectedEolCharactersSubMenuId);
    selectedEolCharacterMenuItem.setChecked(true);

    return true;
}
 
Example 13
Source File: GroupsViewFragment.java    From HomeGenie-Android with GNU General Public License v3.0 4 votes vote down vote up
public void UpdateCurrentGroupMenu() {
        StartActivity rootActivity = (StartActivity) getActivity();
        if (rootActivity == null)
            return;
        Menu menu = rootActivity.getActionMenu();
        if (menu != null) {
            MenuItem automation = menu.findItem(R.id.menu_automation);
            if (automation != null) {
                automation.setEnabled(false);
                Menu submenu = automation.getSubMenu();
                if (submenu == null) return;
                //
                submenu.removeGroup(Menu.NONE);
                if (mGroupPrograms.size() > 0) {
                    for (Module program : mGroupPrograms) {
                        MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName());
                        prg.setIcon(R.drawable.ic_action_flash_on);
                        MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                        final String address = program.Address;
                        String groupName = "";
                        try {
                            groupName = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8");
                        } catch (Exception e) {
                        }
                        final String group = groupName;
                        prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                            @Override
                            public boolean onMenuItemClick(MenuItem menuItem) {
                                String apiCall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" +
                                        address + "/" +
                                        group + "/" + new Date().getTime();
                                Control.apiRequest(apiCall, null);
                                return true;
                            }
                        });
                    }
                    automation.setEnabled(true);
                }
            }
            //
//            MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro");
//            recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem menuItem) {
//                    StartActivity sa = (StartActivity)getActivity();
//                    sa.openMacroRecordMenu();
//                    return true;
//                }
//            });
//            rootactivity.supportInvalidateOptionsMenu();
        }
    }
 
Example 14
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;
            }
        }
    }
}
 
Example 15
Source File: ViewerActivity.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.emdev.ui.AbstractActionActivity#updateMenuItems(android.view.Menu)
 */
@Override
protected void updateMenuItems(final Menu menu) {
    final AppSettings as = AppSettings.current();

    ActionMenuHelper.setMenuItemChecked(menu, as.fullScreen, R.id.mainmenu_fullscreen);
    ActionMenuHelper.setMenuItemChecked(menu, as.showTitle, R.id.mainmenu_showtitle);
    ActionMenuHelper
            .setMenuItemChecked(menu, getZoomControls().getVisibility() == View.VISIBLE, R.id.mainmenu_zoom);

    final BookSettings bs = getController().getBookSettings();
    if (bs == null) {
        return;
    }

    ActionMenuHelper.setMenuItemChecked(menu,
            (bs.rotation == RotationType.PORTRAIT || bs.rotation == RotationType.REVERSE_PORTRAIT),
            R.id.mainmenu_force_portrait);
    ActionMenuHelper.setMenuItemChecked(menu,
            (bs.rotation == RotationType.LANDSCAPE || bs.rotation == RotationType.REVERSE_LANDSCAPE),
            R.id.mainmenu_force_landscape);
    ActionMenuHelper.setMenuItemChecked(menu,
            (bs.rotation == RotationType.REVERSE_LANDSCAPE || bs.rotation == RotationType.REVERSE_PORTRAIT),
            R.id.mainmenu_reverse_orientation);
    ActionMenuHelper.setMenuItemEnabled(menu,
            (bs.rotation == RotationType.PORTRAIT
            || bs.rotation == RotationType.REVERSE_PORTRAIT
            || bs.rotation == RotationType.LANDSCAPE
            || bs.rotation == RotationType.REVERSE_LANDSCAPE),
            R.id.mainmenu_reverse_orientation);
    ActionMenuHelper.setMenuItemChecked(menu, bs.nightMode, R.id.mainmenu_nightmode);
    ActionMenuHelper.setMenuItemChecked(menu, bs.cropPages, R.id.mainmenu_croppages);
    ActionMenuHelper.setMenuItemChecked(menu, bs.splitPages, R.id.mainmenu_splitpages,
            R.drawable.viewer_menu_split_pages, R.drawable.viewer_menu_split_pages_off);
    ActionMenuHelper.setMenuItemChecked(menu, bs.viewMode == DocumentViewMode.SINGLE_PAGE,
            R.id.mainmenu_singlepage);

    final DecodeService ds = getController().getDecodeService();

    final boolean cropSupported = ds.isFeatureSupported(CodecFeatures.FEATURE_CROP_SUPPORT);
    ActionMenuHelper.setMenuItemVisible(menu, cropSupported, R.id.mainmenu_croppages);
    ActionMenuHelper.setMenuItemVisible(menu, cropSupported, R.id.mainmenu_crop);

    final boolean splitSupported = ds.isFeatureSupported(CodecFeatures.FEATURE_SPLIT_SUPPORT);
    ActionMenuHelper.setMenuItemVisible(menu, splitSupported, R.id.mainmenu_splitpages);

    final MenuItem navMenu = menu.findItem(R.id.mainmenu_nav_menu);
    if (navMenu != null) {
        final SubMenu subMenu = navMenu.getSubMenu();
        subMenu.removeGroup(R.id.actions_goToBookmarkGroup);
        if (AppSettings.current().showBookmarksInMenu && LengthUtils.isNotEmpty(bs.bookmarks)) {
            for (final Bookmark b : bs.bookmarks) {
                addBookmarkMenuItem(subMenu, b);
            }
        }
    }

}
 
Example 16
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 17
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 18
Source File: BottomSheetAdapterBuilder.java    From SimplicityBrowser with MIT License 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: Main.java    From Cook-It-Android-XML-Template with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setupToolbar(R.id.toolbar, "COOK IT", R.color.colorPink, R.color.colorWhiteTrans, R.drawable.ic_burger);

    FragmentTransaction ft;
    FragmentHome fragmentHome = new FragmentHome();
    ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.frameLayout, fragmentHome).commit();

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    Menu m = navigationView.getMenu();
    for (int i=0;i<m.size();i++) {
        MenuItem mi = m.getItem(i);
        SubMenu subMenu = mi.getSubMenu();
        if (subMenu!=null && subMenu.size() >0 ) {
            for (int j=0; j <subMenu.size();j++) {
                MenuItem subMenuItem = subMenu.getItem(j);
                applyFontToMenuItem(subMenuItem);
            }
        }
        applyFontToMenuItem(mi);
    }

    View header = navigationView.getHeaderView(0);
    ImageView imageView = (ImageView) header.findViewById(R.id.imageView);
    Glide.with(this)
            .load(Uri.parse("https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg"))
            .transform(new CircleGlide(this))
            .into(imageView);
}
 
Example 20
Source File: UartBaseFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 4 votes vote down vote up
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_uart, menu);

    // Mqtt
    mMqttMenuItem = menu.findItem(R.id.action_mqttsettings);
    mMqttMenuItemAnimationHandler = new Handler();
    mMqttMenuItemAnimationRunnable.run();

    // DisplayMode
    MenuItem displayModeMenuItem = menu.findItem(R.id.action_displaymode);
    displayModeMenuItem.setTitle(String.format("%s: %s", getString(R.string.uart_settings_displayMode_title), getString(mIsTimestampDisplayMode ? R.string.uart_settings_displayMode_timestamp : R.string.uart_settings_displayMode_text)));
    SubMenu displayModeSubMenu = displayModeMenuItem.getSubMenu();
    if (mIsTimestampDisplayMode) {
        MenuItem displayModeTimestampMenuItem = displayModeSubMenu.findItem(R.id.action_displaymode_timestamp);
        displayModeTimestampMenuItem.setChecked(true);
    } else {
        MenuItem displayModeTextMenuItem = displayModeSubMenu.findItem(R.id.action_displaymode_text);
        displayModeTextMenuItem.setChecked(true);
    }

    // DataMode
    MenuItem dataModeMenuItem = menu.findItem(R.id.action_datamode);
    dataModeMenuItem.setTitle(String.format("%s: %s", getString(R.string.uart_settings_dataMode_title), getString(mShowDataInHexFormat ? R.string.uart_settings_dataMode_hex : R.string.uart_settings_dataMode_ascii)));
    SubMenu dataModeSubMenu = dataModeMenuItem.getSubMenu();
    if (mShowDataInHexFormat) {
        MenuItem dataModeHexMenuItem = dataModeSubMenu.findItem(R.id.action_datamode_hex);
        dataModeHexMenuItem.setChecked(true);
    } else {
        MenuItem dataModeAsciiMenuItem = dataModeSubMenu.findItem(R.id.action_datamode_ascii);
        dataModeAsciiMenuItem.setChecked(true);
    }

    // Echo
    MenuItem echoMenuItem = menu.findItem(R.id.action_echo);
    echoMenuItem.setTitle(R.string.uart_settings_echo_title);
    echoMenuItem.setChecked(mIsEchoEnabled);

    // Eol
    MenuItem eolMenuItem = menu.findItem(R.id.action_eol);
    eolMenuItem.setTitle(R.string.uart_settings_eol_title);
    eolMenuItem.setChecked(mIsEolEnabled);

    // Eol Characters
    MenuItem eolModeMenuItem = menu.findItem(R.id.action_eolmode);
    eolModeMenuItem.setTitle(String.format("%s: %s", getString(R.string.uart_settings_eolCharacters_title), getString(getEolCharactersStringId())));
    SubMenu eolModeSubMenu = eolModeMenuItem.getSubMenu();
    int selectedEolCharactersSubMenuId;
    switch (mEolCharactersId) {
        case 1:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_r;
            break;
        case 2:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_nr;
            break;
        case 3:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_rn;
            break;
        default:
            selectedEolCharactersSubMenuId = R.id.action_eolmode_n;
            break;
    }
    MenuItem selectedEolCharacterMenuItem = eolModeSubMenu.findItem(selectedEolCharactersSubMenuId);
    selectedEolCharacterMenuItem.setChecked(true);


}