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.findcab.activity.LocationOverlay.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    menu.add(0, 1, 1, "");
    menu.add(0, 2, 2, "");
    return super.onCreateOptionsMenu(menu);
}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void refreshNavigationMenu() {

    NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    final Menu menu = mNavigationView.getMenu();
    List<TransmartServer> connectedServers = getConnectedServers();

    menu.clear();//  w w  w. ja  v a2s  . c  o m

    int order = 0;
    int group = 1;

    SubMenu serverMenu = menu.addSubMenu(Menu.NONE, order, order, getString(R.string.menu_serversSubmenu));
    order += 1;

    for (TransmartServer transmartServer : connectedServers) {
        int menuItemID = serverMenu.add(group, order, order, transmartServer.getServerLabel())
                .setIcon(R.drawable.ic_action_accounts).getItemId();
        transmartServer.setMenuItemID(menuItemID);
        order += 1;
    }
    add_server_item = serverMenu.add(group, order, order, R.string.menu_addNewServer)
            .setIcon(R.drawable.ic_action_new_account).getItemId();
    order += 1;

    serverMenu.setGroupCheckable(group, true, true);

    about_item = menu.add(Menu.NONE, order, order, R.string.menu_about).setIcon(R.drawable.ic_action_about)
            .getItemId();
}

From source file:com.ringdroid.RingdroidEditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuItem item;// w w w. j ava 2s. c  om

    item = menu.add(0, CMD_SAVE, 0, R.string.menu_save);
    item.setIcon(R.drawable.menu_save);

    item = menu.add(0, CMD_RESET, 0, R.string.menu_reset);
    item.setIcon(R.drawable.menu_reset);

    // item = menu.add(0, CMD_ABOUT, 0, R.string.menu_about);
    // item.setIcon(R.drawable.menu_about);

    item = menu.add(0, CMD_USE_ALL, 0, R.string.use_all);
    item.setIcon(R.drawable.ic_menu_chat_dashboard);

    return true;
}

From source file:net.sourceforge.servestream.activity.MediaPlayerActivity.java

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

    updateVolumeBar();//w  ww  .jav a  2  s .  c  o m

    if (Build.VERSION.SDK_INT >= 9) {
        // Don't offer the audio effects display when running on an OS
        // before API level 9 because it relies on the getAudioSessionId method,
        // which isn't available until after API 8
        if (menu.findItem(EFFECTS_PANEL) == null) {
            Intent i = new Intent("android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL");
            if (getPackageManager().resolveActivity(i, 0) != null) {
                menu.add(0, EFFECTS_PANEL, 0, R.string.list_menu_effects).setIcon(R.drawable.ic_menu_eq);
            }
        } else {
            MenuItem item = menu.findItem(EFFECTS_PANEL);

            if (item != null) {
                if (MusicUtils.getCurrentAudioId() >= 0) {
                    item.setVisible(true);
                } else {
                    item.setVisible(false);
                }
            }
        }
    }

    return true;
}

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

private void buildDirectoryContextMenu(Menu menu, FileViewHolder viewHolder) {
    menu.add(Menu.NONE, R.id.context_download, 0, R.string.context_download);
    menu.add(Menu.NONE, R.id.context_rename, 10, R.string.context_rename);
    menu.add(Menu.NONE, R.id.context_delete, 11, R.string.context_delete);
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    try {/*w w  w .  j  av a  2 s  . co m*/
        getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

        menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

        // Add either a "next" or "finish" button to the action bar, depending on which page
        // is currently selected.
        MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
                (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish
                        : R.string.action_next);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        item.setIcon(R.drawable.ic_menu_forward);

        MenuItem stepItem = menu.add(Menu.NONE, R.id.action_step_ten, Menu.NONE,
                step10 ? R.string.action_step_ten : R.string.action_step_one);

        stepItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        MenuItem turn_on_flash_Item = menu.add(Menu.NONE, R.id.action_turn_on_flash, Menu.NONE,
                R.string.action_turn_on_light);

        turn_on_flash_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        turn_on_flash_Item.setIcon(R.drawable.ic_menu_flashlight);

        MenuItem filter_Item = menu.add(Menu.NONE, R.id.action_filter, Menu.NONE, R.string.filter);

        filter_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        filter_Item.setIcon(R.drawable.filter);

        MenuItem search_Item = menu.add(Menu.NONE, R.id.action_search, Menu.NONE, R.string.search);

        search_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        MenuItem addCustomer_Item = menu.add(Menu.NONE, R.id.action_new_customer, Menu.NONE,
                R.string.new_customer);

        addCustomer_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        setTitle();
        progressbar.setProgress(mPager.getCurrentItem() + 1);
        progressbar.setMax(mPagerAdapter.getCount());
        final Handler handler = new Handler();
        progressbar.setVisibility(View.VISIBLE);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callCount--;
                if (callCount <= 0) {
                    progressbar.setVisibility(View.GONE);
                }
            }
        }, 3000);
        callCount++;
    } catch (Exception ex) {
        ex.toString();
    }
    return true;
}

From source file:cgeo.geocaching.cgeocaches.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_FILTER, 0, res.getString(R.string.caches_filter)).setIcon(R.drawable.ic_menu_filter);

    if (type != CacheListType.HISTORY) {
        menu.add(0, MENU_SORT, 0, res.getString(R.string.caches_sort))
                .setIcon(R.drawable.ic_menu_sort_alphabetically);
    }//from w w  w .  j av a  2 s . c o m

    menu.add(0, MENU_SWITCH_SELECT_MODE, 0, res.getString(R.string.caches_select_mode))
            .setIcon(R.drawable.ic_menu_agenda);
    menu.add(0, MENU_INVERT_SELECTION, 0, res.getString(R.string.caches_select_invert))
            .setIcon(R.drawable.ic_menu_mark);
    if (type == CacheListType.OFFLINE) {
        SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_OFFLINE, 0, res.getString(R.string.caches_manage))
                .setIcon(R.drawable.ic_menu_save);
        subMenu.add(0, MENU_DROP_CACHES, 0, res.getString(R.string.caches_drop_all)); // delete saved caches
        subMenu.add(0, MENU_DROP_CACHES_AND_LIST, 0, res.getString(R.string.caches_drop_all_and_list));
        subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches
        subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
        subMenu.add(0, MENU_DELETE_EVENTS, 0, res.getString(R.string.caches_delete_events));
        subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs));

        //TODO: add submenu/AlertDialog and use R.string.gpx_import_title
        subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title));
        if (Settings.getWebDeviceCode() != null) {
            subMenu.add(0, MENU_IMPORT_WEB, 0, res.getString(R.string.web_import_title));
        }

        subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches
    } else {
        if (type == CacheListType.HISTORY) {
            SubMenu subMenu = menu
                    .addSubMenu(0, SUBMENU_MANAGE_HISTORY, 0, res.getString(R.string.caches_manage))
                    .setIcon(R.drawable.ic_menu_save);
            subMenu.add(0, MENU_REMOVE_FROM_HISTORY, 0, res.getString(R.string.cache_clear_history)); // remove from history
            subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches
            subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs));
            menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh))
                    .setIcon(R.drawable.ic_menu_set_as);
        } else {
            menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.caches_store_offline))
                    .setIcon(R.drawable.ic_menu_set_as); // download details for all caches
        }
    }

    navigationMenu = CacheListAppFactory.addMenuItems(menu, this, res);

    if (type == CacheListType.OFFLINE) {
        SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_LISTS, 0, res.getString(R.string.list_menu))
                .setIcon(R.drawable.ic_menu_more);
        subMenu.add(0, MENU_CREATE_LIST, 0, res.getString(R.string.list_menu_create));
        subMenu.add(0, MENU_DROP_LIST, 0, res.getString(R.string.list_menu_drop));
        subMenu.add(0, MENU_RENAME_LIST, 0, res.getString(R.string.list_menu_rename));
        subMenu.add(0, MENU_SWITCH_LIST, 0, res.getString(R.string.list_menu_change));
    }

    return true;
}

From source file:illab.nabal.NabalSimpleDemoActivity.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.activity_nabal_simple_demo, menu);
    menu.add(0, 1, 0, "Purge Facebook Session").setOnMenuItemClickListener(mClickListener);
    menu.add(0, 2, 0, "Purge Twitter Session").setOnMenuItemClickListener(mClickListener);
    menu.add(0, 3, 0, "Purge Weibo Session").setOnMenuItemClickListener(mClickListener);
    return true;/*  w ww.j a v  a2s.c o  m*/
}

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java

/**
 * Set up the App bar menu/*from  w  w  w .j  av a  2 s . co  m*/
 *
 * Loop through all menu items, checking ID for set up.
 * We do it this way because item indices aren't set since the menu is dynamic.
 * (ex. travel charts may be added to the start)
 *
 * @param menu
 * @return
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();

    getMenuInflater().inflate(R.menu.traffic, menu);

    if (bestTimesAvailable) {
        menu.add(0, R.id.best_times_to_travel, 0, "Best Times to Travel").setIcon(R.drawable.ic_menu_chart)
                .setActionView(R.layout.action_bar_notification_icon)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        final MenuItem chartMenuItem = menu.findItem(R.id.best_times_to_travel);
        // Since we added an action view, need to hook up the onclick ourselves.
        chartMenuItem.getActionView()
                .setOnClickListener(v -> TrafficMapActivity.this.onMenuItemSelected(0, chartMenuItem));
        menu_item_refresh = 2;
    } else {
        menu_item_refresh = 1;
    }

    for (int i = 0; i < menu.size(); i++) {
        switch (menu.getItem(i).getItemId()) {
        case R.id.toggle_cameras:
            if (showCameras) {
                menu.getItem(i).setTitle("Hide Cameras");
                menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam);
            } else {
                menu.getItem(i).setTitle("Show Cameras");
                menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam_off);
            }
            break;
        default:
            break;
        }
    }
    return super.onPrepareOptionsMenu(menu);
}