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:can.yrt.onebusaway.MyRouteListFragmentBase.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final TextView text = (TextView) info.targetView.findViewById(R.id.short_name);
    menu.setHeaderTitle(getString(R.string.route_name, text.getText()));
    if (isShortcutMode()) {
        menu.add(0, CONTEXT_MENU_DEFAULT, 0, R.string.my_context_create_shortcut);
    } else {//from w  w  w  .  ja v  a  2s .c o  m
        menu.add(0, CONTEXT_MENU_DEFAULT, 0, R.string.my_context_get_route_info);
    }
    menu.add(0, CONTEXT_MENU_SHOW_ON_MAP, 0, R.string.my_context_showonmap);
    final String url = QueryUtils.RouteList.getUrl(getListView(), info.position);
    if (!TextUtils.isEmpty(url)) {
        menu.add(0, CONTEXT_MENU_SHOW_URL, 0, R.string.my_context_show_schedule);
    }
}

From source file:com.androsz.electricsleepbeta.alarmclock.AlarmClock.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenuInfo menuInfo) {
    // Inflate the menu from xml.
    // super.getMenuInflater().inflate(R.menu.context_menu, (Menu)menu);
    menu.add(android.view.Menu.NONE, R.id.enable_alarm, android.view.Menu.NONE, R.string.enable_alarm);
    menu.add(android.view.Menu.NONE, R.id.edit_alarm, android.view.Menu.NONE, R.string.menu_edit_alarm);
    menu.add(android.view.Menu.NONE, R.id.delete_alarm, android.view.Menu.NONE, R.string.delete_alarm);
    // Use the current item to create a custom view for the header.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem(info.position);
    final Alarm alarm = new Alarm(c);

    // Construct the Calendar to compute the time.
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, alarm.hour);
    cal.set(Calendar.MINUTE, alarm.minutes);
    final String time = Alarms.formatTime(this, cal);

    // Inflate the custom view and set each TextView's text.
    final View v = mFactory.inflate(R.layout.context_menu_header, null);
    TextView textView = (TextView) v.findViewById(R.id.header_time);
    textView.setText(time);//from w  w  w .j a  va2  s .  c o m
    textView = (TextView) v.findViewById(R.id.header_label);
    textView.setText(alarm.label);

    // Set the custom view on the menu.
    menu.setHeaderView(v);
    // Change the text based on the state of the alarm.
    if (alarm.enabled) {
        menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm);
    }
}

From source file:can.yrt.onebusaway.MyStopListFragmentBase.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final TextView text = (TextView) info.targetView.findViewById(R.id.stop_name);
    menu.setHeaderTitle(text.getText());
    if (isShortcutMode()) {
        menu.add(0, CONTEXT_MENU_DEFAULT, 0, R.string.my_context_create_shortcut);
    } else {/*  w ww  . ja  v  a  2s .c o  m*/
        menu.add(0, CONTEXT_MENU_DEFAULT, 0, R.string.my_context_get_stop_info);
    }
    menu.add(0, CONTEXT_MENU_SHOW_ON_MAP, 0, R.string.my_context_showonmap);
    if (!isShortcutMode()) {
        menu.add(0, CONTEXT_MENU_CREATE_SHORTCUT, 0, R.string.my_context_create_shortcut);
    }
}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.SelectPlaylistActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    menu.add(Menu.NONE, MENU_ITEM_PLAY_ALL, MENU_ITEM_PLAY_ALL, R.string.common_play_now);
}

From source file:ua.com.spacetv.mycookbook.fragments.FragSubCategory.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (mIsFolder) {
        menu.add(0, ID_POPUP_ITEM_REN, 0, R.string.item_rename);
        menu.add(0, ID_POPUP_ITEM_DEL, 0, R.string.item_delete);
    } else {//from   w  ww.  ja  va 2s  . co m
        menu.add(0, ID_POPUP_ITEM_FAV, 0, R.string.item_favorite);
        menu.add(0, ID_POPUP_ITEM_REN, 0, R.string.item_rename);
        menu.add(0, ID_POPUP_ITEM_MOV, 0, R.string.item_move);
        menu.add(0, ID_POPUP_ITEM_DEL, 0, R.string.item_delete);
    }
}

From source file:dev.drsoran.moloko.fragments.ContactsListFragment.java

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

    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Contact contact = getListAdapter().getItem(info.position);

    if (contact.getLookUpKey() != null) {
        final String fullname = contact.getFullname();
        menu.add(Menu.NONE, R.id.ctx_menu_show_phonebook_contact, Menu.NONE,
                getString(R.string.contactslist_listitem_show_phonebook_contact, fullname));
    }//w  w  w  .  j ava 2  s  .  c o  m
}

From source file:org.flerda.android.honeypad.NoteListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.add(0, DELETE_ID, 0, R.string.menu_delete);

}

From source file:org.yammp.fragment.AlbumFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {

    if (mCursor == null)
        return;/*from w  ww . j a v a2 s  .  c  o  m*/

    menu.add(hashCode(), PLAY_SELECTION, 0, R.string.play_selection);
    menu.add(hashCode(), DELETE_ITEMS, 0, R.string.delete_music);
    menu.add(hashCode(), DELETE_LYRICS, 0, R.string.delete_lyrics);

    AdapterContextMenuInfo adapterinfo = (AdapterContextMenuInfo) info;
    mSelectedPosition = adapterinfo.position;
    mCursor.moveToPosition(mSelectedPosition);
    try {
        mSelectedId = mCursor.getLong(mIdIdx);
    } catch (IllegalArgumentException ex) {
        mSelectedId = adapterinfo.id;
    }

    mCurrentArtistNameForAlbum = mCursor.getString(mArtistIdx);

    mCurrentAlbumName = mCursor.getString(mAlbumIdx);
    if (mCurrentAlbumName != null && !MediaStore.UNKNOWN_STRING.equals(mCurrentAlbumName)) {
        menu.add(hashCode(), SEARCH, 0, android.R.string.search_go);
        menu.setHeaderTitle(mCurrentAlbumName);
    } else {
        menu.setHeaderTitle(R.string.unknown_album);
    }

}

From source file:org.lyricue.android.PlaylistFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.playlistView) {
        menu.setHeaderTitle("Item Actions");
        menu.add(1, 0, 0, "Show Item");
        menu.add(1, 1, 0, "Remove Item");
    }//from   w ww .  j  av  a 2  s  . c  o  m
}

From source file:com.googlecode.android_scripting.activity.ApiBrowser.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    if (!mIsLanguageSupported) {
        return;//from w w  w  .  j av  a 2 s.c o m
    }
    menu.add(Menu.NONE, ContextMenuId.INSERT_TEXT.getId(), Menu.NONE,
            getResources().getString(R.string.s_Insert));
    menu.add(Menu.NONE, ContextMenuId.PROMPT_PARAMETERS.getId(), Menu.NONE,
            getResources().getString(R.string.s_Prompt));
    if (Help.checkApiHelp(this)) {
        menu.add(Menu.NONE, ContextMenuId.HELP.getId(), Menu.NONE, getResources().getString(R.string.s_Help));
    }
}