Example usage for android.view SubMenu add

List of usage examples for android.view SubMenu add

Introduction

In this page you can find the example usage for android.view SubMenu add.

Prototype

public MenuItem add(int groupId, int itemId, int order, CharSequence title);

Source Link

Document

Add a new item to the menu.

Usage

From source file:cgeo.geocaching.cgeocaches.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_FILTER, 0, res.getString(R.string.caches_filter)).setIcon(R.drawable.ic_menu_filter);

    if (type != CacheListType.HISTORY) {
        menu.add(0, MENU_SORT, 0, res.getString(R.string.caches_sort))
                .setIcon(R.drawable.ic_menu_sort_alphabetically);
    }//from w ww  . j  a  v  a 2 s  .  c o m

    menu.add(0, MENU_SWITCH_SELECT_MODE, 0, res.getString(R.string.caches_select_mode))
            .setIcon(R.drawable.ic_menu_agenda);
    menu.add(0, MENU_INVERT_SELECTION, 0, res.getString(R.string.caches_select_invert))
            .setIcon(R.drawable.ic_menu_mark);
    if (type == CacheListType.OFFLINE) {
        SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_OFFLINE, 0, res.getString(R.string.caches_manage))
                .setIcon(R.drawable.ic_menu_save);
        subMenu.add(0, MENU_DROP_CACHES, 0, res.getString(R.string.caches_drop_all)); // delete saved caches
        subMenu.add(0, MENU_DROP_CACHES_AND_LIST, 0, res.getString(R.string.caches_drop_all_and_list));
        subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches
        subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
        subMenu.add(0, MENU_DELETE_EVENTS, 0, res.getString(R.string.caches_delete_events));
        subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs));

        //TODO: add submenu/AlertDialog and use R.string.gpx_import_title
        subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title));
        if (Settings.getWebDeviceCode() != null) {
            subMenu.add(0, MENU_IMPORT_WEB, 0, res.getString(R.string.web_import_title));
        }

        subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches
    } else {
        if (type == CacheListType.HISTORY) {
            SubMenu subMenu = menu
                    .addSubMenu(0, SUBMENU_MANAGE_HISTORY, 0, res.getString(R.string.caches_manage))
                    .setIcon(R.drawable.ic_menu_save);
            subMenu.add(0, MENU_REMOVE_FROM_HISTORY, 0, res.getString(R.string.cache_clear_history)); // remove from history
            subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches
            subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs));
            menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh))
                    .setIcon(R.drawable.ic_menu_set_as);
        } else {
            menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.caches_store_offline))
                    .setIcon(R.drawable.ic_menu_set_as); // download details for all caches
        }
    }

    navigationMenu = CacheListAppFactory.addMenuItems(menu, this, res);

    if (type == CacheListType.OFFLINE) {
        SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_LISTS, 0, res.getString(R.string.list_menu))
                .setIcon(R.drawable.ic_menu_more);
        subMenu.add(0, MENU_CREATE_LIST, 0, res.getString(R.string.list_menu_create));
        subMenu.add(0, MENU_DROP_LIST, 0, res.getString(R.string.list_menu_drop));
        subMenu.add(0, MENU_RENAME_LIST, 0, res.getString(R.string.list_menu_rename));
        subMenu.add(0, MENU_SWITCH_LIST, 0, res.getString(R.string.list_menu_change));
    }

    return true;
}

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

protected void getMenu(FragmentActivity activity, Menu menu) {
    MenuItem mi;//from   w  w  w.j  a  v a2 s  . 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.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  ww  .j a  v a  2s  .  c  om*/

    // 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));
    }
}

From source file:ca.spencerelliott.mercury.Changesets.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    int i = 0;//from w  ww.j a  v a  2s . co  m

    //Get the context menu info from the adapter
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    //Find which item has been selected
    last_item_touched = info.position;

    //Create the menu
    //menu.add(0, EMAIL_PERSON, ++i, R.string.changesets_link_contact);
    menu.add(0, VIEW_BROWSER, ++i, R.string.changesets_view_browser);//.setEnabled(!is_https);

    SubMenu link_menu = menu.addSubMenu(0, LINK_COMMITTER, ++i, R.string.changesets_link_contact);

    if (contacts_list == null) {
        //Create the contacts list
        contacts_list = new ArrayList<Map<String, String>>();

        //Store which columns are needed from the contact
        String[] columns = { People._ID, People.NAME };

        //Get the Uri to the contacts content provider
        Uri contacts = People.CONTENT_URI;

        //Run the query to get all of the contacts on the device
        Cursor all_contacts = managedQuery(contacts, columns, null, null, People.NAME + " ASC");

        //Store the column number of the name and id from the content provider
        int id_column = all_contacts.getColumnIndex(People._ID);
        int name_column = all_contacts.getColumnIndex(People.NAME);

        //If there are columns
        if (all_contacts.moveToFirst()) {
            //Loop through each contact and add them to the list
            do {
                //Create a new contact map
                Map<String, String> new_contact = new HashMap<String, String>();

                //Add the id and name to the map
                new_contact.put("id", all_contacts.getString(id_column));
                new_contact.put("name", all_contacts.getString(name_column));

                //Add the new contact to the list
                contacts_list.add(new_contact);
            } while (all_contacts.moveToNext());
        }
    }

    //Set count to -1 since the loop pre-increments the variable so the first
    //used value of count will be 0
    int count = -1;

    //Add all the contacts to the sub-menu
    for (Map<String, String> c : contacts_list) {
        link_menu.add(CONTACT_GROUP, Integer.parseInt(c.get("id")), ++count, c.get("name"));
    }
}

From source file:com.ichi2.anki2.Reviewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Resources res = getResources();

    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card,
            R.drawable.ic_menu_mark);//from w w w  . ja  va  2 s. c  om
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo,
            R.drawable.ic_menu_revert_disabled);
    UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card,
            R.drawable.ic_menu_edit);
    if (mPrefWhiteboard) {
        if (mShowWhiteboard) {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.hide_whiteboard, R.drawable.ic_menu_compose);
        } else {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.show_whiteboard, R.drawable.ic_menu_compose);
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE,
                R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist);
    }

    if (mPrefRecord) {
        // TODO proper icon
        final MenuItem recorderItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD, Menu.NONE,
                Recorder.recording() ? R.string.record_stop : R.string.record_start,
                R.drawable.ic_circle_pressed);
        final MenuItem replayItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD_REPLAY, Menu.NONE,
                R.string.record_play, R.drawable.ic_circle_normal);
        // disable unless something is recorded
        replayItem.setEnabled(false);
        // set relevant listeners
        Recorder.setRecordingStartedListener(new Recorder.RecordingStartedListener() {

            @Override
            public void onRecordingStarted() {
                recorderItem.setTitle(R.string.record_stop);
            }
        });
        Recorder.setRecordingFinishedListener(new Recorder.RecordingFinishedListener() {

            @Override
            public void onRecordingFinished() {
                recorderItem.setTitle(R.string.record_start);
                replayItem.setEnabled(true);
            }
        });
        Recorder.setRecorderResetListener(new Recorder.RecorderResetListener() {

            @Override
            public void onRecorderReset() {
                replayItem.setEnabled(false);
            }
        });
    }

    SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note);
    removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY, Menu.NONE, R.string.menu_bury_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note);
    if (mPrefTextSelection) {
        MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select));
        item.setIcon(R.drawable.ic_menu_search);
        item.setEnabled(Lookup.isAvailable());
    }
    return true;
}

From source file:com.nit.vicky.Reviewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Resources res = getResources();

    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card,
            R.drawable.ic_menu_mark);//  w  w w  .ja v a 2s  .  co  m
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo,
            R.drawable.ic_menu_revert_disabled);
    UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card,
            R.drawable.ic_menu_edit);

    if (mPrefWhiteboard) {
        if (mShowWhiteboard) {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.hide_whiteboard, R.drawable.ic_menu_compose);
        } else {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.show_whiteboard, R.drawable.ic_menu_compose);
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE,
                R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist);
    }

    SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note);
    removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_CARD, Menu.NONE, R.string.menu_bury_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_NOTE, Menu.NONE, R.string.menu_bury_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note);
    if (mPrefTextSelection) {
        MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select));
        item.setIcon(R.drawable.ic_menu_search);
        item.setEnabled(Lookup.isAvailable());
    }
    return true;
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //Logger.LogVerbose("OpenExplorer.onPrepareOptionsMenu");

    if (getClipboard() != null) {
        MenuUtils.setMenuChecked(menu, getClipboard().isMultiselect(), R.id.menu_multi);
        MenuUtils.setMenuVisible(menu, getClipboard().size() > 0, R.id.content_paste);
    } else/*  w w  w.ja  v a  2s.c  o m*/
        MenuUtils.setMenuVisible(menu, false, R.id.content_paste);

    MenuUtils.setMenuVisible(menu, IS_DEBUG_BUILD && !isBlackBerry(), R.id.menu_debug);

    if (!BEFORE_HONEYCOMB && USE_ACTION_BAR) {
        //MenuUtils.setMenuVisible(menu, false, R.id.title_menu);
        if (menu.findItem(R.id.menu_search) != null) {
            if (mSearchView == null)
                mSearchView = SearchViewCompat.newSearchView(this);
            MenuItem item = menu.findItem(R.id.menu_search);
            MenuItemCompat.setShowAsAction(item,
                    MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            MenuItemCompat.setActionView(item, mSearchView);
            if (mSearchView != null)
                SearchViewCompat.setOnQueryTextListener(mSearchView,
                        new SearchViewCompat.OnQueryTextListenerCompat() {
                            public boolean onQueryTextSubmit(String query) {
                                mSearchView.clearFocus();
                                Intent intent = new Intent();
                                intent.setAction(Intent.ACTION_SEARCH);
                                Bundle appData = new Bundle();
                                appData.putString("path", getDirContentFragment(false).getPath().getPath());
                                intent.putExtra(SearchManager.APP_DATA, appData);
                                intent.putExtra(SearchManager.QUERY, query);
                                handleIntent(intent);
                                return true;
                            }

                            public boolean onQueryTextChange(String newText) {
                                return false;
                            }
                        });
        }
    }

    MenuUtils.setMenuChecked(menu, USE_SPLIT_ACTION_BAR, R.id.menu_view_split);
    //MenuUtils.setMenuChecked(menu, mLogFragment != null && mLogFragment.isVisible(), R.id.menu_view_logview);
    MenuUtils.setMenuChecked(menu, getPreferences().getBoolean("global", "pref_fullscreen", false),
            R.id.menu_view_fullscreen);
    if (!getResources().getBoolean(R.bool.allow_fullscreen))
        MenuUtils.setMenuVisible(menu, false, R.id.menu_view_fullscreen);
    else
        MenuUtils.setMenuChecked(menu, IS_FULL_SCREEN, R.id.menu_view_fullscreen);
    if (getWindowWidth() < 500 && Build.VERSION.SDK_INT < 14) // ICS can split the actionbar
    {
        MenuUtils.setMenuShowAsAction(menu, 0 // Never
                , R.id.menu_sort, R.id.menu_view, R.id.menu_new_folder);
        MenuUtils.setMenuVisible(menu, true, R.id.menu_more);
    }

    //if(BEFORE_HONEYCOMB)
    {
        OpenFragment f = getSelectedFragment();
        if (f != null && f.hasOptionsMenu() && !f.isDetached() && f.isVisible())
            f.onPrepareOptionsMenu(menu);
    }

    if (menu != null && menu.findItem(R.id.content_paste) != null && getClipboard() != null
            && getClipboard().size() > 0) {
        SubMenu sub = menu.findItem(R.id.content_paste).getSubMenu();
        if (sub != null) {
            int i = 0;
            for (final OpenPath item : getClipboard().getAll()) {
                sub.add(Menu.CATEGORY_CONTAINER, i++, i, item.getName()).setCheckable(true).setChecked(true)
                        .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                            @Override
                            public boolean onMenuItemClick(MenuItem menuitem) {
                                getClipboard().remove(item);
                                return true;
                            }
                        }).setIcon(ThumbnailCreator.getDefaultResourceId(item, 32, 32));
            }
        }
    }

    if (!CAN_DO_CAROUSEL)
        MenuUtils.setMenuVisible(menu, false, R.id.menu_view_carousel);

    //if(BEFORE_HONEYCOMB)
    //   setupBaseBarButtons(menu, false);

    return true;
}