Example usage for android.view Menu add

List of usage examples for android.view Menu add

Introduction

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

Prototype

public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

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

Usage

From source file:org.alfresco.mobile.android.application.accounts.fragment.AccountDetailsFragment.java

public void getMenu(Menu menu) {
    MenuItem mi;/*www .  ja v  a 2 s.co m*/

    if (acc.getActivation() == null) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_ACCOUNT_EDIT,
                Menu.FIRST + MenuActionItem.MENU_ACCOUNT_EDIT,
                String.format(getString(R.string.account_edit_hint), acc.getDescription()));
        mi.setIcon(R.drawable.ic_edit);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    mi = menu.add(Menu.NONE, MenuActionItem.MENU_ACCOUNT_DELETE,
            Menu.FIRST + MenuActionItem.MENU_ACCOUNT_DELETE,
            String.format(getString(R.string.account_delete_hint), acc.getDescription()));
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

From source file:com.robertcm.romcontrol.project.MainActivity.java

private void setUpPrefsMenu(Menu navigationMenu) {
    String[] titles = getResources().getStringArray(R.array.nav_menu_prefs_titles);
    TypedArray iconIds = getResources().obtainTypedArray(R.array.nav_menu_prefs_drawables);
    mNavMenuItemsIds = new ArrayList<>();
    for (int i = 0; i < titles.length; i++) {
        Integer id = View.generateViewId();
        mNavMenuItemsIds.add(id);//from  w w w .  jav a 2 s.c  o m
        MenuItem item = navigationMenu.add(Menu.NONE, id, 0, titles[i]).setIcon(iconIds.getResourceId(i, -1));
        if (titles[i] != null && titles[i].equals(getTitle().toString())) {
            item.setChecked(true);
        }
    }
    iconIds.recycle();
    navigationMenu.setGroupCheckable(Menu.NONE, true, true);
}

From source file:com.getchute.android.photopickerplus.ui.activity.ServicesActivity.java

@SuppressLint("NewApi")
@Override/*  w w  w .  j a  v  a 2  s .c om*/
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    if (PhotoPicker.getInstance().hasLogoutOption()) {
        MenuItem item = menu.add(0, LOGOUT_ITEM, 0, R.string.button_navigation_services_logout);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
    return true;

}

From source file:org.alfresco.mobile.android.application.fragments.favorites.FavoritesSyncFragment.java

public void getMenu(Menu menu) {
    info = SyncScanInfo.getLastSyncScanData(getActivity(), acc);
    if (info != null && (info.hasWarning() && !info.hasResponse())) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_SYNC_WARNING,
                Menu.FIRST + MenuActionItem.MENU_SYNC_WARNING, R.string.sync_warning);
        mi.setIcon(R.drawable.ic_warning);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }//w ww . java2  s  . com

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

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem itemUpdate = menu.add(Menu.NONE, R.id.menu_update, 101, resources.getString(R.string.menu_update));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        itemUpdate.setIcon(ThemeUtils.getActionbarIcon(activity.getTheme(), resources, R.attr.actionRefresh));
        CompatibilityImpl.setShowAsActionIfRoom(itemUpdate);
    } else {//from www.  j a va 2  s .  co m
        itemUpdate.setIcon(R.drawable.ic_menu_refresh);
    }

    if (quickAccessList == null)
        return;
    for (QuickAccess.Entry entry : quickAccessList)
        if (entry.boardName == null && entry.chan != null
                && entry.chan.getChanName().equals(chan.getChanName()))
            return;
    menu.add(Menu.NONE, R.id.menu_quickaccess_add, 102, resources.getString(R.string.menu_quickaccess_add))
            .setIcon(R.drawable.ic_menu_add_bookmark);
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.FileActions.java

private void getMenu(Menu menu) {
    menu.clear();/* w w w .  j av a2 s  .c o  m*/

    MenuItem mi;

    if (getFragment() instanceof ListingModeFragment) {
        switch (((ListingModeFragment) getFragment()).getMode()) {
        case FileExplorerFragment.MODE_LISTING:
            if (selectedFolder.isEmpty()) {
                mi = menu.add(Menu.NONE, R.id.menu_upload, Menu.FIRST + 30, R.string.upload);
                mi.setIcon(R.drawable.ic_upload);
                mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

                mi = menu.add(Menu.NONE, R.id.menu_action_share, Menu.FIRST + 100, R.string.share);
                mi.setIcon(R.drawable.ic_share);
                mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            }

            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);
            break;

        case FileExplorerFragment.MODE_PICK:

            if (selectedFolder.isEmpty()) {
                mi = menu.add(Menu.NONE, R.id.menu_file_send, Menu.FIRST, R.string.action_upload);
                mi.setIcon(R.drawable.ic_upload);
                mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_ALWAYS);
            }

            break;

        default:
            break;
        }
        mi = menu.add(Menu.NONE, R.id.menu_select_all, Menu.FIRST + 200, R.string.select_all);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }
}

From source file:net.simonvt.cathode.ui.fragment.EpisodeFragment.java

private void createMenu(Toolbar toolbar) {
    Menu menu = toolbar.getMenu();
    menu.clear();/*from w w  w  .ja  v a 2  s  . c o  m*/

    toolbar.inflateMenu(R.menu.activity_base);

    if (loaded) {
        if (checkedIn) {
            menu.add(0, R.id.action_checkin_cancel, 1, R.string.action_checkin_cancel)
                    .setIcon(R.drawable.ic_action_cancel).setShowAsActionFlags(
                            isTablet ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_ALWAYS);
        } else if (!watching) {
            menu.add(0, R.id.action_checkin, 2, R.string.action_checkin).setIcon(R.drawable.ic_action_checkin)
                    .setShowAsActionFlags(
                            isTablet ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_ALWAYS);
        }

        if (watched) {
            menu.add(0, R.id.action_unwatched, 3, R.string.action_unwatched);
        } else {
            menu.add(0, R.id.action_watched, 4, R.string.action_watched);
            if (inWatchlist) {
                menu.add(0, R.id.action_watchlist_remove, 5, R.string.action_watchlist_remove);
            } else {
                menu.add(0, R.id.action_watchlist_add, 6, R.string.action_watchlist_add);
            }
        }

        if (collected) {
            menu.add(0, R.id.action_collection_remove, 7, R.string.action_collection_remove);
        } else {
            menu.add(0, R.id.action_collection_add, 8, R.string.action_collection_add);
        }
    }
}

From source file:com.mishiranu.dashchan.ui.gallery.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    ActionIconSet set = new ActionIconSet(this);
    menu.add(0, OPTIONS_MENU_SAVE, 0, R.string.action_save).setIcon(set.getId(R.attr.actionSave))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, OPTIONS_MENU_GALLERY, 0, R.string.action_gallery);
    menu.add(0, OPTIONS_MENU_REFRESH, 0, R.string.action_refresh).setIcon(set.getId(R.attr.actionRefresh))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, OPTIONS_MENU_TECHNICAL_INFO, 0, R.string.action_technical_info);
    menu.add(0, OPTIONS_MENU_SEARCH_IMAGE, 0, R.string.action_search_image);
    menu.add(0, OPTIONS_MENU_COPY_LINK, 0, R.string.action_copy_link);
    menu.add(0, OPTIONS_MENU_NAVIGATE_POST, 0, R.string.action_go_to_post);
    menu.add(0, OPTIONS_MENU_SHARE_LINK, 0, R.string.action_share_link);
    menu.add(0, OPTIONS_MENU_SHARE_FILE, 0, R.string.action_share_file);
    menu.add(0, OPTIONS_MENU_SELECT, 0, R.string.action_select).setIcon(set.getId(R.attr.actionSelect))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    actionMenuConfigurator.onAfterCreateOptionsMenu(menu);
    return true;/*from  ww w . ja v a 2s  .c om*/
}

From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java

/*******************************************************************/

@Override/*from   w ww.  ja  va2s .c  o  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    MenuItem item;
    item = menu.add(ContextMenu.NONE, MENU_SEARCH, ContextMenu.NONE, android.R.string.search_go)
            .setIcon(R.drawable.ic_search_24dp).setAlphabeticShortcut(SearchManager.MENU_KEY);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    item = menu.add(ContextMenu.NONE, MENU_PICKER, ContextMenu.NONE, R.string.menu_picker)
            .setIcon(R.drawable.ic_import_24dp);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    item = menu.add(ContextMenu.NONE, MENU_VACUUM, ContextMenu.NONE, R.string.menu_vacuum)
            .setIcon(android.R.drawable.ic_menu_crop);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_NEVER);
    return result;
}

From source file:com.andybotting.tubechaser.activity.StationDetail.java

/**
 * Create the options menu//from www .  ja  va 2s . c o m
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    menu.add(0, MENU_REFRESH, 0, R.string.menu_item_refresh).setIcon(R.drawable.ic_menu_refresh);

    menu.add(0, MENU_STAR, 0, "") // Set in onMenuOpened
            .setIcon(R.drawable.ic_menu_star);

    menu.add(0, MENU_MAP, 0, R.string.menu_item_map).setIcon(R.drawable.ic_menu_mapmode);

    return true;
}