Example usage for android.view ContextMenu add

List of usage examples for android.view ContextMenu add

Introduction

In this page you can find the example usage for android.view ContextMenu add.

Prototype

public MenuItem add(int groupId, int itemId, int order, CharSequence title);

Source Link

Document

Add a new item to the menu.

Usage

From source file:com.numenta.htmit.mobile.instance.InstanceListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    //TODO:FEATURE_FLAG: Annotations were introduced in version 1.6
    if (HTMITApplication.getInstance().getServerVersion().compareTo(HTMITClientImpl.SERVER_1_6) < 0) {
        return;/*from ww  w .  j  a  va  2  s . c  om*/
    }
    if (isMenuVisible()) {
        // Make sure we have data for this instance before showing the menu
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);
        if (instance != null && instance.hasData()) {
            // Get timestamp from the selected bar on the anomaly chart
            AnomalyChartView targetView = (AnomalyChartView) info.targetView
                    .findViewById(R.id.anomaly_chart_view);
            long selectedTimestamp = targetView.getSelectedTimestamp();
            if (selectedTimestamp == -1) {
                // The user did not select any anomaly bar. He must have clicked around the chart
                return;
            }
            menu.add(0, R.id.menu_add_annotation, 0, R.string.menu_add_annotation);
        }
    }
}

From source file:com.groksolutions.grok.mobile.instance.InstanceListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    //TODO:FEATURE_FLAG: Annotations were introduced in version 1.6
    if (HTMITApplication.getInstance().getServerVersion().compareTo(HTMClientImpl.GROK_SERVER_1_6) < 0) {
        return;//from   www  .ja va2s  .c o m
    }
    if (isMenuVisible()) {
        // Make sure we have data for this instance before showing the menu
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);
        if (instance != null && instance.hasData()) {
            // Get timestamp from the selected bar on the anomaly chart
            AnomalyChartView targetView = (AnomalyChartView) info.targetView
                    .findViewById(R.id.anomaly_chart_view);
            long selectedTimestamp = targetView.getSelectedTimestamp();
            if (selectedTimestamp == -1) {
                // The user did not select any anomaly bar. He must have clicked around the chart
                return;
            }
            menu.add(0, R.id.menu_add_annotation, 0, R.string.menu_add_annotation);
        }
    }
}

From source file:com.YOMPsolutions.YOMP.mobile.instance.InstanceListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    //TODO:FEATURE_FLAG: Annotations were introduced in version 1.6
    if (YOMPApplication.getInstance().getServerVersion().compareTo(YOMPClientImpl.YOMP_SERVER_1_6) < 0) {
        return;//w w w . j  a va2 s . co  m
    }
    if (isMenuVisible()) {
        // Make sure we have data for this instance before showing the menu
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);
        if (instance != null && instance.hasData()) {
            // Get timestamp from the selected bar on the anomaly chart
            AnomalyChartView targetView = (AnomalyChartView) info.targetView
                    .findViewById(R.id.anomaly_chart_view);
            long selectedTimestamp = targetView.getSelectedTimestamp();
            if (selectedTimestamp == -1) {
                // The user did not select any anomaly bar. He must have clicked around the chart
                return;
            }
            menu.add(0, R.id.menu_add_annotation, 0, R.string.menu_add_annotation);
        }
    }
}

From source file:co.taqat.call.ChatFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.send_picture) {
        menu.add(0, MENU_PICTURE_SMALL, 0, getString(R.string.share_picture_size_small));
        menu.add(0, MENU_PICTURE_MEDIUM, 0, getString(R.string.share_picture_size_medium));
        menu.add(0, MENU_PICTURE_LARGE, 0, getString(R.string.share_picture_size_large));
        //         Not a good idea, very big pictures cause Out of Memory exceptions, slow display, ...
        //         menu.add(0, MENU_PICTURE_REAL, 0, getString(R.string.share_picture_size_real));
    } else {/* ww  w .j  a  v a 2s.  c  o m*/
        menu.add(v.getId(), MENU_DELETE_MESSAGE, 0, getString(R.string.delete));
        menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text));
    }

    LinphoneChatMessage msg = getMessageForId(v.getId());
    if (msg != null && msg.getStatus() == LinphoneChatMessage.State.NotDelivered) {
        menu.add(v.getId(), MENU_RESEND_MESSAGE, 0, getString(R.string.retry));
    }
}

From source file:com.money.manager.ex.common.CategoryListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int child = ExpandableListView.getPackedPositionChild(info.packedPosition);

    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        menu.setHeaderTitle(mCategories.get(group).getName());
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        QueryCategorySubCategory subCategory = mSubCategories.get(mCategories.get(group)).get(child);
        menu.setHeaderTitle(//from w  ww . j  a  v a  2s  . c  om
                subCategory.getCategName().toString() + ": " + subCategory.getSubcategoryName().toString());
    }

    // context menu from resource
    menu.add(Menu.NONE, ContextMenuIds.EDIT.getId(), Menu.NONE, getString(R.string.edit));
    menu.add(Menu.NONE, ContextMenuIds.DELETE.getId(), Menu.NONE, getString(R.string.delete));
    menu.add(Menu.NONE, ContextMenuIds.VIEW_TRANSACTIONS.getId(), Menu.NONE,
            getString(R.string.view_transactions));
}

From source file:com.fvd.nimbus.BrowseActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    //if (wv.getInjected()) return;
    menu.add(Menu.NONE, IDM_OPEN, Menu.NONE, "Save Page");
    menu.add(Menu.NONE, IDM_SAVE, Menu.NONE, "Save Image");
    menu.add(Menu.NONE, IDM_SAVE, Menu.NONE, "Take Screenshot");
}

From source file:com.andrewshu.android.reddit.profile.ProfileActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    int rowId = (int) info.id;
    ThingInfo item = mThingsAdapter.getItem(rowId);

    // Mark the message/comment as selected
    mVoteTargetThingInfo = item;// w w w.  ja v a  2  s  .c  o m
    mVoteTargetView = v;

    if (item.getName().startsWith(Constants.THREAD_KIND)) {
        menu.add(0, Constants.DIALOG_THREAD_CLICK, Menu.NONE, "Go to thread");
    } else {
        // TODO: include the context!
        menu.add(0, Constants.DIALOG_COMMENT_CLICK, Menu.NONE, "Go to comment");
    }
}

From source file:in.shick.diode.user.ProfileActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    int rowId = (int) info.id;
    ThingInfo item = mThingsAdapter.getItem(rowId);

    // Mark the message/comment as selected
    mVoteTargetThingInfo = item;/*from  ww w.  j  a va  2  s  . c  o m*/

    if (item.isThreadKind()) {
        menu.add(0, Constants.DIALOG_THREAD_CLICK, Menu.NONE, R.string.goto_thread);
    } else {
        menu.add(0, Constants.DIALOG_COMMENT_CLICK, Menu.NONE, R.string.view_context);
        if (mVoteTargetThingInfo.getLink_id() != null) {
            // Don't add the thread link if the link_id is null for some reason.
            menu.add(1, Constants.DIALOG_THREAD_CLICK, Menu.NONE, R.string.goto_thread);
        }
        // Lazy-load the URL list to make the list-loading more 'snappy'.
        if (mVoteTargetThingInfo.getUrls() != null && mVoteTargetThingInfo.getUrls().isEmpty()) {
            Markdown.getURLs(mVoteTargetThingInfo.getBody(), mVoteTargetThingInfo.getUrls());
        }
        if (mVoteTargetThingInfo.getUrls() != null && !mVoteTargetThingInfo.getUrls().isEmpty()) {
            menu.add(0, Constants.DIALOG_LINKS, Menu.NONE, R.string.links_menu_item);
        }
    }
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

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

    AdapterView.AdapterContextMenuInfo info;
    info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    ThingInfo _item = mThreadsAdapter.getItem(info.position);

    mVoteTargetThing = _item;//from  ww  w .  j  a  va2  s . co  m

    menu.add(0, Constants.VIEW_SUBREDDIT_CONTEXT_ITEM, 0, R.string.view_subreddit);
    menu.add(0, Constants.SHARE_CONTEXT_ITEM, 0, R.string.share);
    menu.add(0, Constants.OPEN_IN_BROWSER_CONTEXT_ITEM, 0, R.string.open_browser);

    if (mSettings.isLoggedIn()) {
        if (!_item.isSaved()) {
            menu.add(0, Constants.SAVE_CONTEXT_ITEM, 0, "Save");
        } else {
            menu.add(0, Constants.UNSAVE_CONTEXT_ITEM, 0, "Unsave");
        }
        menu.add(0, Constants.HIDE_CONTEXT_ITEM, 0, "Hide");
    }

    menu.add(0, Constants.DIALOG_VIEW_PROFILE, Menu.NONE,
            String.format(getResources().getString(R.string.user_profile), _item.getAuthor()));
}