Java Code Examples for android.widget.AdapterView.AdapterContextMenuInfo

The following are Jave code examples for showing how to use AdapterContextMenuInfo of the android.widget.AdapterView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: fuckView   File: MainFragment.java   View Source Code Vote up 6 votes
@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        MainActivity.BlockModel model = models.get(info.position);
        if (deleteList.size() > 0) {
            menu.add(0, 4, Menu.NONE, R.string.delete_selections);
            menu.add(0, 5, Menu.NONE, R.string.share_selections);
            return;
        }
        menu.add(0, 1, Menu.NONE, R.string.delete_item);
//        if (!model.className.equals("*")) {
//            menu.add(0, 2, Menu.NONE, "设为不按类名定位");
//        }
        menu.add(0, 3, Menu.NONE, R.string.share);
        menu.add(0, 6, Menu.NONE, model.enable ?R.string.disable_item: R.string.enable_item);
    }
 
Example 2
Project: financisto1-holo   File: AbstractListActivity.java   View Source Code Vote up 6 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
	AdapterView.AdapterContextMenuInfo mi = (AdapterView.AdapterContextMenuInfo)menuInfo;
	String headerTitle = getContextMenuHeaderTitle(mi.position);
	if (headerTitle != null) {
		menu.setHeaderTitle(headerTitle);
	}
	List<MenuItemInfo> menus = createContextMenus(mi.id);
	int i = 0;
	for (MenuItemInfo m : menus) {
		if (m.enabled) {
			menu.add(0, m.menuId, i++, m.titleId);				
		}
	}
}
 
Example 3
Project: CSipSimple   File: CodecsFragment.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings("unchecked")
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
         info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(THIS_FILE, "bad menuInfo", e);
        return false;
    }
    
    HashMap<String, Object> codec = null;
    codec = (HashMap<String, Object>) mAdapter.getItem(info.position);
    
    if (codec == null) {
        // If for some reason the requested item isn't available, do nothing
        return false;
    }
    int selId = item.getItemId();
    if (selId == MENU_ITEM_ACTIVATE) {
        boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
        userActivateCodec(codec, isDisabled);
        return true;
    }
    return false;
}
 
Example 4
Project: yaacc-code   File: ContentListActivity.java   View Source Code Vote up 6 votes
/**
 * Creates context menu for certain actions on a specific item.
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
                                ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    if (v instanceof ListView) {
        ListView listView = (ListView) v;
        Object item = listView.getAdapter().getItem(info.position);
        if (item instanceof DIDLObject) {
            selectedDIDLObject = (DIDLObject) item;
        }
    }
    menu.setHeaderTitle(v.getContext().getString(
            R.string.browse_context_title));
    ArrayList<String> menuItems = new ArrayList<String>();
    menuItems.add(v.getContext().getString(R.string.browse_context_play_all));
    menuItems.add(v.getContext().getString(R.string.browse_context_play));
    //menuItems.add(v.getContext().getString( R.string.browse_context_add_to_playplist));
    menuItems.add(v.getContext()
            .getString(R.string.browse_context_download));
    for (int i = 0; i < menuItems.size(); i++) {
        menu.add(Menu.NONE, i, i, menuItems.get(i));
    }
}
 
Example 5
Project: add_to_evernote_note   File: NoteListFragment.java   View Source Code Vote up 6 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    switch (v.getId()) {
        case R.id.listView:
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

            NoteRef noteRef = mNoteRefList.get(info.position);
            boolean linked = noteRef.isLinked();
            menu.setHeaderTitle(noteRef.getTitle());

            String[] menuItems = getResources().getStringArray(R.array.notes_context_menu);
            for (int i = 0; i < menuItems.length; i++) {
                if (linked && (i == 0 || i == 3)) {
                    // share public link and delete
                    continue;
                }

                menu.add(Menu.NONE, i, i, menuItems[i]);
            }
            break;

        default:
            super.onCreateContextMenu(menu, v, menuInfo);
            break;
    }
}
 
Example 6
Project: CSipSimple   File: MessageFragment.java   View Source Code Vote up 6 votes
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterView.AdapterContextMenuInfo info =
            (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    Cursor c = (Cursor) mAdapter.getItem(info.position);
    if (c != null) {
        SipMessage msg = new SipMessage(c);
        switch (item.getItemId()) {
            case MENU_COPY: {
                clipboardManager.setText(msg.getDisplayName(), msg.getBody());
                break;
            }
            default:
                break;
        }

    }
    return super.onContextItemSelected(item);
}
 
Example 7
Project: microMathematics   File: Commander.java   View Source Code Vote up 6 votes
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
    if (featureId != Window.FEATURE_CONTEXT_MENU)
    {
        return false;
    }
    try
    {
        AdapterView.AdapterContextMenuInfo info;
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        if (info == null)
            return false;
        fileListView.setSelection(info.position, 0);
        dispatchCommand(item.getItemId());
        return true;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
}
 
Example 8
Project: AppRTC-Android   File: ConnectActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
  if (item.getItemId() == REMOVE_FAVORITE_INDEX) {
    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    roomList.remove(info.position);
    adapter.notifyDataSetChanged();
    return true;
  }

  return super.onContextItemSelected(item);
}
 
Example 9
Project: ultrasonic   File: SelectAlbumActivity.java   View Source Code Vote up 5 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo)
{
	super.onCreateContextMenu(menu, view, menuInfo);
	AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

	MusicDirectory.Entry entry = (MusicDirectory.Entry) albumListView.getItemAtPosition(info.position);

	if (entry != null && entry.isDirectory())
	{
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.select_album_context, menu);
	}

	shareButton = menu.findItem(R.id.menu_item_share);

	if (shareButton != null)
	{
		shareButton.setVisible(!Util.isOffline(this));
	}

	MenuItem downloadMenuItem = menu.findItem(R.id.album_menu_download);

	if (downloadMenuItem != null)
	{
		downloadMenuItem.setVisible(!Util.isOffline(this));
	}
}
 
Example 10
Project: AppRTC-Android   File: ConnectActivity.java   View Source Code Vote up 5 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
  if (v.getId() == R.id.room_listview) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    menu.setHeaderTitle(roomList.get(info.position));
    String[] menuItems = getResources().getStringArray(R.array.roomListContextMenu);
    for (int i = 0; i < menuItems.length; i++) {
      menu.add(Menu.NONE, i, i, menuItems[i]);
    }
  } else {
    super.onCreateContextMenu(menu, v, menuInfo);
  }
}
 
Example 11
Project: DoorAccess   File: SetUIDFragment.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem menuItem) {

    final AdapterView.AdapterContextMenuInfo menuInfo;
    menuInfo = (AdapterView.AdapterContextMenuInfo)menuItem.getMenuInfo();

    /**
     * menuInfo.position for List index
     * menuItem.getItemId for operation index
     */
    final Tag tag = mTagList.get(menuInfo.position);
    switch(menuItem.getItemId()) {
        case UID_CONTEXT_MENU_MODIFY:
            // TODO
            Toast.makeText(getContext(), "Modify Tag", Toast.LENGTH_SHORT);
            ModifyTagFragment modifyTag = new ModifyTagFragment(tag, menuInfo.position);
            modifyTag.setTargetFragment(this, 0);
            modifyTag.show(mFragmentManager, "ModifyTag");
            break;

        case UID_CONTEXT_MENU_DELETE:
            /* TODO Need verify operation */
            DeleteTag(tag);
            break;
    }

    return false;
}
 
Example 12
Project: financisto1-holo   File: LocationsListActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
	if (super.onContextItemSelected(item)) {
		return true;
	}
	if (item.getItemId() == MENU_RESOLVE) {
		AdapterView.AdapterContextMenuInfo mi = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
		resolveAddress(mi.position, mi.id);
	}
	return false;
}
 
Example 13
Project: mobile-grammar   File: UserGroupLessonsActivity.java   View Source Code Vote up 5 votes
/**
 * Provides two actions: edit and hide a group
 *
 * @param item MenuItem
 * @return
 */
@SuppressWarnings("JavaDoc")
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    // get data of row where context menu has been fired
    int groupIdToRemove = info.position;
    /**
     * When we click on listview, we get variable "position", which counts since 0, having in mind just simple order of row.
     * In order to edit group we must to define his id from database
     */
    Cursor c = (Cursor) userGroupLessonsViewAdapter.getItem(groupIdToRemove);
    Long id = c.getLong(c.getColumnIndexOrThrow("_id"));
    // We extract name of group if user would want to edit name
    String groupNameToEdit = c.getString(c.getColumnIndexOrThrow("title"));

    switch (item.getItemId()) {
        case R.id.context_menu_edit_group:
            // edit group
            Intent intent = new Intent(getApplicationContext(), FormCreateNewGroupActivity.class);
            intent.putExtra("edit_group", id);
            intent.putExtra("group_name", groupNameToEdit);
            startActivity(intent);
            return true;
        case R.id.context_menu_remove_group:
            // remove group. User must confirm the removing
            new AlertDialog.Builder(this)
                    .setIcon(R.drawable.drawer_icon)
                    .setTitle(R.string.removing_group)
                    .setMessage(R.string.this_will_remove_selected_group)
                    .setPositiveButton(message_ok, new AlertRemoveGroupById(id))
                    .setNegativeButton(message_cancel, null)
                    .show();
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 14
Project: SimpleNotes   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.copy_context:
            String textToCopy = adapter.getItem(info.position).getText();
            String label = "Note text";
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(label, textToCopy);
            clipboard.setPrimaryClip(clip);
            Toast.makeText(this, R.string.copied_to_clipboard_toast, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.edit_context:
            Intent intent = new Intent(this, EditActivity.class);
            intent.putExtra(NOTE_FLAG_INTENT, adapter.getItem(info.position).getText());
            intent.putExtra(NOTE_POSITION_FLAG_INTENT, info.position);
            startActivityForResult(intent, MainActivity.REQUEST_CODE_NOTE);
            return true;
        case R.id.voice_edit_context:
            recognitionListener.setCurrentNote(adapter.getItem(info.position));
            if (voiceProcessMethod == VOICE_PROCESS_EDITOR) {
                recognitionListener.setCurrentMode(VoiceRecognitionImplementation.CHANGE_NOTE_EDITOR);
                recognitionListener.setCurrentNotePosition(info.position);
            }
            else {
                recognitionListener.setCurrentMode(VoiceRecognitionImplementation.CHANGE_NOTE_LIST);
            }
            buttonVoiceAdd.setChecked(true);
            return true;
        case R.id.delete_context:
            adapter.remove(adapter.getItem(info.position));
            Toast.makeText(this, R.string.note_deleted_toast, Toast.LENGTH_SHORT).show();
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 15
Project: buildAPKsApps   File: Trolly.java   View Source Code Vote up 5 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
		ContextMenuInfo menuInfo) {
	AdapterView.AdapterContextMenuInfo info;
       try {
            info = (AdapterView.AdapterContextMenuInfo) menuInfo;
       } catch (ClassCastException e) {
           return;
       }
	Cursor cursor = (Cursor)getListAdapter().getItem(info.position);
	if (cursor == null) {
           // For some reason the requested item isn't available, do nothing
           return;
       }
       // Setup the menu header
       menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(ShoppingList.ITEM)));
       int status = cursor.getInt(cursor.getColumnIndex(ShoppingList.STATUS));
       
   	//Add context menu items depending on current state
   	switch (status) {
       case ShoppingList.OFF_LIST:
       	menu.add(0, MENU_ITEM_ON_LIST, 0, R.string.move_on_list);
       	menu.add(0, MENU_ITEM_IN_TROLLEY, 0, R.string.move_in_trolley);
       	break;
       case ShoppingList.ON_LIST:
       	menu.add(0, MENU_ITEM_IN_TROLLEY, 0, R.string.move_in_trolley);
       	menu.add(0, MENU_ITEM_OFF_LIST, 0, R.string.move_off_list);
       	break;
       case ShoppingList.IN_TROLLEY:
       	menu.add(0, MENU_ITEM_ON_LIST, 0, R.string.move_on_list);
       	menu.add(0, MENU_ITEM_OFF_LIST, 0, R.string.move_off_list);
       	break;
       }
   	
       // Add context menu items that are relevant for all items
   	menu.add(0, MENU_ITEM_EDIT, 0, R.string.edit_item);
   	menu.add(0, MENU_ITEM_DELETE, 0, R.string.delete_item);
}
 
Example 16
Project: CSipSimple   File: AccountFiltersListFragment.java   View Source Code Vote up 5 votes
/**
 * Retrieve filter id from a given context menu info pressed
 * @param cmi The context menu info to retrieve infos from
 * @return corresponding filter id if everything goes well, -1 if not able to retrieve filter
 */
private long filterIdFromContextMenuInfo(ContextMenuInfo cmi) {
    AdapterView.AdapterContextMenuInfo info;
    try {
        info = (AdapterView.AdapterContextMenuInfo) cmi;
    } catch (ClassCastException e) {
        Log.e(THIS_FILE, "bad menuInfo", e);
        return -1;
    }
    return info.id;
}
 
Example 17
Project: zabbkit-android   File: HostActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    String[] actions = getResources().getStringArray(R.array.list_hosts_actions);
    if (item.getTitle().equals(actions[0])) {
        AdapterView.AdapterContextMenuInfo contextMenuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        int position = contextMenuInfo.position;
        Cursor cursor = hostsAdapter.getCursor();
        cursor.moveToPosition(position);
        removeHost(cursor.getString(cursor.getColumnIndex(Host.COLUMN_URL)));
    }
    return super.onContextItemSelected(item);
}
 
Example 18
Project: GCSApp   File: SharedFilesActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setMessage("Deleting...");
    pd.setCanceledOnTouchOutside(false);
    pd.show();

    final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;

    EMClient.getInstance().groupManager().asyncDeleteGroupSharedFile(
            groupId,
            fileList.get(position).getFileId(),
            new EMCallBack() {
                @Override
                public void onSuccess() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            pd.dismiss();
                            fileList.remove(position);
                            adapter.notifyDataSetChanged();

                        }
                    });
                }

                @Override
                public void onError(int code, final String error) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(SharedFilesActivity.this, "Delete file fails, " + error, Toast.LENGTH_SHORT).show();
                        }
                    });
                }

                @Override
                public void onProgress(int progress, String status) {
                }
            }
    );

    return super.onContextItemSelected(item);
}
 
Example 19
Project: ultrasonic   File: SelectArtistActivity.java   View Source Code Vote up 4 votes
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo)
{
	super.onCreateContextMenu(menu, view, menuInfo);

	AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

	if (artistListView.getItemAtPosition(info.position) instanceof Artist)
	{
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.select_artist_context, menu);
	}
	else if (info.position == 1)
	{
		String musicFolderId = Util.getSelectedMusicFolderId(this);
		MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);

		if (musicFolderId == null)
		{
			menuItem.setChecked(true);
		}

		if (musicFolders != null)
		{
			for (int i = 0; i < musicFolders.size(); i++)
			{
				MusicFolder musicFolder = musicFolders.get(i);
				menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName());

				if (musicFolder.getId().equals(musicFolderId))
				{
					menuItem.setChecked(true);
				}
			}
		}

		menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true);
	}

	MenuItem downloadMenuItem = menu.findItem(R.id.artist_menu_download);

	if (downloadMenuItem != null)
	{
		downloadMenuItem.setVisible(!Util.isOffline(this));
	}
}
 
Example 20
Project: AnotherRSS   File: FeedListFragment.java   View Source Code Vote up 4 votes
@Override
protected String doInBackground(MenuItem... params) {
    MenuItem item = params[0];
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    long id = info.id;
    Cursor c = (Cursor) adapter.getItem(info.position);
    Uri uri = Uri.parse(FeedContentProvider.CONTENT_URI + "/" + id);
    int flagVal = c.getInt(c.getColumnIndex(FeedContract.Feeds.COLUMN_Flag));
    ContentValues values = new ContentValues();
    String link, title, body;

    switch (item.getItemId()) {
        case R.id.action_openFeed:
            link = c.getString(c.getColumnIndex(FeedContract.Feeds.COLUMN_Link));
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
            startActivity(i);
            return null;

        case R.id.action_readedFeed:

            if (flagVal == FeedContract.Flag.NEW) {
                values.put(FeedContract.Feeds.COLUMN_Flag, FeedContract.Flag.READED);
            } else {
                values.put(FeedContract.Feeds.COLUMN_Flag, FeedContract.Flag.NEW);
            }
            getActivity().getContentResolver().update(uri, values, null, null);
            return null;

        case R.id.action_deleteFeed:
            title = c.getString(c.getColumnIndex(FeedContract.Feeds.COLUMN_Title));
            values.put(FeedContract.Feeds.COLUMN_Deleted, FeedContract.Flag.DELETED);
            getActivity().getContentResolver().update(uri, values, null, null);
            return title + "\n" + getString(R.string.deleted);

        case R.id.action_share:
            title = c.getString(c.getColumnIndex(FeedContract.Feeds.COLUMN_Title));
            body = c.getString(c.getColumnIndex(FeedContract.Feeds.COLUMN_Body));

            title = FeedContract.removeHtml(title);
            body = FeedContract.removeHtml(body);
            body = title.toUpperCase() +
                    "\n" + body + "\n" +
                    c.getString(c.getColumnIndex(FeedContract.Feeds.COLUMN_Link));

            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
            startActivity(Intent.createChooser(sharingIntent, getString(R.string.share)));
            return null;

        case 0: // first item!!
            if (flagVal == FeedContract.Flag.FAVORITE) {
                values.put(FeedContract.Feeds.COLUMN_Flag, FeedContract.Flag.NEW);
            } else {
                values.put(FeedContract.Feeds.COLUMN_Flag, FeedContract.Flag.FAVORITE);
            }
            getActivity().getContentResolver().update(uri, values, null, null);
            return null;

        default:
            return null;
    }
}