Example usage for android.view Menu addSubMenu

List of usage examples for android.view Menu addSubMenu

Introduction

In this page you can find the example usage for android.view Menu addSubMenu.

Prototype

SubMenu addSubMenu(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

Variation on #addSubMenu(int,int,int,CharSequence) that takes a string resource identifier for the title instead of the string itself.

Usage

From source file:com.ushahidi.android.presentation.view.ui.activity.PostActivity.java

private void setNavigationViewMenuItems(@NonNull Menu menu) {
    // Reset menu items to avoid duplicates because we reinitialize them
    menu.clear();//from   w  w  w . ja  va2s. co  m
    if (!Utility.isCollectionEmpty(mDeploymentModelList)) {
        SubMenu subMenu = menu.addSubMenu(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.deployments);
        subMenu.setGroupCheckable(DEPLOYMENTS_MENU_ITEMS_GROUP_ID, true, true);
        // Use item position as the menu item's id that way we can retrieve the individual
        // deployment when user clicks on it to make it the active deployment
        for (int pos = 0; pos < mDeploymentModelList.size(); pos++) {
            subMenu.add(DEPLOYMENTS_MENU_ITEMS_GROUP_ID, pos, pos, mDeploymentModelList.get(pos).getTitle())
                    .setIcon(R.drawable.ic_action_globe);
            if (mDeploymentModelList.get(pos).getStatus().equals(DeploymentModel.Status.ACTIVATED)) {
                mNavigationView.getMenu().findItem(pos).setChecked(true);
                mToolbar.setTitle(mNavigationView.getMenu().findItem(pos).getTitle());
            } else {
                mNavigationView.getMenu().findItem(pos).setChecked(false);
            }
        }
    }

    mSubMenuMisc = menu.addSubMenu(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.actions);

    mSubMenuMisc.add(MISC_MENU_ITEMS, MANAGE_DEPLOYMENT_MENU_ID, 1, R.string.manage_deployments)
            .setIcon(R.drawable.ic_action_map);

    mSubMenuMisc.add(MISC_MENU_ITEMS, FEEDBACK_MENU_ID, 2, R.string.send_feedback)
            .setIcon(R.drawable.ic_action_help);
    mSubMenuMisc.add(MISC_MENU_ITEMS, ABOUT_MENU_ID, 3, R.string.about).setIcon(R.drawable.ic_action_info);

    if (mSessionManager.getActiveSession() != null) {
        mSubMenuMisc.add(MISC_MENU_ITEMS, LOGOUT_MENU_ID, 4, R.string.logout)
                .setIcon(R.drawable.ic_action_logout);
    }

    mSubMenuMisc.setGroupCheckable(MISC_MENU_ITEMS, true, true);

}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    toolsSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_tools);//from   w  w  w.  j ava  2  s.c  o  m
    toolsSubMenu.setIcon(R.drawable.ic_edit);
    toolsSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // TOOLS MENU
    MenuItem mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PEN,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PEN, R.string.editor_pen);
    mi.setIcon(R.drawable.ic_edit);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TEXT,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_TEXT, R.string.editor_text);
    mi.setIcon(R.drawable.ic_text);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SELECTION,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SELECTION, R.string.editor_selection);
    mi.setIcon(R.drawable.ic_selection);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ERASER,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ERASER, R.string.editor_eraser);
    mi.setIcon(R.drawable.ic_eraser);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // TOOL SETTINGS MENU
    SubMenu toolsSettingSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings);
    toolsSettingSubMenu.setIcon(R.drawable.ic_action_settings);
    toolsSettingSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_PEN,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_PEN, R.string.editor_pen);
    mi.setIcon(R.drawable.ic_edit);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_TEXT,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_TEXT, R.string.editor_text);
    mi.setIcon(R.drawable.ic_text);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_SELECTION,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_SELECTION, R.string.editor_selection);
    mi.setIcon(R.drawable.ic_selection);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_ERASER,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_ERASER, R.string.editor_eraser);
    mi.setIcon(R.drawable.ic_eraser);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // ADD MENU
    SubMenu addSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ADD,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ADD, R.string.editor_add_menu);
    addSubMenu.setIcon(R.drawable.ic_add);
    addSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // IMAGE
    mi = addSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ADD_IMAGE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ADD_IMAGE, R.string.editor_add_image);
    mi.setIcon(R.drawable.ic_add_image);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // PAGES
    SubMenu pagesMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE, R.string.editor_pages);
    pagesMenu.setIcon(R.drawable.ic_pages);
    pagesMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_MOVE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_MOVE, R.string.editor_pages_move);
    mi.setIcon(R.drawable.ic_pages);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_ADD,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_ADD, R.string.editor_pages_add);
    mi.setIcon(R.drawable.ic_add_page);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_DELETE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_DELETE, R.string.editor_pages_remove);
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // EXTRA SETTINGS
    // SAVE
    mi = menu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SAVE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SAVE, R.string.editor_save);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    super.onCreateOptionsMenu(menu);

    return true;
}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void refreshNavigationMenu() {

    NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    final Menu menu = mNavigationView.getMenu();
    List<TransmartServer> connectedServers = getConnectedServers();

    menu.clear();// w w w  .jav  a 2  s.c  om

    int order = 0;
    int group = 1;

    SubMenu serverMenu = menu.addSubMenu(Menu.NONE, order, order, getString(R.string.menu_serversSubmenu));
    order += 1;

    for (TransmartServer transmartServer : connectedServers) {
        int menuItemID = serverMenu.add(group, order, order, transmartServer.getServerLabel())
                .setIcon(R.drawable.ic_action_accounts).getItemId();
        transmartServer.setMenuItemID(menuItemID);
        order += 1;
    }
    add_server_item = serverMenu.add(group, order, order, R.string.menu_addNewServer)
            .setIcon(R.drawable.ic_action_new_account).getItemId();
    order += 1;

    serverMenu.setGroupCheckable(group, true, true);

    about_item = menu.add(Menu.NONE, order, order, R.string.menu_about).setIcon(R.drawable.ic_action_about)
            .getItemId();
}

From source file:org.alfresco.mobile.android.application.fragments.browser.ChildrenBrowserFragment.java

public static void getMenu(AlfrescoSession session, Menu menu, Folder parentFolder, boolean actionMode) {
    MenuItem mi;//from w w w  .  j  a va  2  s  .  co m

    if (parentFolder == null) {
        return;
    }
    Permissions permission = null;
    try {
        permission = session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder);
    } catch (Exception e) {
        return;
    }

    if (!actionMode) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_SEARCH_FOLDER,
                Menu.FIRST + MenuActionItem.MENU_SEARCH_FOLDER, R.string.search);
        mi.setIcon(R.drawable.ic_search);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!actionMode && permission.canAddChildren()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_CREATE_FOLDER,
                Menu.FIRST + MenuActionItem.MENU_CREATE_FOLDER, R.string.folder_create);
        mi.setIcon(R.drawable.ic_add_folder);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        SubMenu createMenu = menu.addSubMenu(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE,
                Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE, R.string.add_menu);
        createMenu.setIcon(android.R.drawable.ic_menu_add);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        createMenu.add(Menu.NONE, MenuActionItem.MENU_UPLOAD, Menu.FIRST + MenuActionItem.MENU_UPLOAD,
                R.string.upload_title);

        createMenu.add(Menu.NONE, MenuActionItem.MENU_CREATE_DOCUMENT,
                Menu.FIRST + MenuActionItem.MENU_CREATE_DOCUMENT, R.string.create_document);

        createMenu.add(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO,
                Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO, R.string.take_photo);

        if (AndroidVersion.isICSOrAbove()) {
            createMenu.add(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO,
                    Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO, R.string.make_video);
        }

        createMenu.add(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO,
                Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO, R.string.record_audio);

    }

    if (actionMode) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_DETAILS, Menu.FIRST + MenuActionItem.MENU_DETAILS,
                R.string.action_view_properties);
        mi.setIcon(R.drawable.ic_details);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (actionMode && permission.canEdit()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_EDIT, Menu.FIRST + MenuActionItem.MENU_EDIT,
                R.string.edit);
        mi.setIcon(R.drawable.ic_edit);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (actionMode && permission.canDelete()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_DELETE, Menu.FIRST + MenuActionItem.MENU_DELETE,
                R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!actionMode) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_REFRESH, Menu.FIRST + MenuActionItem.MENU_REFRESH,
                R.string.refresh);
        mi.setIcon(R.drawable.ic_refresh);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:og.android.tether.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean supRetVal = super.onCreateOptionsMenu(menu);
    SubMenu setup = menu.addSubMenu(0, MENU_SETUP, 0, getString(R.string.main_activity_settings));
    setup.setIcon(drawable.ic_menu_preferences);
    if (this.application.accessControlSupported) {
        SubMenu accessctr = menu.addSubMenu(0, MENU_ACCESS, 0, getString(R.string.main_activity_accesscontrol));
        accessctr.setIcon(drawable.ic_menu_manage);
    }/*from  w w  w. j a v a 2s . c  om*/
    SubMenu connect = menu.addSubMenu(0, MENU_CONNECT, 0, getString(R.string.main_activity_connect));
    connect.setIcon(drawable.ic_menu_add);
    SubMenu log = menu.addSubMenu(0, MENU_LOG, 0, getString(R.string.main_activity_showlog));
    log.setIcon(drawable.ic_menu_agenda);
    SubMenu community = menu.addSubMenu(0, MENU_COMMUNITY, 0, getString(R.string.main_activity_community));
    community.setIcon(drawable.ic_menu_myplaces);
    SubMenu about = menu.addSubMenu(0, MENU_ABOUT, 0, getString(R.string.main_activity_about));
    about.setIcon(drawable.ic_menu_info_details);

    SubMenu twitter = menu.addSubMenu(0, MENU_TWITTER, 0, getString(R.string.main_activity_twitter));
    SubMenu facebook = menu.addSubMenu(0, MENU_FACEBOOK, 0, getString(R.string.main_activity_facebook));
    return supRetVal;
}

From source file:org.gdg.frisbee.android.common.GdgNavDrawerActivity.java

private void setupDrawerContent(NavigationView navigationView) {

    Menu menu = navigationView.getMenu();
    menu.add(GROUP_ID, Const.DRAWER_HOME, Menu.NONE, R.string.home_gdg).setIcon(R.drawable.ic_drawer_home_gdg);
    menu.add(GROUP_ID, Const.DRAWER_GDE, Menu.NONE, R.string.gde).setIcon(R.drawable.ic_drawer_gde);
    menu.add(GROUP_ID, Const.DRAWER_PULSE, Menu.NONE, R.string.pulse).setIcon(R.drawable.ic_drawer_pulse);

    //adding special events in navigation drawer
    final ArrayList<TaggedEventSeries> currentEventSeries = App.getInstance().currentTaggedEventSeries();
    for (TaggedEventSeries taggedEventSeries : currentEventSeries) {
        menu.add(GROUP_ID, taggedEventSeries.getDrawerId(), Menu.NONE, taggedEventSeries.getTitleResId())
                .setIcon(taggedEventSeries.getDrawerIconResId());
    }/*from   w  w w . j av a 2  s  . c  o  m*/

    SubMenu subMenu = menu.addSubMenu(GAMES_GROUP_ID, Const.DRAWER_SUBMENU_GAMES, Menu.NONE,
            R.string.drawer_subheader_games);
    subMenu.add(GAMES_GROUP_ID, Const.DRAWER_ACHIEVEMENTS, Menu.NONE, R.string.achievements)
            .setIcon(R.drawable.ic_drawer_achievements);
    subMenu.add(GAMES_GROUP_ID, Const.DRAWER_ARROW, Menu.NONE, R.string.arrow)
            .setIcon(R.drawable.ic_drawer_arrow).setCheckable(true);

    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_SETTINGS, Menu.NONE, R.string.settings)
            .setIcon(R.drawable.ic_drawer_settings);
    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_HELP, Menu.NONE, R.string.help).setIcon(R.drawable.ic_drawer_help);
    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_FEEDBACK, Menu.NONE, R.string.feedback)
            .setIcon(R.drawable.ic_drawer_feedback);
    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_ABOUT, Menu.NONE, R.string.about)
            .setIcon(R.drawable.ic_drawer_about);

    menu.setGroupCheckable(GROUP_ID, true, true);

    final int selectedDrawerItemId = getIntent().getIntExtra(EXTRA_SELECTED_DRAWER_ITEM_ID, Const.DRAWER_HOME);
    final MenuItem selectedItem = menu.findItem(selectedDrawerItemId);
    if (selectedItem != null) {
        selectedItem.setChecked(true);
    }

    navigationView.setNavigationItemSelectedListener(

            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    onDrawerItemClick(menuItem);
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
    View headerView = navigationView.getHeaderView(0);
    mDrawerImage = ButterKnife.findById(headerView, R.id.navdrawer_image);
    mDrawerUserPicture = ButterKnife.findById(headerView, R.id.navdrawer_user_picture);
}

From source file:org.alfresco.mobile.android.application.fragments.actions.NodeActions.java

protected void getMenu(FragmentActivity activity, Menu menu) {
    MenuItem mi;// w ww .j  a  va 2s.c o m
    SubMenu createMenu;

    if (selectedFolder.isEmpty()) {
        mi = menu.add(Menu.NONE, R.id.menu_action_download_all, Menu.FIRST, R.string.download);
        mi.setIcon(R.drawable.ic_download_light);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        removeActionIfNecessary(menu, mi.getItemId(), ConfigurableActionHelper.ACTION_NODE_DOWNLOAD);

        if (!(SessionUtils.getSession(activity) instanceof CloudSession)) {
            mi = menu.add(Menu.NONE, R.id.menu_workflow_review_attachments, Menu.FIRST + 500,
                    R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            removeActionIfNecessary(menu, mi.getItemId(), ConfigurableActionHelper.ACTION_NODE_REVIEW);
        }
    }

    // SYNC
    if (SyncContentManager.getInstance(getActivity()).hasActivateSync(getAccount())
            && !SyncContentManager.getInstance(getActivity()).isSynced(getAccount(), parentFolder)) {
        createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_sync_group, Menu.FIRST, R.string.sync);
        createMenu.setIcon(R.drawable.ic_sync_light);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        removeActionIfNecessary(menu, createMenu.getItem().getItemId(),
                ConfigurableActionHelper.ACTION_NODE_SYNC);

        createMenu.add(Menu.NONE, R.id.menu_action_sync_group_sync, Menu.FIRST + 1, R.string.sync);
        createMenu.add(Menu.NONE, R.id.menu_action_sync_group_unsync, Menu.FIRST + 2, R.string.unsync);
    }

    // FAVORITES
    createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_favorite_group, Menu.FIRST + 135,
            R.string.favorite);
    createMenu.setIcon(R.drawable.ic_favorite_light);
    createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    removeActionIfNecessary(menu, createMenu.getItem().getItemId(),
            ConfigurableActionHelper.ACTION_NODE_FAVORITE);

    createMenu.add(Menu.NONE, R.id.menu_action_favorite_group_favorite, Menu.FIRST + 1, R.string.favorite);
    createMenu.add(Menu.NONE, R.id.menu_action_favorite_group_unfavorite, Menu.FIRST + 2, R.string.unfavorite);

    // LIKE
    AlfrescoSession alfSession = SessionUtils.getSession(activity);
    if (alfSession != null && alfSession.getRepositoryInfo() != null
            && alfSession.getRepositoryInfo().getCapabilities() != null
            && alfSession.getRepositoryInfo().getCapabilities().doesSupportLikingNodes()) {
        createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_like_group, Menu.FIRST + 150, R.string.like);
        createMenu.setIcon(R.drawable.ic_like);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        removeActionIfNecessary(menu, createMenu.getItem().getItemId(),
                ConfigurableActionHelper.ACTION_NODE_LIKE);

        createMenu.add(Menu.NONE, R.id.menu_action_like_group_like, Menu.FIRST + 1, R.string.like);
        createMenu.add(Menu.NONE, R.id.menu_action_like_group_unlike, Menu.FIRST + 2, R.string.unlike);
    }

    if (parentFolder != null && ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(),
            parentFolder, ConfigurableActionHelper.ACTION_NODE_DELETE)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        removeActionIfNecessary(menu, mi.getItemId(), ConfigurableActionHelper.ACTION_NODE_DELETE);
    }
}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (!MainApplication.getInstance().settings.showSidePanel() && Build.VERSION.SDK_INT < 11) {
        menu.add(Menu.NONE, R.id.menu_open_close_drawer, Menu.FIRST, R.string.menu_open_drawer)
                .setIcon(R.drawable.ic_menu_windows);
    }/*from   ww w.j av a2  s. com*/
    if (tabsAdapter != null && tabsAdapter.getSelectedItem() >= 0) {
        TabModel tab = tabsAdapter.getItem(tabsAdapter.getSelectedItem());
        if (canFavorite(tab)) {
            menu.add(Menu.NONE, R.id.menu_favorites, 201, R.string.menu_add_favorites)
                    .setIcon(R.drawable.ic_menu_add_bookmark);
        }
        if (tab.webUrl != null) {
            menu.add(Menu.NONE, R.id.menu_open_browser, 202, R.string.menu_open_browser)
                    .setIcon(R.drawable.ic_menu_browser);
        }
    }
    menu.add(Menu.NONE, R.id.menu_settings, 203, R.string.menu_preferences)
            .setIcon(android.R.drawable.ic_menu_preferences);
    Menu subMenu = menu.addSubMenu(Menu.NONE, R.id.menu_sub_settings, 203, R.string.menu_preferences)
            .setIcon(android.R.drawable.ic_menu_preferences);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_suspend, 1, R.string.menu_sub_preferences_suspend);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_autoupdate, 2, R.string.menu_sub_preferences_autoupdate)
            .setCheckable(true);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_maskpictures, 3, R.string.menu_sub_preferences_maskpictures)
            .setCheckable(true);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_all, 4, R.string.menu_sub_preferences_all);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
public void onCreateOptionsMenu(Menu menu) {
    menu.add(0, OPTIONS_MENU_ADD_POST, 0, R.string.action_add_post).setIcon(obtainIcon(R.attr.actionAddPost))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, OPTIONS_MENU_SEARCH, 0, R.string.action_search);
    menu.add(0, OPTIONS_MENU_GALLERY, 0, R.string.action_gallery);
    menu.add(0, OPTIONS_MENU_SELECT, 0, R.string.action_select);
    menu.add(0, OPTIONS_MENU_REFRESH, 0, R.string.action_refresh).setIcon(obtainIcon(R.attr.actionRefresh))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.addSubMenu(0, OPTIONS_MENU_APPEARANCE, 0, R.string.action_appearance);
    SubMenu threadOptions = menu.addSubMenu(0, OPTIONS_MENU_THREAD_OPTIONS, 0, R.string.action_thread_options);
    menu.add(0, OPTIONS_MENU_ADD_TO_FAVORITES_TEXT, 0, R.string.action_add_to_favorites);
    menu.add(0, OPTIONS_MENU_REMOVE_FROM_FAVORITES_TEXT, 0, R.string.action_remove_from_favorites);
    menu.add(0, OPTIONS_MENU_ADD_TO_FAVORITES_ICON, 0, R.string.action_add_to_favorites)
            .setIcon(obtainIcon(R.attr.actionAddToFavorites)).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add(0, OPTIONS_MENU_REMOVE_FROM_FAVORITES_ICON, 0, R.string.action_remove_from_favorites)
            .setIcon(obtainIcon(R.attr.actionRemoveFromFavorites))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add(0, OPTIONS_MENU_OPEN_ORIGINAL_THREAD, 0, R.string.action_open_the_original);
    menu.add(0, OPTIONS_MENU_ARCHIVE, 0, R.string.action_archive_add);

    threadOptions.add(0, THREAD_OPTIONS_MENU_RELOAD, 0, R.string.action_reload);
    threadOptions.add(0, THREAD_OPTIONS_MENU_AUTO_REFRESH, 0, R.string.action_auto_refresh).setCheckable(true);
    threadOptions.add(0, THREAD_OPTIONS_MENU_HIDDEN_POSTS, 0, R.string.action_hidden_posts);
    threadOptions.add(0, THREAD_OPTIONS_MENU_CLEAR_DELETED, 0, R.string.action_clear_deleted);
    threadOptions.add(0, THREAD_OPTIONS_MENU_SUMMARY, 0, R.string.action_summary);
}

From source file:com.android.purenexussettings.TinkerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tinker);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w w  w  .j a  va  2 s  .  c o  m

    // set up some defaults
    boolean cLockInstalled;
    FRAG_ARRAY_START = getResources().getIntArray(R.array.nav_drawer_cat_nums)[0];
    mTitle = mDrawerTitle = getTitle();
    mPackageName = getPackageName();
    LAST_SLIDE_BAR_TAB = 0;
    mBackPress = false;
    mIgnoreBack = false;
    mFromClick = false;
    mMenu = false;
    fullyClosed = true;
    openingHalf = true;

    // for backstack tracking
    fragmentStack = new Stack<>();

    // check if cLock installed
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(KEY_LOCK_CLOCK_PACKAGE_NAME, 0);
        cLockInstalled = pi.applicationInfo.enabled;
    } catch (PackageManager.NameNotFoundException e) {
        cLockInstalled = false;
    }

    // load slide menu items - titles and frag names
    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
    navMenuFrags = getResources().getStringArray(R.array.nav_drawer_fragments);

    // nav drawer icons from resources
    TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mNavView = (NavigationView) findViewById(R.id.slidermenu);

    // create navigationview items
    Menu menu = mNavView.getMenu();
    // pulled in crap menu in xml, need to clear it first
    menu.clear();

    // pull in category names and numbers in each
    String[] navMenuCats = getResources().getStringArray(R.array.nav_drawer_cats);
    int[] navMenuCatCounts = getResources().getIntArray(R.array.nav_drawer_cat_nums);

    // set up some counters
    int j = 0;
    int total = 0;
    SubMenu submenu = null;
    // go through the total possible menu list
    for (int i = 0; i < navMenuTitles.length; i++) {
        // when the count equals a threshold value, increment/sum and add submenu
        if (i == (total + navMenuCatCounts[j])) {
            total += navMenuCatCounts[j];
            // format submenu headings
            SpannableString strcat = new SpannableString(navMenuCats[j]);
            strcat.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0,
                    strcat.length(), 0);
            strcat.setSpan(new RelativeSizeSpan(0.85f), 0, strcat.length(), 0);
            strcat.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, strcat.length(), 0);
            // is the 10 * (j + 1) bit needed...? Maybe not... meh
            submenu = menu.addSubMenu((j + 1), 10 * (j + 1), 10 * (j + 1), strcat);
            j++;
        }
        // assuming all are skipped before first submenu, only add menu items if total <> 0
        if (total > 0) {
            // format menu item title
            SpannableString stritem = new SpannableString(navMenuTitles[i]);
            stritem.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0,
                    stritem.length(), 0);
            // group id is j, i is item id and order..., then title - includes logic for conditional entries
            if (cLockInstalled || !(navMenuTitles[i].equals("cLock"))) {
                // an attempt to add icon if included...
                if (navMenuIcons.getResourceId(i, -1) != -1) {
                    submenu.add(j, i, i, stritem).setIcon(navMenuIcons.getResourceId(i, -1));
                } else {
                    submenu.add(j, i, i, stritem);
                }
            }
        }
    }

    // remove icon tint from NavView
    mNavView.setItemIconTintList(null);

    mNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            // check for external app launching navdrawer items
            if (navMenuTitles[item.getItemId()].equals("cLock")) {
                mIgnore = true;
                mDrawerLayout.closeDrawer(mNavView);
                launchcLock();
            }

            // if nothing was caught in the above, do the usual prep to show frag stuff
            if (!mIgnore) {
                mItemPosition = item.getItemId();
                mFromClick = true;
                setTitle(navMenuTitles[mItemPosition]);
                removeCurrent();
                mDrawerLayout.closeDrawer(mNavView);
            }

            return true;
        }
    });

    // Recycle the typed array
    navMenuIcons.recycle();

    // enabling action bar app icon and behaving it as toggle button
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        @Override
        public void onDrawerClosed(View view) {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mNavView);
            getSupportActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            openingHalf = true;
            invalidateOptionsMenu();
            // now that the drawer animation is done - load fragment
            if (mIgnore || !mFromClick) {
                mIgnore = false;
            } else {
                displayView(mItemPosition);
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            openingHalf = false;
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            fullyClosed = (slideOffset == 0.0f);
            if (slideOffset < 0.5f && !openingHalf) {
                openingHalf = true;
                invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
            } else if (slideOffset > 0.5f && openingHalf) {
                openingHalf = false;
                invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
            }
        }

    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    fragmentManager = getFragmentManager();

    if (savedInstanceState == null) {
        // on first time display view for first nav item
        displayView(mItemPosition = getIntent().getIntExtra(EXTRA_START_FRAGMENT, 0));
    }
}