Example usage for android.view MenuItem getMenuInfo

List of usage examples for android.view MenuItem getMenuInfo

Introduction

In this page you can find the example usage for android.view MenuItem getMenuInfo.

Prototype

public ContextMenuInfo getMenuInfo();

Source Link

Document

Gets the extra information linked to this menu item.

Usage

From source file:com.imalu.alyou.activity.ContactlistFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete_contact) {
        HXUser tobeDeleteUser = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
        // ?/*from w  w w.j  av  a2s . c om*/
        deleteContact(tobeDeleteUser);
        // ?
        InviteMessgeDao dao = new InviteMessgeDao(getActivity());
        dao.deleteMessage(tobeDeleteUser.getUsername());
        return true;
    } else if (item.getItemId() == R.id.add_to_blacklist) {
        HXUser user = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
        moveToBlacklist(user.getUsername());
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // The data from the menu item.
    AdapterView.AdapterContextMenuInfo info;

    try {/*from  w  ww.jav a  2 s .c  om*/
        // Casts the data object in the item into the type for AdapterView objects.
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {

        // If the object can't be cast, logs an error
        Log.e(TAG, "bad menuInfo", e);

        // Triggers default processing of the menu item.
        return false;
    }
    // Appends the selected recipe's ID to the URI sent with the incoming Intent.
    Uri recipeUri = ContentUris.withAppendedId(getIntent().getData(), info.id);

    /*
     * Gets the menu item's ID and compares it to known actions.
     */
    switch (item.getItemId()) {
    case R.id.context_open:
        // Launch activity to view/edit the currently selected item
        startActivity(new Intent(Intent.ACTION_EDIT, recipeUri));
        return true;

    case R.id.context_delete:
        getContentResolver().delete(recipeUri, // The URI of the provider
                null, // No where clause is needed, since only a single recipe ID is being
                // passed in.
                null // No where clause is used, so no where arguments are needed.
        );

        // Returns to the caller and skips further processing.
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.kciray.android.filemanager.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    FileMenu menuEnum = FileMenu.values()[menuItemIndex];
    int itemIndex = info.position;

    switch (menuEnum) {
    case DELETE:// w  w w  . jav  a  2s  .com
        activeDirView.deleteItem(itemIndex);
        break;
    case PROPERTIES:
        activeDirView.showProp(itemIndex);
        break;
    case RENAME:
        activeDirView.renameItem(itemIndex);
        break;
    case CALC_SIZE:
        activeDirView.calcFolderSize(itemIndex);
        break;
    case OPEN_INTENT:
        activeDirView.openIntent(itemIndex);
        break;
    case SEND_TO_HOME_SCREEN:
        activeDirView.sendToHomeScreen(itemIndex);
        break;
    case COPY_FULL_PATH:
        activeDirView.copyFullPath(itemIndex);
        break;
    }

    return true;
}

From source file:com.sim2dial.dialer.HistorySimpleFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    TextView tv = (TextView) info.targetView.getRootView().findViewById(R.id.rowid);

    if (tv.getId() == R.id.rowid) {
        LinphoneActivity.instance().deleteRow(tv.getText().toString());
    }/*ww  w. j av a2  s.  c o  m*/
    /*
     * if (item.getItemId() == R.id.item1) { LinphoneCallLog log =
     * mLogs.get(info.position); LinphoneManager.getLc().removeCallLog(log);
     * mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs()); if
     * (!hideHistoryListAndDisplayMessageIfEmpty()) {
     * historyList.setAdapter(new CallHistoryAdapter(getActivity())); } }
     */
    return false;
}

From source file:com.BreakingBytes.SifterReader.SifterReader.java

/** Methods for selected list context menu option. */
@Override// ww  w.j a v  a2s  .co m
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case MILESTONES_ID:
        getProjDetail(info.id, MILESTONES_URL, MILESTONES, MilestonesActivity.class);
        return true;
    case CATEGORIES_ID:
        getProjDetail(info.id, CATEGORIES_URL, CATEGORIES, CategoriesActivity.class);
        return true;
    case PEOPLE_ID:
        getProjDetail(info.id, PEOPLE_URL, PEOPLE, PeopleActivity.class);
        return true;
    case ISSUES_ID:
        getProjDetail(info.id, ISSUES_URL, ISSUES, IssuesActivity.class);
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:edu.cmu.cylab.starslinger.view.PickRecipientsActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    RecipientRow recip = mContacts.get(info.position);
    if (item.getItemId() == R.id.item_key_details) {
        showHelp(getString(R.string.title_RecipientDetail),
                formatRecpientDetails(PickRecipientsActivity.this, recip));
        return true;
    } else if (item.getItemId() == R.id.item_delete_recipient) {
        doDeleteRecipient(recip);//w w  w  .ja va  2  s  .c  o  m
        updateValues(null);
        return true;
    } else if (item.getItemId() == R.id.item_link_contact_add
            || item.getItemId() == R.id.item_link_contact_change) {
        showUpdateContactLink(recip.getRowId());
        return true;
    } else if (item.getItemId() == R.id.item_edit_contact) {
        showEditContact(recip.getContactlu());
        return true;
    } else {
        return super.onContextItemSelected(item);
    }
}

From source file:nz.co.wholemeal.christchurchmetro.PlatformActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Arrival arrival = (Arrival) arrivals.get((int) info.id);
    Intent intent;/*from  ww  w .  j a  va2  s.c o m*/

    switch (item.getItemId()) {
    case R.id.set_alarm:
        Log.d(TAG, "Set alarm selected");
        createAlarmDialog(arrival);
        return true;
    case R.id.timetable:
        Log.d(TAG, "Timetable selected for route " + arrival.routeNumber);
        Uri uri = Uri
                .parse("http://rtt.metroinfo.org.nz/rtt/public/Schedule.aspx?RouteNo=" + arrival.routeNumber);
        intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.meetingninja.csse.notes.NotesFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    int position = item.getItemId();
    boolean handled = false;
    AdapterContextMenuInfo aInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (item.getGroupId() == MainActivity.DrawerLabel.NOTES.getPosition()) {
        switch (item.getOrder()) {
        case 1: // Add Content
            Toast.makeText(getActivity(), String.format("%s", item.getTitle()), Toast.LENGTH_SHORT).show();
            handled = true;//from w  w  w  .  j  a  v a2 s.c om
            break;
        case 2: // Delete
            delete(noteAdpt.getItem(position));
            handled = true;
            break;
        case 3:
            Intent versionControl = new Intent(getActivity(), VersionControlActivity.class);
            startActivity(versionControl);
            handled = true;
            break;
        case 4:
            Note n = noteAdpt.getItem(position);
            if (mergeNote == null) {
                Log.d("MERGE", "merge_a: " + n.getID());
                mergeNote = n;
                Toast.makeText(getActivity(), String.format("Select second note to merge."), Toast.LENGTH_LONG)
                        .show();
            } else if (mergeNote.getID().equalsIgnoreCase(n.getID())) {
                Log.d("MERGE", "merge_b: " + n.getID() + " : " + mergeNote.getID());
                mergeNote = null;
                Toast.makeText(getActivity(),
                        String.format("Error: Same note selected twice. Please reselect notes to merge."),
                        Toast.LENGTH_LONG).show();
            } else {
                Log.d("MERGE", "merge_c: " + n.getID() + " : " + mergeNote.getID());
                Toast.makeText(getActivity(),
                        String.format("Merging " + n.getTitle() + " into " + mergeNote.getTitle()),
                        Toast.LENGTH_LONG).show();
                mergeNote.setContent(mergeNote.getContent() + "\n" + n.getContent());
                delete(n);
                updateNote(mergeNote);
                mergeNote = null;
                populateList();
            }
            break;
        default:
            Log.wtf(TAG, "Invalid context menu option selected");
            break;
        }
    } else {
        Log.wtf(TAG, "What happened here?");
    }

    return handled;
}

From source file:com.money.manager.ex.fragment.PayeeListFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = null;
    if (item.getMenuInfo() instanceof AdapterView.AdapterContextMenuInfo) {
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } else {/* w ww  .jav  a2 s  .c o  m*/
        return false;
    }
    //        if (item.getMenuInfo() instanceof ExpandableListView.ExpandableListContextMenuInfo) {
    //            info = item.getMenuInfo();
    //        }

    Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor();
    cursor.moveToPosition(info.position);

    // Read values from cursor.
    Payee payee = new Payee();
    payee.loadFromCursor(cursor);

    ContextMenuIds menuId = ContextMenuIds.get(item.getItemId());
    if (menuId == null)
        return false;

    switch (menuId) {
    case EDIT:
        showDialogEditPayeeName(SQLTypeTransaction.UPDATE, payee.getId(), payee.getName());
        break;

    case DELETE:
        PayeeService service = new PayeeService(getActivity());
        if (!service.isPayeeUsed(payee.getId())) {
            showDialogDeletePayee(payee.getId());
        } else {
            new AlertDialogWrapper(getActivity()).setTitle(R.string.attention)
                    .setIcon(new UIHelper(getActivity()).getIcon(GoogleMaterial.Icon.gmd_warning))
                    .setMessage(R.string.payee_can_not_deleted).setPositiveButton(android.R.string.ok)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }
        break;

    case VIEW_TRANSACTIONS:
        SearchParameters parameters = new SearchParameters();
        parameters.payeeId = payee.getId();
        parameters.payeeName = payee.getName();

        Intent intent = IntentFactory.getSearchIntent(getActivity(), parameters);
        startActivity(intent);
    }
    return false;
}

From source file:com.qbcps.sifterclient.SifterReader.java

/** Methods for selected list context menu option. */
@Override/*w  ww . j  a va  2  s .co m*/
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    assert info != null;
    switch (item.getItemId()) {
    case MILESTONES_ID:
        getProjDetail(info.id, MILESTONES_URL, MILESTONES, MilestonesActivity.class);
        return true;
    case CATEGORIES_ID:
        getProjDetail(info.id, CATEGORIES_URL, CATEGORIES, CategoriesActivity.class);
        return true;
    case PEOPLE_ID:
        getProjDetail(info.id, PEOPLE_URL, PEOPLE, PeopleActivity.class);
        return true;
    case ISSUES_ID:
        getProjDetail(info.id, ISSUES_URL, ISSUES, IssuesActivity.class);
        return true;
    }
    return super.onContextItemSelected(item);
}