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.mifos.mifosxdroid.online.clientcharge.ClientChargeFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();/*w  ww . j a v  a2s. c  o  m*/
    MenuItem menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_CHARGES, Menu.NONE,
            getString(R.string.add_new));
    menuItemAddNewDocument
            .setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_white_24dp, null));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    super.onPrepareOptionsMenu(menu);
}

From source file:net.reichholf.dreamdroid.activities.TimerListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, MENU_RELOAD, 0, getText(R.string.reload)).setIcon(android.R.drawable.ic_menu_rotate);
    menu.add(0, MENU_NEW_TIMER, 0, getText(R.string.new_timer)).setIcon(android.R.drawable.ic_menu_add);
    menu.add(0, MENU_CLEANUP, 0, getText(R.string.cleanup)).setIcon(android.R.drawable.ic_menu_manage);
    return true;/*w  ww  .j  a  v a  2  s .  c  o  m*/
}

From source file:edu.illinois.whereru.FriendListFragment.java

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

    menu.add(Menu.NONE, ADD_MENU_ID, Menu.NONE, "ADD Friend");
}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActionMode.java

private void getMenu(Menu menu) {
    MenuItem mi;/*from   w  w  w  . ja  v  a  2s .  co m*/
    menu.clear();

    mi = menu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_DELETE_ID,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings);
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // GROUP MENU
    if (selectedSpenObjects.size() > 1) {
        SubMenu groupSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
                R.string.editor_group_menu);
        groupSubMenu.setIcon(R.drawable.ic_group);
        groupSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID,
                Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID, R.string.editor_group);

        mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID,
                Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID, R.string.editor_ungroup);

        mi.setEnabled(false);
        for (SpenObjectBase obj : selectedSpenObjects) {
            if (obj.getType() == SpenObjectBase.TYPE_CONTAINER) {
                mi.setEnabled(true);
                break;
            }
        }
    }

    // UP MENU
    SubMenu upMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_front_menu);
    upMenu.setIcon(R.drawable.ic_move_up);
    upMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID, R.string.editor_forward);

    mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID, R.string.editor_front);

    // DOWN MENU
    SubMenu downMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_back_menu);
    downMenu.setIcon(R.drawable.ic_move_down);
    downMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID, R.string.editor_backward);

    mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID, R.string.editor_back);
}

From source file:com.cranberrygame.cordova.plugin.optionsmenu.OptionsMenu.java

@Override
public Object onMessage(String id, Object data) {
    //https://github.com/dpogue/cordova-plugin-cambie/blob/master/src/android/Cambie.java
    //http://stackoverflow.com/questions/22403984/get-oncreateoptionsmenu-in-cordova-plugin
    //https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaPlugin.java#L140
    if (id.equals("onCreateOptionsMenu") || id.equals("onPrepareOptionsMenu")) {
        Menu menu = (Menu) data;

        if (this.menus != null) {
            menu.clear();/*ww  w.ja v  a2 s .com*/

            String[] _menus = this.menus.split(",");
            for (int i = 0; i < _menus.length; i++) {
                menu.add(0, i, 0, _menus[i]);
            }
        }
    } else if (id.equals("onOptionsItemSelected")) {
        MenuItem item = (MenuItem) data;

        //webView.loadUrl(String.format("javascript:cordova.fireDocumentEvent('onMenuSelected', {'menu': '%s'});", item.getTitle()));

        Log.d(LOG_TAG, "onOptionsItemSelected: " + item.getTitle());

        JSONObject result = new JSONObject();
        try {
            result.put("event", "onMenuSelected");
            result.put("message", item.getTitle());
        } catch (JSONException ex) {
        }
        //PluginResult pr = new PluginResult(PluginResult.Status.OK, "onMenuSelected");
        PluginResult pr = new PluginResult(PluginResult.Status.OK, result);
        pr.setKeepCallback(true);
        callbackContextKeepCallback.sendPluginResult(pr);
        //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
        //pr.setKeepCallback(true);
        //callbackContextKeepCallback.sendPluginResult(pr);            
    }

    return null;
}

From source file:com.gh4a.activities.Github4AndroidActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.login);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    return super.onCreateOptionsMenu(menu);
}

From source file:net.pmarks.chromadoze.ChromaDoze.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem mi;/*from  w w w  .  ja v a2 s .c  o m*/

    mi = menu.add(0, MENU_PLAY_STOP, 0, getString(R.string.play_stop));
    MenuItemCompat.setShowAsAction(mi, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);

    if (mFragmentId == FragmentIndex.ID_CHROMA_DOZE) {
        mi = menu.add(0, MENU_LOCK, 0, getString(R.string.lock_unlock));
        MenuItemCompat.setShowAsAction(mi, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.android.apis.graphics.FingerPaint.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    menu.add(0, ERASE_ALL_ID, 0, "Erase all").setShortcut('3', 'a');
    menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3', 'c');
    menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4', 's');
    menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5', 'z');
    menu.add(0, ERASE_MENU_ID, 0, "Erase").setShortcut('5', 'z');
    menu.add(0, SRCATOP_MENU_ID, 0, "SrcATop").setShortcut('5', 'z');

    /****   Is this the mechanism to extend with filter effects?
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(/*from  ww w. j  a  va2  s  . co  m*/
                      Menu.ALTERNATIVE, 0,
                      new ComponentName(this, NotesList.class),
                      null, intent, 0, null);
    *****/
    return true;
}

From source file:com.miz.mizuu.fragments.FanartSearchFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    for (int i = 0; i < mItems.length; i++)
        menu.add(1, i, i, mItems[i]);
    menu.setGroupCheckable(1, true, true);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.mifos.mifosxdroid.online.ClientChargeFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from  w w w.ja va 2  s. co m
    MenuItem menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_CHARGES, Menu.NONE,
            getString(R.string.add_new));
    menuItemAddNewDocument
            .setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_content_new, null));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    super.onPrepareOptionsMenu(menu);
}