Java Code Examples for android.widget.AdapterView#AdapterContextMenuInfo

The following examples show how to use android.widget.AdapterView#AdapterContextMenuInfo . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    Cursor cursor = (Cursor) mListView.getAdapter().getItem(info.position);
    if (cursor == null) {
        // For some reason the requested item isn't available, do nothing
        return;
    }
    menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(FolderColumns.NAME)));

    menu.add(0, MENU_ITEM_EXPORT, 0, R.string.export_folder);
    menu.add(0, MENU_ITEM_RENAME, 1, R.string.rename_folder);
    menu.add(0, MENU_ITEM_DELETE, 2, R.string.delete_folder);
}
 
Example 2
@Override
  public boolean onContextItemSelected(MenuItem item) {

/*
 *  Contiene información sobre el elemento del menú contextual
 *  sobre el que se ha pulsado
 */
      AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

      switch (item.getItemId()) {
          case R.id.ctx_editar:
              // Muestra el formulario para modificar la Ubicación
              Ubicacion ubicacion = listaUbicaciones.get(info.position);
              Intent intent = new Intent(getActivity(), NuevaUbicacion.class);
              intent.putExtra("accion", "modificar");
              intent.putExtra("ubicacion", ubicacion);
              startActivity(intent);
              return true;
          case R.id.ctx_eliminar:
              eliminar_ubicacion(info);
              return true;
          default:
              return super.onContextItemSelected(item);
      }
  }
 
Example 3
/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 */
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
        case R.id.fragment_album_tracks_action_play:
            playTrack(info.position);
            return true;
        case R.id.fragment_playlist_tracks_action_enqueue:
            enqueueTrack(info.position, false);
            return true;
        case R.id.fragment_playlist_tracks_action_enqueueasnext:
            enqueueTrack(info.position, true);
            return true;
        case R.id.fragment_playlist_tracks_action_remove:
            removeTrackFromPlaylist(info.position);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 4
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    Cursor cursor = (Cursor) mListView.getAdapter().getItem(info.position);
    if (cursor == null) {
        // For some reason the requested item isn't available, do nothing
        return;
    }

    menu.setHeaderTitle("Puzzle");

    // Add a menu item to delete the note
    menu.add(0, MENU_ITEM_PLAY, 0, R.string.play_puzzle);
    menu.add(0, MENU_ITEM_EDIT_NOTE, 1, R.string.edit_note);
    menu.add(0, MENU_ITEM_RESET, 2, R.string.reset_puzzle);
    menu.add(0, MENU_ITEM_EDIT, 3, R.string.edit_puzzle);
    menu.add(0, MENU_ITEM_DELETE, 4, R.string.delete_puzzle);
}
 
Example 5
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }

    switch (item.getItemId()) {
        case MENU_ITEM_PLAY:
            playSudoku(info.id);
            return true;
        case MENU_ITEM_EDIT:
            Intent i = new Intent(this, SudokuEditActivity.class);
            i.setAction(Intent.ACTION_EDIT);
            i.putExtra(SudokuEditActivity.EXTRA_SUDOKU_ID, info.id);
            startActivity(i);
            return true;
        case MENU_ITEM_DELETE:
            mDeletePuzzleID = info.id;
            showDialog(DIALOG_DELETE_PUZZLE);
            return true;
        case MENU_ITEM_EDIT_NOTE:
            mEditNotePuzzleID = info.id;
            showDialog(DIALOG_EDIT_NOTE);
            return true;
        case MENU_ITEM_RESET:
            mResetPuzzleID = info.id;
            showDialog(DIALOG_RESET_PUZZLE);
            return true;
    }
    return false;
}
 
Example 6
@Override
public void populateContextMenu(ContextMenu menu, AdapterView.AdapterContextMenuInfo acmi, int num)
{
    Item item = (Item) getItem(acmi.position);
    if (item == null)
        return;
    String schema = item.origin instanceof String ? (String) item.origin : null;
    if (!FileUtils.str(schema))
        return;
    if (AdapterDocuments.ORG_SCHEME.startsWith(schema))
    {
        menu.add(0, R.id.fman_action_open_saf, 0, R.string.fman_open_saf);
    }
}
 
Example 7
@Override
public boolean onContextItemSelected(MenuItem item) {
    try {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
        FormRecord selectedRecord = (FormRecord)adapter.getItem(info.position);
        switch (item.getItemId()) {
            case OPEN_RECORD:
                returnItem(info.position);
                return true;
            case DELETE_RECORD:
                FormRecord toDelete =
                        CommCareApplication.instance().getUserStorage(FormRecord.class).read((int)info.id);
                toDelete.logPendingDeletion(TAG, "the user manually selected 'DELETE' in FormRecordListActivity");
                FormRecordCleanupTask.wipeRecord(toDelete);
                listView.post(adapter::notifyDataSetInvalidated);
                return true;
            case RESTORE_RECORD:
                new FormRecordProcessor(this).updateRecordStatus(selectedRecord, FormRecord.STATUS_UNSENT);
                adapter.resetRecords();
                adapter.notifyDataSetChanged();
                return true;
            case SCAN_RECORD:
                FormRecord theRecord = (FormRecord)adapter.getItem(info.position);
                Pair<Boolean, String> result = new FormRecordProcessor(this).verifyFormRecordIntegrity(theRecord);
                createFormRecordScanResultDialog(result, theRecord);
                logIntegrityScanResult(theRecord, result);
                return true;
            case VIEW_QUARANTINE_REASON:
                createQuarantineReasonDialog(selectedRecord);
                return true;
        }
        return true;
    } catch (SessionUnavailableException e) {
        //TODO: Login and try again
        return true;
    }
}
 
Example 8
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()){
        case R.id.menu_delete:
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
            FastItem pm = adapter.getItem(info.position);
            if(pm != null){
                queueRequest(new PMDeleteRequest(folderId, deleteListener, null, pm.getId()));
                return true;
            }
    }
    return super.onContextItemSelected(item);
}
 
Example 9
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo adapterContextMenuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.action_delete:
            if (baseActivity.checkNetworkAvailableWithError() && checkDialogsLoadFinished()) {
                QBChatDialog chatDialog = dialogsListAdapter.getItem(adapterContextMenuInfo.position).getChatDialog();
                deleteDialog(chatDialog);
            }
            break;
    }
    return true;
}
 
Example 10
Source Project: YiBo   File: GroupContextMenuListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
		ContextMenuInfo menuInfo) {
	final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
	int position = info.position;
	if (position < 0 || position >= adapter.getCount()) {
		return;
	}
	Group group = (Group)adapter.getItem(position);
	if (group == null) {
		return;
	}
	Context context = v.getContext();
	analyzeCommentMenu(group, menu, context);
}
 
Example 11
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
		ContextMenuInfo menuInfo) {
	final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
	int position = info.position - 1;
	if (position < 0 || position >= adapter.getCount()) {
		return;
	}
	Comment comment = (Comment)adapter.getItem(position);
	
	Context context = v.getContext();
	analyzeCommentMenu(comment, menu, context);
}
 
Example 12
Source Project: YiBo   File: AccountsActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
	AdapterContextMenuInfo adapterMenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
	int position = adapterMenuInfo.position;
	LocalAccount account = alAdapter.getItem(position);
	
	menu.setHeaderTitle(account.getUser().getScreenName() + "/" + account.getServiceProvider().getSpName());
	menu.add(Menu.NONE, SWITCH_TO_MENU_ID, Menu.NONE, R.string.menu_accounts_switch_to);
	menu.add(Menu.NONE, SET_DEFAULT_MENU_ID, Menu.NONE, R.string.menu_accounts_set_default);
    menu.add(Menu.NONE, DELETE_MENU_ID, Menu.NONE, R.string.menu_accounts_delete);
	
    super.onCreateContextMenu(menu, v, menuInfo);
}
 
Example 13
@Override
public boolean onContextItemSelected(MenuItem item) {
    View v = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).targetView;
    Database.FavoritesEntry entry = (FavoritesEntry) v.getTag();
    switch (item.getItemId()) {
        case R.id.context_menu_remove_favorites:
            MainApplication.getInstance().database.removeFavorite(entry.chan, entry.board, entry.boardPage, entry.thread);
            for (Pair<ListView,String> p : listViews) ((FavoritesAdapter) p.getLeft().getAdapter()).remove(entry);
            return true;
        case R.id.context_menu_open_browser:
            UrlHandler.launchExternalBrowser(activity, entry.url);
            return true;
    }
    return false;
}
 
Example 14
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    if (info.id == -1) return;

    if (info.id  < 0 || getAdapter().getCount() <= info.id ) return;

    Object o = getAdapter().getItem((int) info.id );
    if (o == null)
        return;
    final IListItem topic = (IListItem) o;

    final List<MenuListDialog> list = new ArrayList<>();
    AddLinksSubMenu(list, topic);
    list.add(new MenuListDialog(App.getContext().getString(R.string.delete), () -> new MaterialDialog.Builder(getContext())
            .title(R.string.confirm_action)
            .content(R.string.ask_delete_note)
            .cancelable(true)
            .negativeText(R.string.cancel)
            .positiveText(R.string.delete)
            .onPositive((dialog, which) -> {
                try {
                    NotesTable.delete(topic.getId().toString());
                    getMData().remove(topic);
                    getAdapter().notifyDataSetChanged();
                } catch (Throwable ex) {
                    AppLog.e(getContext(), ex);
                }
            })
            .show()));
    ExtUrl.showContextDialog(getContext(), null, list);

}
 
Example 15
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    synchronized (this.messageList) {
        super.onCreateContextMenu(menu, v, menuInfo);
        AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
        this.selectedMessage = this.messageList.get(acmi.position);
        populateContextMenu(menu);
    }
}
 
Example 16
@Override
public void onCreateContextMenu(ContextMenu menu,
                                View v,
                                ContextMenu.ContextMenuInfo menuInfo) {
  int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
  if (position >= adapter.getCount() || adapter.getItem(position).getResult() != null) {
    menu.add(Menu.NONE, position, position, R.string.history_clear_one_history_text);
  } // else it's just that dummy "Empty" message
}
 
Example 17
/**
 * 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 18
Source Project: android-apps   File: HistoryActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu,
                                View v,
                                ContextMenu.ContextMenuInfo menuInfo) {
  int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
  menu.add(Menu.NONE, position, position, R.string.history_clear_one_history_text);
}
 
Example 19
@Override
public void populateContextMenu(ContextMenu menu, AdapterView.AdapterContextMenuInfo acmi, int num)
{
    try
    {
        if (readWriteAdapter)
        {
            menu.add(0, R.id.fman_action_refresh, 0, R.string.fman_refresh_title);
            menu.add(0, R.id.fman_action_create_folder, 0, R.string.fman_create_folder_title);
            if (num > 0)
            {
                menu.add(0, R.id.fman_action_rename, 0, R.string.fman_rename_title);
                menu.add(0, R.id.fman_action_delete, 0, R.string.fman_delete_title);
            }
        }
        MenuItem activeSort = null;
        menu.add(0, R.id.fman_action_sort_by_name, 0, R.string.fman_sort_by_name);
        if ((mode & MODE_SORTING) == SORT_NAME)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_name);
        }
        menu.add(0, R.id.fman_action_sort_by_ext, 0, R.string.fman_sort_by_ext);
        if ((mode & MODE_SORTING) == SORT_EXT)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_ext);
        }
        menu.add(0, R.id.fman_action_sort_by_size, 0, R.string.fman_sort_by_size);
        if ((mode & MODE_SORTING) == SORT_SIZE)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_size);
        }
        menu.add(0, R.id.fman_action_sort_by_date, 0, R.string.fman_sort_by_date);
        if ((mode & MODE_SORTING) == SORT_DATE)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_date);
        }
        if (activeSort != null)
        {
            activeSort.setCheckable(true);
            activeSort.setChecked(true);
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
Example 20
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
  AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
  menu.setHeaderTitle(adapterApplications.getItem(info.position).getDescription());
  menu.add(ContextMenu.NONE, MENU_INFO, ContextMenu.NONE, R.string.info);
}