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(@StringRes int titleRes);

Source Link

Document

Add a new item to the menu.

Usage

From source file:app.sunstreak.yourpisd.ClassSwipeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.class_swipe_actions, menu);

    if (termIndex == 0)
        menu.findItem(R.id.previous_six_weeks).setEnabled(false);
    else if (termIndex == 7)
        menu.findItem(R.id.next_six_weeks).setEnabled(false);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == studentIndex)
                item.setEnabled(false);/*  ww  w.jav a 2 s . c o  m*/

            item.setOnMenuItemClickListener(new StudentSelectListener(i));
            item.setVisible(true);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.android.contactslist.ui.chartActivity.ContactDetailChartFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    // Inflates the options menu for this fragment
    inflater.inflate(R.menu.contact_detail_menu, menu);

    // Gets a handle to the "find" menu item
    mEditContactMenuItem = menu.findItem(R.id.menu_edit_contact);

    // If contactUri is null the edit menu item should be hidden, otherwise
    // it is visible.
    mEditContactMenuItem.setVisible(mContactUri != null);

    // add the last settings menu to the end of the action bar
    MenuItem settingsItem = menu.add(getResources().getString(R.string.action_bar_overflow_settings));
}

From source file:io.puzzlebox.bloom.ui.BloomFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    menu.add("Share").setOnMenuItemClickListener(this.mShareButtonClickListener)
            .setIcon(android.R.drawable.ic_menu_share).setShowAsAction(SHOW_AS_ACTION_ALWAYS);

    super.onCreateOptionsMenu(menu, inflater);

}

From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from   ww w  .  j  a v a 2 s  .  c o m
    menu.add(R.string.settings);
    if (prefs.showPhotos) {
        menu.add(R.string.turn_off_photos);
    } else {
        menu.add(R.string.turn_on_photos);
    }
    menu.add(R.string.help);

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.example.android.contactslist.ui.eventEntry.EventEntryFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    // Inflates the options menu for this fragment
    inflater.inflate(R.menu.event_entry_menu, menu);

    // add the last settings menu to the end of the action bar
    MenuItem settingsItem = menu.add(getResources().getString(R.string.action_bar_overflow_settings));
}

From source file:app.sunstreak.yourpisd.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_activity, menu);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == session.studentIndex)
                item.setEnabled(false);/*from   w ww . j  a v  a  2s  .com*/

            item.setOnMenuItemClickListener(new StudentChooserListener(i));
            item.setVisible(true);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java

/**
 * Create the options menu that displays the refresh and about options
 *//*from   www.  j a  v  a  2  s . co  m*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (Constants.DEBUG) {
        MenuItem item = menu.add(getString(R.string.test_results));
        item.setIntent(new Intent(this, TestResultsTabActivity.class));
    }

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return true;
}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {

    if (PreferenceManager.getDefaultSharedPreferences(this)
            .getBoolean(getString(R.string.showPrevNextButtonsKey), true)) {
        // Next word.
        nextWordMenuItem = menu.add(getString(R.string.nextWord)).setIcon(R.drawable.arrow_down_float);
        MenuItemCompat.setShowAsAction(nextWordMenuItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        nextWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override/*from   w ww .ja  va  2s.c om*/
            public boolean onMenuItemClick(MenuItem item) {
                onUpDownButton(false);
                return true;
            }
        });

        // Previous word.
        previousWordMenuItem = menu.add(getString(R.string.previousWord)).setIcon(R.drawable.arrow_up_float);
        MenuItemCompat.setShowAsAction(previousWordMenuItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        previousWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                onUpDownButton(true);
                return true;
            }
        });
    }

    randomWordMenuItem = menu.add(getString(R.string.randomWord));
    randomWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            onRandomWordButton();
            return true;
        }
    });

    application.onCreateGlobalOptionsMenu(this, menu);

    {
        final MenuItem dictionaryManager = menu.add(getString(R.string.dictionaryManager));
        MenuItemCompat.setShowAsAction(dictionaryManager, MenuItem.SHOW_AS_ACTION_NEVER);
        dictionaryManager.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(final MenuItem menuItem) {
                startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
                finish();
                return false;
            }
        });
    }

    {
        final MenuItem aboutDictionary = menu.add(getString(R.string.aboutDictionary));
        MenuItemCompat.setShowAsAction(aboutDictionary, MenuItem.SHOW_AS_ACTION_NEVER);
        aboutDictionary.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(final MenuItem menuItem) {
                final Context context = getListView().getContext();
                final Dialog dialog = new Dialog(context);
                dialog.setContentView(R.layout.about_dictionary_dialog);
                final TextView textView = (TextView) dialog.findViewById(R.id.text);

                final String name = application.getDictionaryName(dictFile.getName());
                dialog.setTitle(name);

                final StringBuilder builder = new StringBuilder();
                final DictionaryInfo dictionaryInfo = dictionary.getDictionaryInfo();
                dictionaryInfo.uncompressedBytes = dictFile.length();
                if (dictionaryInfo != null) {
                    builder.append(dictionaryInfo.dictInfo).append("\n\n");
                    builder.append(getString(R.string.dictionaryPath, dictFile.getPath())).append("\n");
                    builder.append(getString(R.string.dictionarySize, dictionaryInfo.uncompressedBytes))
                            .append("\n");
                    builder.append(getString(R.string.dictionaryCreationTime, dictionaryInfo.creationMillis))
                            .append("\n");
                    for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
                        builder.append("\n");
                        builder.append(getString(R.string.indexName, indexInfo.shortName)).append("\n");
                        builder.append(getString(R.string.mainTokenCount, indexInfo.mainTokenCount))
                                .append("\n");
                    }
                    builder.append("\n");
                    builder.append(getString(R.string.sources)).append("\n");
                    for (final EntrySource source : dictionary.sources) {
                        builder.append(getString(R.string.sourceInfo, source.getName(), source.getNumEntries()))
                                .append("\n");
                    }
                }
                textView.setText(builder.toString());

                dialog.show();
                final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
                layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(layoutParams);
                return false;
            }
        });
    }

    return true;
}

From source file:knayi.delevadriver.AvaliableJobDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem item = menu.add("Icon");
    item.setIcon(R.drawable.deleva_dispatcher_white_noeffects_04);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

private void setupActionModeCallback() {
    mActionModeCallbackV7 = new Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override/* www.j  a va  2s.  co  m*/
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onCreateActionMode");
            }

            if (mode == null && torrentListAdapter.getCheckedItemCount() == 0
                    && torrentListAdapter.getSelectedPosition() < 0) {
                return false;
            }

            Menu origMenu = menu;
            if (tb != null) {
                menu = tb.getMenu();
            }
            if (mode != null) {
                mActionMode = (mode instanceof ActionModeWrapperV7) ? mode
                        : new ActionModeWrapperV7(mode, tb, getActivity());

                mActionMode.setTitle(R.string.context_torrent_title);
            }
            ActionBarToolbarSplitter.buildActionBar(getActivity(), this, R.menu.menu_context_torrent_details,
                    menu, tb);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onCreateActionMode(mode, menu);
            }

            if (sideListArea == null) {
                SubMenu subMenu = origMenu.addSubMenu(R.string.menu_global_actions);
                subMenu.setIcon(R.drawable.ic_menu_white_24dp);
                MenuItemCompat.setShowAsAction(subMenu.getItem(), MenuItemCompat.SHOW_AS_ACTION_NEVER);

                try {
                    // Place "Global" actions on top bar in collapsed menu
                    MenuInflater mi = mode == null ? getActivity().getMenuInflater() : mode.getMenuInflater();
                    mi.inflate(R.menu.menu_torrent_list, subMenu);
                    onPrepareOptionsMenu(subMenu);
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG, e.getMessage());
                    menu.removeItem(subMenu.getItem().getItemId());
                }
            }

            if (AndroidUtils.usesNavigationControl()) {
                MenuItem add = origMenu.add(R.string.select_multiple_items);
                add.setCheckable(true);
                add.setChecked(torrentListAdapter.isMultiCheckMode());
                add.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        boolean turnOn = !torrentListAdapter.isMultiCheckModeAllowed();

                        torrentListAdapter.setMultiCheckModeAllowed(turnOn);
                        if (turnOn) {
                            torrentListAdapter.setMultiCheckMode(turnOn);
                            torrentListAdapter.setItemChecked(torrentListAdapter.getSelectedPosition(), true);
                        }
                        return true;
                    }
                });
            }

            return true;
        }

        // Called each time the action mode is shown. Always called after
        // onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "MULTI:onPrepareActionMode " + mode);
            }
            if (tb != null) {
                menu = tb.getMenu();
            }

            // Must be called first, because our drawer sets all menu items
            // visible.. :(
            getActivity().onPrepareOptionsMenu(menu);

            prepareContextMenu(menu);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onPrepareActionMode(mode, menu);
            }

            AndroidUtils.fixupMenuAlpha(menu);

            return true;
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onActionItemClicked " + item.getTitle());
            }

            if (TorrentListFragment.this.handleFragmentMenuItems(item.getItemId())) {
                return true;
            }
            if (getActivity().onOptionsItemSelected(item)) {
                return true;
            }
            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                if (frag.onActionItemClicked(mode, item)) {
                    return true;
                }
            }
            return false;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onDestroyActionMode. BeingReplaced?" + actionModeBeingReplaced);
            }

            mActionMode = null;

            if (!actionModeBeingReplaced) {
                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        torrentListAdapter.setMultiCheckMode(false);
                        torrentListAdapter.clearChecked();
                        updateCheckedIDs();
                    }
                });

                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.actionModeBeingReplacedDone();
                        }
                    }
                });

                listview.setLongClickable(true);
                listview.requestLayout();
                AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
            }
        }
    };
}