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:com.gmail.at.faint545.fragments.HistoryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from   w  ww  . j a  va  2  s .  com
    /* Only show these two options if there are jobs to delete */
    if (mSelectedPositions.size() > 0 && mOldJobs.size() > 0) {
        menu.add(Menu.NONE, DELETE, Menu.NONE, "Delete selected");
    } else if (mOldJobs.size() > 0) {
        menu.add(Menu.NONE, DELETE, Menu.NONE, "Delete all");
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:com.wheelly.fragments.LocationsMapFragment.java

@SuppressWarnings("deprecation")
@Override//from w w w .  java  2  s. co m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuCompat.setShowAsAction(
            menu.add(Menu.NONE, 1, Menu.NONE, R.string.item_add).setIcon(android.R.drawable.ic_menu_add),
            MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

From source file:net.idlesoft.android.apps.github.activities.SingleActivityItem.java

public boolean onPrepareOptionsMenu(final Menu menu) {
    if (menu.hasVisibleItems()) {
        menu.clear();/*from  w w w .j  a  v  a  2s.  c o m*/
    }
    menu.add(0, 0, 0, "Back to Main").setIcon(android.R.drawable.ic_menu_revert);
    menu.add(0, 1, 0, "Clear Preferences");
    menu.add(0, 2, 0, "Clear Cache");
    return true;
}

From source file:edu.cmu.cs.cloudlet.android.CloudletActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, SYNTHESIS_MENU_ID_SETTINGS, 0, getString(R.string.synthesis_config_memu_setting));
    menu.add(0, SYNTHESIS_MENU_ID_CLEAR, 1, getString(R.string.synthesis_config_memu_clear));
    return super.onCreateOptionsMenu(menu);
}

From source file:net.idlesoft.android.apps.github.activities.Repository.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    if (menu.hasVisibleItems()) {
        menu.clear();//from w  ww. j a  va 2  s. c  o m
    }
    if (mIsWatching) {
        menu.add(0, 3, 0, "Unwatch");
    } else {
        menu.add(0, 3, 0, "Watch");
    }
    menu.add(0, 0, 0, "Back to Main").setIcon(android.R.drawable.ic_menu_revert);
    menu.add(0, 1, 0, "Clear Preferences");
    menu.add(0, 2, 0, "Clear Cache");
    return true;
}

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

@Override
public void createMenu(Toolbar toolbar) {
    super.createMenu(toolbar);
    Menu menu = toolbar.getMenu();

    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(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        } else if (!watching) {
            menu.add(0, R.id.action_checkin, 2, R.string.action_checkin).setIcon(R.drawable.ic_action_checkin)
                    .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        }/*from  ww  w .ja  v  a  2s .  c  om*/

        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, 7, R.string.action_watchlist_remove);
            } else {
                menu.add(0, R.id.action_watchlist_add, 8, R.string.action_watchlist_add);
            }
        }

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

From source file:com.scigames.slidegame.ProfileActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    //menu.add(0, BACK_ID, 0, R.string.back).setShortcut('0', 'b');
    menu.add(0, QUIT_ID, 0, R.string.quit).setShortcut('0', 'b');

    return true;/*from  www.  java  2s . com*/
}

From source file:com.grarak.kerneladiutor.fragments.tools.InitdFragment.java

private void load(List<RecyclerViewItem> items) {
    for (final String initd : Initd.list()) {
        CardView cardView = new CardView(getActivity());
        cardView.setOnMenuListener(new CardView.OnMenuListener() {
            @Override//from w w w  . ja v a 2s  .  c om
            public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
                Menu menu = popupMenu.getMenu();
                menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
                menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.delete));

                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch (item.getItemId()) {
                        case 0:
                            mEditInitd = initd;
                            Intent intent = new Intent(getActivity(), EditorActivity.class);
                            intent.putExtra(EditorActivity.TITLE_INTENT, initd);
                            intent.putExtra(EditorActivity.TEXT_INTENT, Initd.read(initd));
                            startActivityForResult(intent, 0);
                            break;
                        case 1:
                            mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                        }
                                    }, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            Initd.delete(initd);
                                            reload();
                                        }
                                    }, new DialogInterface.OnDismissListener() {
                                        @Override
                                        public void onDismiss(DialogInterface dialogInterface) {
                                            mDeleteDialog = null;
                                        }
                                    }, getActivity());
                            mDeleteDialog.show();
                            break;
                        }
                        return false;
                    }
                });
            }
        });

        DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(initd);
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
                mExecuteDialog = ViewUtils.dialogBuilder(getString(R.string.exceute_question, initd),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        }, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                execute(initd);
                            }
                        }, new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                mExecuteDialog = null;
                            }
                        }, getActivity());
                mExecuteDialog.show();
            }
        });

        cardView.addItem(descriptionView);
        items.add(cardView);
    }
}

From source file:com.cellbots.eyes.EyesActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, R.string.settings, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.maproot.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, menu);
    menu.add(0, MENU_A, 0, "Info");
    menu.add(0, MENU_B, 0, "Legal Notices");
    menu.add(0, MENU_c, 0, "Mode");
    return true;/* ww w  . ja  va2  s .  c  om*/
}