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:info.corne.performancetool.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());
    String selectedItem = (String) profilesAdapter.getItem(info.position);
    switch (itemId) {
    case 1://w w  w  .j av  a 2s.  co m
        showDetailsDialog(selectedItem, sharedPreferences);
        break;
    case 2:
        if (info.position == 0 || info.position == 1 || info.position == 2) {
            Toast.makeText(this, getResources().getString(R.string.default_no_remove), Toast.LENGTH_SHORT)
                    .show();
        } else {
            Editor editor = sharedPreferences.edit();
            String profiles = sharedPreferences.getString(Settings.PROFILES, "").replace("|" + selectedItem,
                    "");
            editor.putString(Settings.PROFILES, profiles);

            for (int i = 0; i < Settings.ALL_PROFILE.length; i++) {
                String settings = Settings.ALL_PROFILE[i];
                editor.remove(settings + selectedItem);
            }
            editor.commit();
            refreshProfilesList();
        }
        break;
    }

    return true;
}

From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java

@Override
public boolean onContextItemSelected(final MenuItem aItem) {

    final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) aItem
            .getMenuInfo();//from w  w  w. j  ava 2s.  c  om

    // To get the id of the clicked item in the list use menuInfo.id
    Log.e(EBookLauncherApplication.LOG_TAG,
            EBookLauncherActivity.LOG_TAG + "list pos:" + menuInfo.position + " id:" + menuInfo.id);
    final Book bk = myApp.dataMdl.getBook(this, menuInfo.id);

    switch (aItem.getItemId()) {

    case CONTEXTMENU_VIEW_DETAILS:
        Log.d(EBookLauncherApplication.LOG_TAG + EBookLauncherActivity.LOG_TAG,
                "Show details of book: " + bk.toString());
        startActivity(new Intent(this, BookDetailsActivity.class));
        return true;

    case CONTEXTMENU_OPEN_BOOK:
        return true;

    case CONTEXTMENU_DELETE_BOOK:
        Log.d(EBookLauncherApplication.LOG_TAG + EBookLauncherActivity.LOG_TAG,
                "Delete book: " + bk.toString());
        // this.myApp.getCalibreController().deleteBook(this.myApp.contextMenuSelectedBook);
        return true;

    default:
        return super.onContextItemSelected(aItem);
    }
}

From source file:com.googlecode.networklog.LogFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (!(item.getMenuInfo() instanceof AdapterContextMenuInfo))
        return super.onContextItemSelected(item);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    ListItem listItem = listData.get(info.position);

    switch (item.getItemId()) {
    case R.id.log_copy_src_ip:
        copySourceIp(listItem);/*from w ww . ja v  a  2 s  .co  m*/
        return true;
    case R.id.log_copy_dst_ip:
        copyDestIp(listItem);
        return true;
    case R.id.log_whois_src_ip:
        whoisSourceIp(listItem);
        return true;
    case R.id.log_whois_dst_ip:
        whoisDestIp(listItem);
        return true;
    case R.id.log_graph:
        showGraph(listItem);
        return true;
    case R.id.log_toggle_app_notifications:
        if (NetworkLogService.toastBlockedApps.remove(listItem.app.packageName) == null) {
            NetworkLogService.toastBlockedApps.put(listItem.app.packageName, listItem.app.packageName);
        }
        new SelectToastApps().saveBlockedApps(NetworkLog.context, NetworkLogService.toastBlockedApps);
        return true;
    case R.id.log_toggle_app_logging:
        if (NetworkLogService.blockedApps.remove(listItem.app.packageName) == null) {
            NetworkLogService.blockedApps.put(listItem.app.packageName, listItem.app.packageName);
        }
        new SelectBlockedApps().saveBlockedApps(NetworkLog.context, NetworkLogService.blockedApps);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:sjizl.com.ChatActivityFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int index = info.position;
    String textTocopy = ArrChatLines.get(index).getLaatstBericht();

    switch (item.getItemId()) {
    case R.id.delete:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();

        Toast.makeText(getActivity().getApplicationContext(), "delete almost implementated", Toast.LENGTH_SHORT)
                .show();//from   w  ww .  ja  v a  2s  .c om
        return false;

    case R.id.copy:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("simple text", textTocopy);
            clipboard.setPrimaryClip(clip);
        } else {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(textTocopy);

        }

        //place your TextView's text in clipboard

        Toast.makeText(getActivity().getApplicationContext(), "Item copied", Toast.LENGTH_SHORT).show();
        return false;
    }
    return false;
}

From source file:com.pdftron.pdf.controls.UserBookmarkDialogFragment.java

public boolean onPopupItemSelected(MenuItem item, int position) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    switch (menuItemIndex) {
    case CONTEXT_MENU_EDIT_ITEM:
        mModified = true;//from  ww w.j  a v  a2 s .co  m

        mBookmarkViewAdapter.setEditMode(true);
        mBookmarkViewAdapter.setSelectedIndex(position);
        mBookmarkViewAdapter.notifyDataSetChanged();

        com.pdftron.pdf.utils.AnalyticsHandlerAdapter.getInstance()
                .sendEvent(AnalyticsHandlerAdapter.CATEGORY_BOOKMARK, "User Bookmark Rename Clicked");
        break;
    case CONTEXT_MENU_DELETE_ITEM:
        mModified = true;

        if (!mReadOnly) {
            boolean needUnlock = false;
            try {
                mPDFDoc.lock();
                needUnlock = true;
                if (mBookmarkViewAdapter.getItem(position).pdfBookmark != null) {
                    mBookmarkViewAdapter.getItem(position).pdfBookmark.delete();
                }
            } catch (Exception e) {

            } finally {
                if (needUnlock) {
                    try {
                        mPDFDoc.unlock();
                    } catch (PDFNetException ex) {
                    }
                }
            }
        }
        mBookmarkViewAdapter.remove(mBookmarkViewAdapter.getItem(position));
        mBookmarkViewAdapter.notifyDataSetChanged();

        com.pdftron.pdf.utils.AnalyticsHandlerAdapter.getInstance()
                .sendEvent(AnalyticsHandlerAdapter.CATEGORY_BOOKMARK, "User Bookmark Delete Clicked");
        break;
    case CONTEXT_MENU_DELETE_ALL:
        mModified = true;

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.controls_bookmark_dialog_delete_all_message)
                .setTitle(R.string.controls_misc_delete_all)
                .setPositiveButton(R.string.tools_misc_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (!mReadOnly) {
                            removeRootPDFBookmark(mPDFDoc);
                        }
                        mBookmarkViewAdapter.clear();
                        mBookmarkViewAdapter.notifyDataSetChanged();

                        com.pdftron.pdf.utils.AnalyticsHandlerAdapter.getInstance().sendEvent(
                                AnalyticsHandlerAdapter.CATEGORY_BOOKMARK, "User Bookmark Delete All Clicked");
                    }
                }).setNegativeButton(R.string.controls_misc_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // do nothing
                    }
                }).create().show();
        break;
    }
    return true;
}

From source file:org.mozilla.gecko.home.TopSitesPanel.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (super.onContextItemSelected(item)) {
        // HomeFragment was able to handle to selected item.
        return true;
    }//from  www  .  j  a  v  a 2 s  .c  o m

    ContextMenuInfo menuInfo = item.getMenuInfo();

    if (!(menuInfo instanceof TopSitesGridContextMenuInfo)) {
        return false;
    }

    TopSitesGridContextMenuInfo info = (TopSitesGridContextMenuInfo) menuInfo;

    final int itemId = item.getItemId();
    final BrowserDB db = GeckoProfile.get(getActivity()).getDB();

    if (itemId == R.id.top_sites_pin) {
        final String url = info.url;
        final String title = info.title;
        final int position = info.position;
        final Context context = getActivity().getApplicationContext();

        ThreadUtils.postToBackgroundThread(new Runnable() {
            @Override
            public void run() {
                db.pinSite(context.getContentResolver(), url, title, position);
            }
        });

        Telemetry.sendUIEvent(TelemetryContract.Event.PIN);
        return true;
    }

    if (itemId == R.id.top_sites_unpin) {
        final int position = info.position;
        final Context context = getActivity().getApplicationContext();

        ThreadUtils.postToBackgroundThread(new Runnable() {
            @Override
            public void run() {
                db.unpinSite(context.getContentResolver(), position);
            }
        });

        Telemetry.sendUIEvent(TelemetryContract.Event.UNPIN);

        return true;
    }

    if (itemId == R.id.top_sites_edit) {
        // Decode "user-entered" URLs before showing them.
        mEditPinnedSiteListener.onEditPinnedSite(info.position, StringUtils.decodeUserEnteredUrl(info.url));

        Telemetry.sendUIEvent(TelemetryContract.Event.EDIT);
        return true;
    }

    return false;
}

From source file:at.ac.uniklu.mobile.sportal.CourseListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (DEBUG)//from   w  w w.  j av  a2s  .  c  o  m
        Log.d(TAG, "onContextItemSelected " + getTag());
    /* WORKAROUND 
     * The onContextItemSelected event is received by all "visible" fragments, in this
     * case it is the currently displayed fragment in the ViewPager, and fragments beside
     * this displayed fragment that are preloaded and thus "visible" but not really visible
     * since they are outside the screen.
     * Anyway, since this event is received by all "visible" fragments, I need to make sure
     * that only the event handler of the currently displayed fragment gets executed.
     */
    if (((FragmentPagerSupport) getActivity()).getCurrentItemIndex() != mIndex) {
        return false;
    }

    Lehrveranstaltung course = mCourseModel.getCourse(((AdapterContextMenuInfo) item.getMenuInfo()).position);

    switch (item.getItemId()) {
    case R.id.details:
        Analytics.onEvent(Analytics.EVENT_WEB_COURSEDETAILS);
        Intent courseDetails = new Intent(getActivity(), WebViewActivity.class)
                .putExtra(WebViewActivity.URL, course.getDetailsUrl())
                .putExtra(WebViewActivity.TITLE, getString(R.string.course_details_title));
        startActivity(courseDetails);
        return true;
    case R.id.participants:
        Analytics.onEvent(Analytics.EVENT_COURSE_PARTICIPANTS, "rlvkey", course.getKey() + "");
        Intent participants = new Intent(getActivity(), CourseParticipantsListActivity.class)
                .putExtra(CourseListActivity.COURSE_KEY, course.getKey())
                .putExtra(CourseListActivity.COURSE_NAME, course.getTyp() + " " + course.getName());
        startActivity(participants);
        return true;
    case R.id.website:
        Analytics.onEvent(Analytics.EVENT_WEB_COURSEWEBSITE);
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(course.getWebsiteUrl())));
        return true;
    case R.id.moodle:
        Analytics.onEvent(Analytics.EVENT_WEB_COURSEMOODLE);
        Intent moodle = new Intent(getActivity(), WebViewActivity.class)
                .putExtra(WebViewActivity.URL, course.getMoodleUrl())
                .putExtra(WebViewActivity.TITLE, getString(R.string.moodle))
                .putExtra(WebViewActivity.MOODLE_HACK, true).putExtra(WebViewActivity.SSO, true);
        startActivity(moodle);
        return true;
    case R.id.checklists:
        Analytics.onEvent(Analytics.EVENT_COURSE_CHECKLISTS, "rlvkey", course.getKey() + "");
        Intent checklists = new Intent(getActivity(), CourseChecklistsActivity.class)
                .putExtra(CourseListActivity.COURSE_KEY, course.getKey())
                .putExtra(CourseListActivity.COURSE_NAME, course.getTyp() + " " + course.getName());
        startActivity(checklists);
        return true;
    case R.id.ignore:
        Analytics.onEvent(Analytics.EVENT_IGNORE_COURSE);
        if (item.isChecked()) {
            mDB.courseBlacklist_insert(course.getKey());
        } else {
            mDB.courseBlacklist_delete(course.getKey());
        }
        if (DEBUG)
            Log.d(TAG, "notifyDataSetChanged " + getTag());
        mCourseListAdapter.notifyDataSetChanged();
        mListener.onBlacklistChanged();
        return true;
    }

    return super.onContextItemSelected(item);
}

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

@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    if (item.getItemId() == R.id.item_delete_message) {
        doDeleteMessage(mMessageList.get(info.position));
        updateMessageList(false);/*from www.j  av a 2s  .  co  m*/
        return true;
    } else if (item.getItemId() == R.id.item_message_details) {
        String detailStr = BaseActivity.formatMessageDetails(getActivity(), mMessageList.get(info.position));
        showHelp(getString(R.string.title_MessageDetail), detailStr);
        return true;
    } else if (item.getItemId() == R.id.item_message_copytext) {
        SafeSlinger.getApplication().copyPlainTextToClipboard(mMessageList.get(info.position).getText());
        showNote(getString(R.string.state_TextCopiedToClipboard));
        return true;
    } else if (item.getItemId() == R.id.item_message_forward) {
        doForward(mMessageList.get(info.position));
        return true;
    } else if (item.getItemId() == R.id.item_debug_transcript) {
        doExportTranscript(mMessageList);
        return true;
    } else if (item.getItemId() == R.id.item_delete_thread) {
        doDeleteThread(mThreadList.get(info.position).getMsgRow().getKeyId());
        updateMessageList(false);
        return true;
    } else if (item.getItemId() == R.id.item_thread_details) {
        showHelp(getString(R.string.title_RecipientDetail),
                BaseActivity.formatThreadDetails(getActivity(), mThreadList.get(info.position)));
        return true;
    } else if (item.getItemId() == R.id.item_link_contact_add
            || item.getItemId() == R.id.item_link_contact_change) {
        ((BaseActivity) getActivity())
                .showUpdateContactLink(mThreadList.get(info.position).getRecipient().getRowId());
        return true;
    } else if (item.getItemId() == R.id.item_edit_contact) {
        ((BaseActivity) getActivity())
                .showEditContact(mThreadList.get(info.position).getRecipient().getContactlu());
        return true;
    } else {
        return super.onContextItemSelected(item);
    }
}

From source file:com.gsma.rcs.ri.messaging.GroupTalkView.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Cursor cursor = (Cursor) (mAdapter.getItem(info.position));
    int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID));
    String id = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID));
    if (LogUtils.isActive) {
        Log.d(LOGTAG, "onContextItemSelected Id=".concat(id));
    }// w  ww.  j  a  v  a 2 s .  c  o m
    try {
        switch (item.getItemId()) {
        case R.id.menu_view_group_delivery:
            GroupDeliveryInfoList.startActivity(this, id);
            return true;

        case R.id.menu_delete_message:
            if (ChatLog.Message.HISTORYLOG_MEMBER_ID == providerId) {
                mChatService.deleteMessage(id);
            } else {
                mFileTransferService.deleteFileTransfer(id);
            }
            return true;

        case R.id.menu_view_detail:
            if (ChatLog.Message.HISTORYLOG_MEMBER_ID == providerId) {
                ChatMessageLogView.startActivity(this, id);
            } else {
                FileTransferLogView.startActivity(this, id);
            }
            return true;

        case R.id.menu_display_content:
            if (FileTransferLog.HISTORYLOG_MEMBER_ID == providerId) {
                String file = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.CONTENT));
                Utils.showPicture(this, Uri.parse(file));
                markFileTransferAsRead(cursor, id);
                return true;
            }
            break;

        case R.id.menu_listen_content:
            if (FileTransferLog.HISTORYLOG_MEMBER_ID == providerId) {
                String file = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.CONTENT));
                Utils.playAudio(this, Uri.parse(file));
                markFileTransferAsRead(cursor, id);
                return true;
            }
            break;
        }
        return super.onContextItemSelected(item);
    } catch (RcsServiceException e) {
        showException(e);
    }
    return true;
}

From source file:info.staticfree.android.units.Units.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final ContextMenuInfo ctxMenuInfo = item.getMenuInfo();
    int position = history.getCount() - 1;
    if (ctxMenuInfo instanceof AdapterContextMenuInfo) {
        position = ((AdapterContextMenuInfo) ctxMenuInfo).position;
    }/*from   w  ww .  ja va  2  s.c om*/
    final Uri itemUri = ContentUris.withAppendedId(HistoryEntry.CONTENT_URI,
            mHistoryAdapter.getItemId(position));

    switch (item.getItemId()) {
    case MENU_COPY: {
        final CharSequence itemText = getEntryAsCharSequence(itemUri);
        final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipboard.setText(itemText);
        Toast.makeText(this, getString(R.string.toast_copy, itemText), Toast.LENGTH_SHORT).show();
    }
        break;

    case MENU_REEDIT: {
        setCurrentEntry(itemUri);
        setHistoryVisible(false);
    }
        break;

    case MENU_SEND: {
        final CharSequence itemText = getEntryAsCharSequence(itemUri);
        startActivity(Intent.createChooser(
                new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, itemText),
                getText(R.string.ctx_menu_send_title)));
    }
        break;

    case MENU_USE_RESULT: {
        final Cursor c = getContentResolver().query(itemUri, PROJECTION_LOAD_FROM_HISTORY, null, null, null);
        if (c.moveToFirst()) {
            final int resultCol = c.getColumnIndex(HistoryEntry._RESULT);
            setCurrentEntry((c.isNull(resultCol) ? "" : (c.getDouble(resultCol) + " "))
                    + c.getString(c.getColumnIndex(HistoryEntry._WANT)), "");
            setHistoryVisible(false);
        }
        c.close();
    }
        break;
    }

    return super.onContextItemSelected(item);
}