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.ubuntuone.android.files.activity.FilesActivity.java

private void buildFileContextMenu(Menu menu, FileViewHolder holder) {
    if (ResourceState.STATE_GETTING.equals(holder.resourceState)) {
        menu.add(Menu.NONE, R.id.context_cancel_download, 1, R.string.context_cancel_download);
    } else {// w  w w  .  ja v  a  2  s . com
        menu.add(Menu.NONE, R.id.context_download, 1, R.string.context_download);
    }
    if (holder.isPublic) {
        menu.add(Menu.NONE, R.id.context_share_link, 1, R.string.context_share_link);
        menu.add(Menu.NONE, R.id.context_disable_link, 2, R.string.context_disable_link);
    } else {
        menu.add(Menu.NONE, R.id.context_create_link, 1, R.string.context_create_link);
    }
    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);
    if (!TextUtils.isEmpty(holder.data) && !holder.data.startsWith(ContentResolver.SCHEME_CONTENT)) {
        menu.add(Menu.NONE, R.id.context_delete_from_device, 12, R.string.context_delete_from_device);
    }
}

From source file:com.SpeechEd.SpeechEdEditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuItem item;/*  ww  w  .ja v a 2 s  .co  m*/

    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);

    return true;
}

From source file:biz.bokhorst.xprivacy.ActivityApp.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    // Check if running
    boolean running = false;
    ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    for (RunningAppProcessInfo info : activityManager.getRunningAppProcesses())
        if (info.uid == mAppInfo.getUid())
            running = true;//ww  w. java 2  s  .  c om

    PackageManager pm = getPackageManager();
    List<String> listPackageNames = mAppInfo.getPackageName();
    List<String> listApplicationName = mAppInfo.getApplicationName();
    for (int i = 0; i < listPackageNames.size(); i++) {
        Menu appMenu = (listPackageNames.size() == 1) ? menu
                : menu.addSubMenu(i, Menu.NONE, Menu.NONE, listApplicationName.get(i));

        // Launch
        MenuItem launch = appMenu.add(i, MENU_LAUNCH, Menu.NONE, getString(R.string.menu_app_launch));
        if (pm.getLaunchIntentForPackage(listPackageNames.get(i)) == null)
            launch.setEnabled(false);

        // Settings
        appMenu.add(i, MENU_SETTINGS, Menu.NONE, getString(R.string.menu_app_settings));

        // Kill
        MenuItem kill = appMenu.add(i, MENU_KILL, Menu.NONE, getString(R.string.menu_app_kill));
        kill.setEnabled(running && PrivacyManager.isApplication(mAppInfo.getUid()));

        // Play store
        MenuItem store = appMenu.add(i, MENU_STORE, Menu.NONE, getString(R.string.menu_app_store));
        if (!Util.hasMarketLink(this, listPackageNames.get(i)))
            store.setEnabled(false);
    }
}

From source file:com.jtechme.apphub.AppDetailsData.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.clear();/*from   w w  w .j  av a  2 s  .  c  o  m*/
    if (app == null)
        return true;

    if (mPm.getLaunchIntentForPackage(app.packageName) != null && app.canAndWantToUpdate()) {
        MenuItemCompat.setShowAsAction(
                menu.add(Menu.NONE, LAUNCH, 1, R.string.menu_launch).setIcon(R.drawable.ic_play_arrow_white),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    }

    if (app.isInstalled()) {
        MenuItemCompat.setShowAsAction(
                menu.add(Menu.NONE, UNINSTALL, 1, R.string.menu_uninstall).setIcon(R.drawable.ic_delete_white),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
    }

    MenuItemCompat.setShowAsAction(
            menu.add(Menu.NONE, SHARE, 1, R.string.menu_share).setIcon(R.drawable.ic_share_white),
            MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(Menu.NONE, IGNOREALL, 2, R.string.menu_ignore_all).setIcon(R.drawable.ic_do_not_disturb_white)
            .setCheckable(true).setChecked(app.ignoreAllUpdates);

    if (app.hasUpdates()) {
        menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this)
                .setIcon(R.drawable.ic_do_not_disturb_white).setCheckable(true)
                .setChecked(app.ignoreThisUpdate >= app.suggestedVercode);
    }

    // Ignore on devices without Bluetooth
    if (app.isInstalled() && fdroidApp.bluetoothAdapter != null) {
        menu.add(Menu.NONE, SEND_VIA_BLUETOOTH, 3, R.string.send_via_bluetooth)
                .setIcon(R.drawable.ic_bluetooth_white);
    }
    return true;
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    // Don't show the menu items if we got launched by path/filedescriptor, or
    // if we're in one shot mode. In most cases, these menu items are not
    // useful in those modes, so for consistency we never show them in these
    // modes, instead of tailoring them to the specific file being played.
    if (MusicUtils.getCurrentAudioId() >= 0) {
        menu.add(0, GOTO_START, 0, R.string.goto_start).setIcon(R.drawable.ic_menu_music_library);
        menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
        SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0, R.string.add_to_playlist)
                .setIcon(android.R.drawable.ic_menu_add);
        // these next two are in a separate group, so they can be shown/hidden as needed
        // based on the keyguard state
        menu.add(1, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short)
                .setIcon(R.drawable.ic_menu_set_as_ringtone);
        menu.add(1, DELETE_ITEM, 0, R.string.delete_item).setIcon(R.drawable.ic_menu_delete);

        Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
        if (getPackageManager().resolveActivity(i, 0) != null) {
            menu.add(0, EFFECTS_PANEL, 0, R.string.effectspanel).setIcon(R.drawable.ic_menu_eq);
        }//from  w  w w . ja v a  2s  .  c om

        return true;
    }
    return false;
}

From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    PageHolder pageHolder = getPageHolder();
    ChanConfiguration configuration = getChanConfiguration();
    getAdapter().setSelectionModeEnabled(true);
    mode.setTitle(getString(R.string.text_selected_format, 0));
    int pasteResId = ResourceUtils.getSystemSelectionIcon(getActivity(), "actionModePasteDrawable",
            "ic_menu_paste_holo_dark");
    int flags = MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
    ChanConfiguration.Board board = configuration.safe().obtainBoard(pageHolder.boardName);
    menu.add(0, ACTION_MENU_MAKE_THREADSHOT, 0, R.string.action_make_threadshot)
            .setIcon(obtainIcon(R.attr.actionMakeThreadshot)).setShowAsAction(flags);
    if (replyable != null) {
        menu.add(0, ACTION_MENU_REPLY, 0, R.string.action_reply).setIcon(pasteResId).setShowAsAction(flags);
    }//  ww w.  jav a  2 s  . c  o m
    if (board.allowDeleting) {
        ChanConfiguration.Deleting deleting = configuration.safe().obtainDeleting(pageHolder.boardName);
        if (deleting != null && deleting.multiplePosts) {
            menu.add(0, ACTION_MENU_DELETE_POSTS, 0, R.string.action_delete)
                    .setIcon(obtainIcon(R.attr.actionDelete)).setShowAsAction(flags);
        }
    }
    if (board.allowReporting) {
        ChanConfiguration.Reporting reporting = configuration.safe().obtainReporting(pageHolder.boardName);
        if (reporting != null && reporting.multiplePosts) {
            menu.add(0, ACTION_MENU_SEND_REPORT, 0, R.string.action_report)
                    .setIcon(obtainIcon(R.attr.actionReport)).setShowAsAction(flags);
        }
    }
    return true;
}

From source file:com.FluksoViz.FluksoVizActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, 0, 0, R.string.preferences).setIcon(android.R.drawable.ic_menu_manage);
    menu.add(0, 1, 1, "Created by" + " Maciej Eckstein \n " + "Version:" + versionName)
            .setIcon(android.R.drawable.ic_menu_help);
    ;// w  ww .j a v a  2 s  . co m
    return true;
}

From source file:com.hichinaschool.flashcards.anki.CardEditor.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item;/*from   w ww .  ja  va2s.c  o m*/
    Resources res = getResources();
    // Lookup.initialize(this, mDeck.getDeckPath());
    // item = menu.add(Menu.NONE, MENU_LOOKUP, Menu.NONE,
    // Lookup.getSearchStringTitle());
    // item.setIcon(R.drawable.ic_menu_search);
    // item.setEnabled(Lookup.isAvailable());
    // item = menu.add(Menu.NONE, MENU_RESET, Menu.NONE,
    // res.getString(R.string.card_editor_reset));
    // item.setIcon(R.drawable.ic_menu_revert);
    if (!mAddNote) {
        item = menu.add(Menu.NONE, MENU_ADD_CARD, Menu.NONE, res.getString(R.string.card_editor_add_card));
        item.setIcon(R.drawable.ic_menu_add);
    }
    item = menu.add(Menu.NONE, MENU_COPY_CARD, Menu.NONE, res.getString(R.string.card_editor_copy_card));
    item.setIcon(R.drawable.ic_menu_upload);
    if (!mAddNote) {
        item = menu.add(Menu.NONE, MENU_RESET_CARD_PROGRESS, Menu.NONE,
                res.getString(R.string.card_editor_reset_card));
        item.setIcon(R.drawable.ic_menu_delete);
    }
    if (mCaller != CALLER_CARDEDITOR_INTENT_ADD) {
        mIntentInformation = MetaDB.getIntentInformation(this);
        item = menu.add(Menu.NONE, MENU_SAVED_INTENT, Menu.NONE,
                res.getString(R.string.intent_add_saved_information));
        item.setIcon(R.drawable.ic_menu_archive);
    }
    return true;
}

From source file:org.alfresco.mobile.android.application.fragments.node.details.NodeDetailsFragment.java

public void getMenu(Context context, AlfrescoSession session, Menu menu, Node node) {
    MenuItem mi;/* ww  w .  j  a v a  2s . c  o m*/

    if (node == null) {
        return;
    }
    if (node instanceof NodeSyncPlaceHolder) {
        return;
    }

    boolean isRestrict = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    if (node.isDocument()) {
        if (((Document) node).getContentStreamLength() > 0 && !isRestrict
                && ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
                        ConfigurableActionHelper.ACTION_NODE_DOWNLOAD)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_download, Menu.FIRST, R.string.download);
            mi.setIcon(R.drawable.ic_download_light);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (((Document) node).isLatestVersion() && ConfigurableActionHelper.isVisible(getActivity(),
                getAccount(), getSession(), node, ConfigurableActionHelper.ACTION_NODE_UPDATE)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_update, Menu.FIRST + 130, R.string.update);
            mi.setIcon(R.drawable.ic_upload);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (!(session instanceof CloudSession) && ConfigurableActionHelper.isVisible(getActivity(),
                getAccount(), getSession(), node, ConfigurableActionHelper.ACTION_NODE_REVIEW)) {
            mi = menu.add(Menu.NONE, R.id.menu_workflow_add, Menu.FIRST + 500, R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }

    if (session == null) {
        return;
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_EDIT)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_edit, Menu.FIRST + 10, R.string.edit);
        mi.setIcon(R.drawable.ic_properties);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (node.hasAspect(ContentModel.ASPECT_GEOGRAPHIC)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_location, Menu.FIRST + 50, R.string.geolocation);
        mi.setIcon(R.drawable.ic_location);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_DELETE)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }
}

From source file:com.Beat.RingdroidEditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    MenuItem item;/*from   w  w  w .  java 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);

    return true;
}