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:ca.nehil.rter.streamingapp2.StreamingActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    menu.add(0, 0, 0, "Start");
    return true;//w  w w .  j av  a  2  s . co m
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // ??/* www  . jav  a 2s .  c  om*/
    MenuItem actionItem = menu.add(Menu.NONE, MENU_ID.SETTING.ordinal(), MENU_ID.SETTING.ordinal(),
            this.getString(R.string.menu_title_setting));
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    actionItem.setIcon(MENU_ID.SETTING.getDrawableResId());

    // Twitter?
    actionItem = menu.add(Menu.NONE, MENU_ID.TWITTER.ordinal(), MENU_ID.TWITTER.ordinal(),
            this.getString(R.string.menu_title_share));
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    actionItem.setIcon(MENU_ID.TWITTER.getDrawableResId());

    // Facebook
    actionItem = menu.add(Menu.NONE, MENU_ID.FACEBOOK.ordinal(), MENU_ID.FACEBOOK.ordinal(),
            this.getString(R.string.menu_title_facebook));
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    actionItem.setIcon(MENU_ID.FACEBOOK.getDrawableResId());

    if (enableNewFunction) {
        // HISTORY
        actionItem = menu.add(Menu.NONE, MENU_ID.HISTORY.ordinal(), MENU_ID.HISTORY.ordinal(),
                this.getString(R.string.menu_title_history));
        actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        actionItem.setIcon(MENU_ID.HISTORY.getDrawableResId());

    }

    // LINE
    actionItem = menu.add(Menu.NONE, MENU_ID.LINE.ordinal(), MENU_ID.LINE.ordinal(),
            this.getString(R.string.menu_title_line));
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    actionItem.setIcon(MENU_ID.LINE.getDrawableResId());

    // FEEDBACK
    actionItem = menu.add(Menu.NONE, MENU_ID.FEEDBACK.ordinal(), MENU_ID.FEEDBACK.ordinal(),
            this.getString(R.string.menu_title_feedback));
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    actionItem.setIcon(MENU_ID.FEEDBACK.getDrawableResId());

    // LICENSE
    actionItem = menu.add(Menu.NONE, MENU_ID.LICENSE.ordinal(), MENU_ID.LICENSE.ordinal(),
            this.getString(R.string.menu_title_license));
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    actionItem.setIcon(MENU_ID.LICENSE.getDrawableResId());

    return true;
}

From source file:com.yacorso.nowaste.views.activities.DrawerActivity.java

private void loadNavItems() {
    int index = 0;
    Menu navigationMenu = navigationView.getMenu();
    navigationMenu.clear();//  w w w  . j  a  va  2s  .c  om
    navigationItems.clear();

    SubMenu fridgeSection = navigationMenu.addSubMenu(getText(R.string.menu_section_fridges));
    List<Fridge> fridges = currentUser.getFridges();
    for (Fridge fridge : fridges) {
        navigationItems.put(index, fridge);
        fridgeSection.add(0, index++, 0, fridge.getName()).setIcon(R.drawable.ic_fridge);
    }

    SubMenu customListSection = navigationMenu.addSubMenu(getText(R.string.menu_section_custom_lists));
    List<CustomList> customLists = currentUser.getCustomLists();

    for (CustomList customList : customLists) {
        navigationItems.put(index, customList);
        customListSection.add(1, index++, 0, customList.getName()).setIcon(R.drawable.ic_folder);
    }

    navigationMenu.add(2, index++, 0, R.string.menu_add_foodlist).setIcon(R.drawable.ic_add_circle_white);
    navigationMenu.add(3, index, 0, R.string.menu_title_settings).setIcon(R.drawable.ic_setting_dark);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getGroupId() < 2) {
                changeFragment(menuItem.getItemId(), true);
            } else if (menuItem.getGroupId() == 2) {
                launchDialog(ChooseTypeFoodListDialog.newInstance());
            } else if (menuItem.getGroupId() == 3) {
                changeFragment(menuItem.getItemId(), false);
            }

            return true;
        }
    });

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
}

From source file:ca.nehil.rter.streamingapp.StreamingActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    menu.add(0, 0, 0, "Start");
    return true;/*w w  w.  j ava 2s.  c  o m*/
}

From source file:com.recipewizard.recipewizard.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // only show options menu on portrait view
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_main_actions, menu);
    menu.add(Menu.NONE, MENU_RESET_INGREDIENTS, Menu.NONE,
            getResources().getString(R.string.reset_ingredient_list));
    return true;//from  w w w.  j  a v a  2  s  .  co m
}

From source file:com.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java

/**
 * Run during fragment initialization, this sets up the song info popup menu.
 *
 * @param view The view in which to setup the song info View for this class.
 * @return The song info view used as a field in this class.
 *//*  ww w  .  ja v  a  2  s .  c  om*/
private View getSongInfo(final View view) {
    final View songInfo = view.findViewById(R.id.songInfo);

    final PopupMenu popupMenu = new PopupMenu(mActivity, songInfo);
    final Menu menu = popupMenu.getMenu();
    menu.add(Menu.NONE, POPUP_ALBUM, Menu.NONE, R.string.goToAlbum);
    menu.add(Menu.NONE, POPUP_ARTIST, Menu.NONE, R.string.goToArtist);
    menu.add(Menu.NONE, POPUP_ALBUM_ARTIST, Menu.NONE, R.string.goToAlbumArtist);
    menu.add(Menu.NONE, POPUP_FOLDER, Menu.NONE, R.string.goToFolder);
    menu.add(Menu.NONE, POPUP_CURRENT, Menu.NONE, R.string.goToCurrent);
    menu.add(Menu.NONE, POPUP_SHARE, Menu.NONE, R.string.share);
    popupMenu.setOnMenuItemClickListener(this);
    mPopupMenuTouchListener = PopupMenuCompat.getDragToOpenListener(popupMenu);

    final PopupMenu popupMenuStream = new PopupMenu(mActivity, songInfo);
    final Menu menuStream = popupMenuStream.getMenu();
    menuStream.add(Menu.NONE, POPUP_STREAM, Menu.NONE, R.string.goToStream);
    menuStream.add(Menu.NONE, POPUP_CURRENT, Menu.NONE, R.string.goToCurrent);
    menuStream.add(Menu.NONE, POPUP_SHARE, Menu.NONE, R.string.share);
    popupMenuStream.setOnMenuItemClickListener(this);
    mPopupMenuStreamTouchListener = PopupMenuCompat.getDragToOpenListener(popupMenuStream);

    songInfo.setOnClickListener(new OnClickListener() {

        /**
         * Checks whether the album artist should be on the popup menu for the current track.
         *
         * @return True if the album artist popup menu entry should be visible, false otherwise.
         */
        private boolean isAlbumArtistVisible() {
            boolean albumArtistEnabled = false;
            final String albumArtist = mCurrentSong.getAlbumArtist();

            if (albumArtist != null && !albumArtist.isEmpty()) {
                final String artist = mCurrentSong.getArtist();

                if (isArtistVisible() && !albumArtist.equals(artist)) {
                    albumArtistEnabled = true;
                }
            }

            return albumArtistEnabled;
        }

        /**
         * Checks whether the album should be on the popup menu for the current track.
         *
         * @return True if the album popup menu entry should be visible, false otherwise.
         */
        private boolean isAlbumVisible() {
            final boolean isAlbumVisible;
            final String album = mCurrentSong.getAlbum();

            if (album != null && !album.isEmpty()) {
                isAlbumVisible = true;
            } else {
                isAlbumVisible = false;
            }

            return isAlbumVisible;
        }

        /**
         * Checks whether the artist should be on the popup menu for the current track.
         *
         * @return True if the artist popup menu entry should be visible, false otherwise.
         */
        private boolean isArtistVisible() {
            final boolean isArtistVisible;
            final String artist = mCurrentSong.getArtist();

            if (artist != null && !artist.isEmpty()) {
                isArtistVisible = true;
            } else {
                isArtistVisible = false;
            }

            return isArtistVisible;
        }

        /**
         * This method checks the dynamic entries for visibility prior to showing the song info
         * popup menu.
         *
         * @param v The view for the song info popup menu.
         */
        @Override
        public void onClick(final View v) {
            if (mCurrentSong != null) {
                if (mCurrentSong.isStream()) {
                    popupMenuStream.show();
                } else {
                    // Enable / Disable menu items that need artist and album defined.
                    menu.findItem(POPUP_ALBUM).setVisible(isAlbumVisible());
                    menu.findItem(POPUP_ARTIST).setVisible(isArtistVisible());
                    menu.findItem(POPUP_ALBUM_ARTIST).setVisible(isAlbumArtistVisible());
                    popupMenu.show();
                }
            }
        }
    });

    return songInfo;
}

From source file:com.inovex.zabbixmobile.activities.BaseActivity.java

private void toggleServerSelectionMode() {
    Menu menu = mNavigationView.getMenu();
    if (mServerSelectMode) {
        // show normal menu
        menu.setGroupVisible(R.id.grp1, true);
        menu.setGroupVisible(R.id.grp2, true);
        menu.removeGroup(R.id.grp0_server);
        mServerSelectButton.setImageDrawable(getResources().getDrawable(R.drawable.spinner_triangle));

    } else {//  w ww.  ja va 2s .  c  o  m
        // show server selection list
        menu.setGroupVisible(R.id.grp1, false);
        menu.setGroupVisible(R.id.grp2, false);
        for (int i = 0; i < mServersListAdapter.getCount(); i++) {
            ZabbixServer server = mServersListAdapter.getItem(i);
            menu.add(R.id.grp0_server, (int) server.getId(), Menu.NONE, server.getName())
                    .setIcon(R.drawable.ic_monitor_grey600_24dp);
        }
        mServerSelectButton.setImageDrawable(getResources().getDrawable(R.drawable.spinner_triangle_flipped));
    }
    mServerSelectMode = !mServerSelectMode;
}

From source file:org.openremote.android.console.GroupActivity.java

/**
 * If there have global or local tabbar, create and update menu before the menu is shown.
 * /*w ww .  j a  v a  2s  .c  o m*/
 * @see android.app.Activity#onPrepareOptionsMenu(android.view.Menu)
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (currentGroupView == null || currentGroupView.getGroup() == null) {
        return true;
    }
    TabBar tabBar = currentGroupView.getGroup().getTabBar();
    if (tabBar == null) {
        tabBar = XMLEntityDataBase.globalTabBar;
    }
    if (tabBar != null && tabBar.getTabBarItems().size() > 0) {
        menu.clear();
        ArrayList<TabBarItem> items = tabBar.getTabBarItems();
        int itemSize = items.size();
        for (int i = 0; i < itemSize; i++) {
            MenuItem menuItem = menu.add(0, i, i, items.get(i).getName());
            if (items.get(i).getImage() != null) {
                menuItem.setIcon(ImageUtil
                        .createFromPathQuietly(Constants.FILE_FOLDER_PATH + items.get(i).getImage().getSrc()));
            }
            final Navigate navigate = items.get(i).getNavigate();
            if (navigate != null) {
                menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        handleNavigate(navigate);
                        return true;
                    }

                });
            }
        }
    }
    return true;
}

From source file:lewa.support.v7.internal.widget.ActionBarContextView.java

private void initTitle() {
    if (!lewaInitTitle()) {
        if (mTitleLayout == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            inflater.inflate(R.layout.action_bar_title_item_with_spinner, this);
            //inflater.inflate(R.layout.abc_action_bar_title_item, this);
            mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1);
            // mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
            // mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
            // if (mTitleStyleRes != 0) {
            // mTitleView.setTextAppearance(mContext, mTitleStyleRes);
            // }/*w  ww.j  a v  a2s  .com*/
            // if (mSubtitleStyleRes != 0) {
            // mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
            // }

            mSpinner = (Button) mTitleLayout.findViewById(R.id.action_bar_spinner);
            mSpinner.setText("One item selected");

            final PopupMenu popMenu = new PopupMenu(mContext, mSpinner);
            final Menu menu = popMenu.getMenu();
            menu.add(Menu.NONE, android.R.id.selectAll, Menu.NONE, android.R.string.selectAll);
            popMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    if (null != mActionMode) {
                        if (mActionMode instanceof ActionModeImpl) {
                            return ((ActionModeImpl) mActionMode).onMenuItemSelected((MenuBuilder) menu, item);
                        }
                        if (mActionMode instanceof StandaloneActionMode) {
                            return ((StandaloneActionMode) mActionMode).onMenuItemSelected((MenuBuilder) menu,
                                    item);
                        }
                        // Woody Guo @ 2012/12/18: State of the selection menu item
                        // is totally controlled by the calling client
                        /*
                         * mActionMode.setSelectionMode(
                         *         ActionMode.SELECT_ALL == mActionMode.getSelectionMode()
                         *         ? ActionMode.SELECT_NONE : ActionMode.SELECT_ALL);
                         * item.setTitle(ActionMode.SELECT_ALL == mActionMode.getSelectionMode()
                         *         ? android.R.string.selectAll : R.string.selectNone);
                         * return true;
                         */
                    }
                    return false;
                }
            });

            mSpinner.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    popMenu.getMenu().getItem(0)
                            .setTitle(ActionMode.SELECT_ALL == mActionMode.getSelectionMode()
                                    ? android.R.string.selectAll
                                    : R.string.selectNone);
                    popMenu.show();
                }
            });
        }

        mSpinner.setText(mTitle);
    }
    if (true) {
        if (mTitleView != null) {
            mTitleView.setText(mTitle);
        }
        //mSubtitleView.setText(mSubtitle);
    }
    final boolean hasTitle = !TextUtils.isEmpty(mTitle);
    //final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle);
    //mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE);
    //mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE);
    mTitleLayout.setVisibility(hasTitle ? VISIBLE : GONE);
    if (mTitleLayout.getParent() == null) {
        addView(mTitleLayout);
    }
}

From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //    MenuInflater inflater = getMenuInflater();
    //    inflater.inflate(R.menu.options_menu, menu);
    super.onCreateOptionsMenu(menu);
    menu.add(0, SETTINGS_ID, 0, "Settings").setIcon(android.R.drawable.ic_menu_preferences);
    menu.add(0, ABOUT_ID, 0, "About").setIcon(android.R.drawable.ic_menu_info_details);
    return true;//from   w ww.  j  ava  2s .c  o m
}