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:sjizl.com.ChatFriendListFragment.java

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

    switch (item.getItemId()) {
    case R.id.delete:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        naam_to_delete = stock_list2.get(info.position);
        new DeleteConversation().execute();

        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 {/*from w  w w .j a va  2s.  c om*/
            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 true;
    }
    return false;
}

From source file:org.bombusim.lime.fragments.ChatFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.cmdCopy:
        try {/*from w  ww .j  a  va2  s.  co m*/
            String s = ((MessageView) (info.targetView)).toString();

            // Gets a handle to the clipboard service.
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);

            // Set the clipboard's primary clip.
            clipboard.setText(s);

        } catch (Exception e) {
        }
        return true;

    case R.id.cmdDelete:

        chatListView.setVisibility(View.GONE);
        mChat.removeFromHistory(info.id);
        refreshVisualContent();

        return true;

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

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooser.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    View v = info.targetView;/*from  w  ww .ja  va2  s .c  om*/
    final Option o = adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case R.id.mnuDelete:
        String msg = String.format(getString(R.string.txtReallyDelete), o.getName());
        if (lib.ShowMessageYesNo(_main, msg, _main.getString(R.string.question)) == lib.yesnoundefined.yes) {
            try {
                File F = new File(o.getPath());
                boolean delete = false;
                if (F.exists()) {
                    if (F.isDirectory()) {
                        String[] deleteCmd = { "rm", "-r", F.getPath() };
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec(deleteCmd);
                        delete = true;
                    } else {
                        delete = F.delete();
                    }
                }

                if (delete)
                    adapter.remove(o);

            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        //lib.ShowToast(_main,"delete " + t1.getText().toString() + " " + t2.getText().toString() + " " + o.getData() + " "  + o.getPath() + " " + o.getName());
        //editNote(info.id);
        return true;
    case R.id.mnuRename:
        String msg2 = String.format(getString(R.string.txtRenameFile), o.getName());
        AlertDialog.Builder A = new AlertDialog.Builder(_main);
        final EditText inputRename = new EditText(_main);
        A.setMessage(msg2);
        A.setTitle(getString(R.string.rename));

        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        inputRename.setInputType(InputType.TYPE_CLASS_TEXT);
        inputRename.setText(o.getName());
        A.setView(inputRename);
        A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String name = inputRename.getText().toString();
                final String pattern = ".+\\.(((?i)v.{2})|((?i)k.{2})|((?i)dic))$";
                Pattern vok = Pattern.compile(pattern);
                if (lib.libString.IsNullOrEmpty(name))
                    return;
                if (vok.matcher(name).matches()) {
                    try {

                        File F = new File(o.getPath());
                        File F2 = new File(F.getParent(), name);
                        if (!F2.exists()) {
                            final boolean b = F.renameTo(F2);
                            if (b) {
                                o.setName(name);
                                o.setPath(F2.getPath());
                                adapter.notifyDataSetChanged();
                            }
                        } else {
                            lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                        }

                    } catch (Exception ex) {
                        lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
                    }
                } else {
                    AlertDialog.Builder A = new AlertDialog.Builder(_main);
                    A.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });
                    A.setMessage(getString(R.string.msgWrongExt2));
                    A.setTitle(getString(R.string.message));
                    AlertDialog dlg = A.create();
                    dlg.show();

                }
            }
        });
        A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        AlertDialog dlg = A.create();
        dlg.show();
        return true;
    case R.id.mnuCopy:
        _copiedFile = (o.getPath());
        _cutFile = null;
        return true;
    case R.id.mnuCut:
        _cutFile = (o.getPath());
        _cutOption = o;
        _copiedFile = null;
        return true;
    case R.id.mnuPaste:
        if (_cutFile != null && _copiedFile != null)
            return true;
        String path;
        File F = new File(o.getPath());
        if (F.isDirectory()) {
            path = F.getPath();
        } else {
            path = F.getParent();
        }
        if (_copiedFile != null) {
            File source = new File(_copiedFile);
            File dest = new File(path, source.getName());
            if (dest.exists()) {
                lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                return true;
            }
            String[] copyCmd;
            if (source.isDirectory()) {
                copyCmd = new String[] { "cp", "-r", _copiedFile, path };
            } else {
                copyCmd = new String[] { "cp", _copiedFile, path };
            }
            Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec(copyCmd);
                Option newOption;
                if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) {
                    if (dest.isDirectory() && !dest.isHidden()) {
                        adapter.add(new Option(dest.getName(), getString(R.string.folder),
                                dest.getAbsolutePath(), true, false, false));
                    } else {
                        if (!dest.isHidden())
                            adapter.add(new Option(dest.getName(),
                                    getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(),
                                    false, false, false));
                    }
                }
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }

        } else if (_cutFile != null) {
            File source = new File(_cutFile);
            File dest = new File(path, source.getName());
            if (dest.exists()) {
                lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                return true;
            }
            String[] copyCmd;
            if (source.isDirectory()) {
                copyCmd = new String[] { "mv", "-r", _cutFile, path };
            } else {
                copyCmd = new String[] { "mv", _cutFile, path };
            }
            Runtime runtime = Runtime.getRuntime();
            _cutFile = null;
            try {
                runtime.exec(copyCmd);
                Option newOption;
                try {
                    adapter.remove(_cutOption);
                    _cutOption = null;
                } catch (Exception e) {

                }
                if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) {
                    if (dest.isDirectory() && !dest.isHidden()) {
                        adapter.add(new Option(dest.getName(), getString(R.string.folder),
                                dest.getAbsolutePath(), true, false, false));
                    } else {
                        if (!dest.isHidden())
                            adapter.add(new Option(dest.getName(),
                                    getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(),
                                    false, false, false));
                    }
                }
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        return true;
    case R.id.mnuNewFolder:
        A = new AlertDialog.Builder(_main);
        //final EditText input = new EditText(_main);
        final EditText inputNF = new EditText(_main);
        A.setMessage(getString(R.string.msgEnterNewFolderName));
        A.setTitle(getString(R.string.cmnuNewFolder));

        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        inputNF.setInputType(InputType.TYPE_CLASS_TEXT);
        inputNF.setText("");
        A.setView(inputNF);
        A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String name = inputNF.getText().toString();
                if (lib.libString.IsNullOrEmpty(name))
                    return;
                String NFpath;
                File NF = new File(o.getPath());
                if (NF.isDirectory()) {
                    NFpath = NF.getPath();
                } else {
                    NFpath = NF.getParent();
                }
                try {
                    File NewFolder = new File(NFpath, name);
                    NewFolder.mkdir();
                    adapter.add(new Option(NewFolder.getName(), getString(R.string.folder),
                            NewFolder.getAbsolutePath(), true, false, false));

                } catch (Exception ex) {
                    lib.ShowException(_main, ex);
                }
            }
        });
        A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dlg = A.create();
        dlg.show();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.ros.android.app_chooser.ExchangeActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    int groupId = item.getGroupId();
    switch (groupId) {
    case INSTALLED_ITEM_ID:
        switch (menuItemIndex) {
        case 0://from  w  w  w . j  a v  a  2 s  .  c o m
            uninstallApp(installedAppListView);
            return true;
        default:
            return false;
        }
    case AVAILABLE_ITEM_ID:
        switch (menuItemIndex) {
        case 0:
            installApp(availableAppListView);
            return true;
        default:
            return false;
        }
    default:
        return false;
    }
}

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    View v = info.targetView;//from   w w w.ja v  a  2  s. c o m
    RowData o = adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case R.id.mnuDelete:
        String msg = String.format(getString(R.string.txtReallyDelete), o.name);
        if (lib.ShowMessageYesNo(_main, msg, _main.getString(R.string.question)) == lib.yesnoundefined.yes) {
            try {
                /*
                File F = new File(o.getPath());
                if (F.exists()) {
                   if (F.isDirectory()) {
                String [] deleteCmd = {"rm", "-r", F.getPath()};
                Runtime runtime = Runtime.getRuntime();
                runtime.exec(deleteCmd);
                   } else {
                F.delete();
                   }
                }
                */
                adapter.remove(o);

            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        //lib.ShowToast(_main,"delete " + t1.getText().toString() + " " + t2.getText().toString() + " " + o.getData() + " "  + o.getPath() + " " + o.getName());
        //editNote(info.id);
        return true;
    case R.id.mnuRename:
        String msg2 = String.format(getString(R.string.txtRenameFile), o.name);
        lib.OkCancelStringResult res = lib.InputBox(_main, getString(R.string.rename), msg2, o.name, false);
        if (res.res == lib.okcancelundefined.ok.ok && !lib.libString.IsNullOrEmpty(res.input)
                && res.input != o.name) {
            try {
                /*
                File F = new File(o.getPath());
                File F2 = new File(F.getParent(),res.input);
                F.renameTo(F2);
                */
                o.name = (res.input);
                //o.setPath(F2.getPath());
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        //lib.ShowToast(_main, "rename " + t1.getText().toString() + " " + t2.getText().toString() + " " + o.getData() + " "  + o.getPath() + " " + o.getName());
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.kyakujin.android.autoeco.ui.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {//from   w  w  w  .  j a  v  a  2  s.c  o m
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return false;
    }

    mCurrentSchedUri = ContentUris.withAppendedId(SchedTbl.CONTENT_URI, info.id);
    switch (item.getItemId()) {
    case R.id.context_delete:
        // ?
        AlertDialog dlg = new AlertDialog.Builder(this).setTitle(R.string.alert_title_delete)
                .setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.alert_message_delete_sched)
                .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // ???
                        SchedModel model = new SchedModel();
                        model.setId(Integer.valueOf(mCurrentSchedUri.getLastPathSegment()));
                        SchedAlarmManager am = new SchedAlarmManager(mActivity);
                        am.cancelAlarm(model);

                        // DB??
                        SchedDAO dao = new SchedDAO(mActivity);
                        dao.deleteSchedById(Integer.valueOf(mCurrentSchedUri.getLastPathSegment()));

                        mCurrentSchedUri = null;

                        // ????
                        // NOTE:?????????
                        activityRestart();
                    }
                }).setNegativeButton("NO", null).setInverseBackgroundForced(true).create();
        dlg.show();
        return true;
    case R.id.context_edit:
        setTime();
        // mManager.restartLoader(Query.LOADER_ID, null, this);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.thomasamsler.android.flashcards.fragment.CardSetsFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int listItemPosition = (int) getListAdapter().getItemId(info.position);

    switch (item.getGroupId()) {

    case MENU_ITEM_ADD:
        addCard(listItemPosition);/*ww w.  j  a  va2s.c  o  m*/
        break;
    case MENU_ITEM_DELETE:
        deleteCardSet(listItemPosition);
        break;
    default:
        Log.w(AppConstants.LOG_TAG, "List context menu selection not recognized.");
    }

    return false;
}

From source file:com.gh4a.fragment.EventListFragment.java

public boolean open(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    Event event = (Event) mAdapter.getItem(info.position);
    EventRepository eventRepo = event.getRepo();
    String[] repoNamePart = eventRepo.getName().split("/");
    String repoOwner = null;// ww  w . ja  v  a2  s  .c om
    String repoName = null;
    if (repoNamePart.length == 2) {
        repoOwner = repoNamePart[0];
        repoName = repoNamePart[1];
    }

    String title = item.getTitle().toString();
    String value = title.split(" ")[1];

    Gh4Application context = ((BaseSherlockFragmentActivity) getActivity()).getApplicationContext();

    /** User item */
    if (title.startsWith("User")) {
        context.openUserInfoActivity(getSherlockActivity(), value, null);
    }
    /** Repo item */
    else if (title.startsWith("Repo")) {
        context.openRepositoryInfoActivity(getSherlockActivity(), repoOwner, repoName, 0);
    }
    /** Commit item */
    else if (title.startsWith("Commit")) {
        if (repoOwner != null) {
            context.openCommitInfoActivity(getSherlockActivity(), repoOwner, repoName, value, 0);
        } else {
            context.notFoundMessage(getSherlockActivity(), R.plurals.repository);
        }
    }
    /** Issue comment item */
    else if (title.startsWith("Open issues")) {
        context.openIssueListActivity(getSherlockActivity(), repoOwner, repoName,
                Constants.Issue.ISSUE_STATE_OPEN);
    }
    /** Issue item */
    else if (title.startsWith("Issue")) {
        IssuesPayload payload = (IssuesPayload) event.getPayload();
        context.openIssueActivity(getSherlockActivity(), repoOwner, repoName, payload.getIssue().getNumber());
    }
    /** Commit comment item */
    else if (title.startsWith("Comment in browser")) {
        CommitCommentPayload payload = (CommitCommentPayload) event.getPayload();
        context.openBrowser(getSherlockActivity(), payload.getComment().getUrl());
    }
    /** Gist item */
    else if (title.startsWith("Gist")) {
        GistPayload payload = (GistPayload) event.getPayload();
        context.openGistActivity(getSherlockActivity(), payload.getGist().getUser().getLogin(),
                payload.getGist().getId(), 0);
    }
    /** Download item */
    else if (title.startsWith("File")) {
        if (repoOwner != null) {
            DownloadPayload payload = (DownloadPayload) event.getPayload();
            context.openBrowser(getSherlockActivity(), payload.getDownload().getHtmlUrl());
        } else {
            context.notFoundMessage(getSherlockActivity(), R.plurals.repository);
        }
    }
    /** Fork item */
    else if (title.startsWith("Forked repo")) {
        ForkPayload payload = (ForkPayload) event.getPayload();
        Repository forkee = payload.getForkee();
        if (forkee != null) {
            context.openRepositoryInfoActivity(getSherlockActivity(), forkee);
        } else {
            context.notFoundMessage(getSherlockActivity(), R.plurals.repository);
        }
    }
    /** Wiki item */
    else if (title.startsWith("Wiki in browser")) {
        GollumPayload payload = (GollumPayload) event.getPayload();
        List<GollumPage> pages = payload.getPages();
        if (pages != null && !pages.isEmpty()) {//TODO: now just open the first page
            context.openBrowser(getSherlockActivity(), pages.get(0).getHtmlUrl());
        }
    }
    /** Pull Request item */
    else if (title.startsWith("Pull request")) {
        PullRequestPayload payload = (PullRequestPayload) event.getPayload();
        context.openPullRequestActivity(getSherlockActivity(), repoOwner, repoName, payload.getNumber());
    }

    else if (title.startsWith("Compare")) {
        if (repoOwner != null) {
            PushPayload payload = (PushPayload) event.getPayload();

            Intent intent = new Intent().setClass(context, CompareActivity.class);
            intent.putExtra(Constants.Repository.REPO_OWNER, repoOwner);
            intent.putExtra(Constants.Repository.REPO_NAME, repoName);
            intent.putExtra(Constants.Repository.HEAD, payload.getHead());
            intent.putExtra(Constants.Repository.BASE, payload.getBefore());
            startActivity(intent);
        }
    }
    return true;
}

From source file:it.geosolutions.geocollect.android.core.form.FormEditActivity.java

/**
 * // w  w  w. ja va 2 s  .  co  m
 * @author Lorenzo Pini
        
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultIntent) {
   super.onActivityResult(requestCode, resultCode, resultIntent);
           
           
           
}
 */

// Context menu for images

@Override
public boolean onContextItemSelected(MenuItem item) {
    // super.onContextItemSelected(item);
    if (item != null) {
        switch (item.getItemId()) {
        case CONTEXT_IMAGE_ACTION_DELETE:
            Log.v("FEA", "Need to delete the image");
            if (item.getMenuInfo() != null && item.getMenuInfo() instanceof AdapterContextMenuInfo) {
                final AdapterContextMenuInfo aminfo = (AdapterContextMenuInfo) item.getMenuInfo();
                Log.v("FEA", "Target view type: " + aminfo.targetView.getClass().getName());
                String imagepath = (String) aminfo.targetView.getTag(R.id.tag_image_path);
                if (imagepath != null) {
                    Log.v("FEA", "ImagePath: " + imagepath);

                    final String imagePath = imagepath;
                    new AlertDialog.Builder(this).setTitle(R.string.button_confirm_image_delete_title)
                            .setMessage(R.string.button_confirm_image_delete)
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                    FormUtils.deleteFile(imagePath);
                                    ((UILImageAdapter) ((GridView) aminfo.targetView.getParent()).getAdapter())
                                            .notifyDataSetChanged();
                                }
                            }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    // do nothing
                                }
                            }).show();

                    return true;
                }
            }
            break;

        default:
            break;
        }

        return false;
    }
    return false;
}

From source file:com.hx.hxchat.activity.ChatHistoryFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.delete_message) {
        EMContact tobeDeleteUser = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
        boolean isGroup = false;
        if (tobeDeleteUser instanceof EMGroup)
            isGroup = true;/*from ww w.  j  a v a2 s  .  c o  m*/

        // ?
        boolean deleteConversation = EMChatManager.getInstance()
                .deleteConversation(tobeDeleteUser.getUsername());
        InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(getActivity());
        inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername());

        BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername());

        adapter.remove(tobeDeleteUser);
        adapter.notifyDataSetChanged();

        // ?
        // TODO
        // ((MainActivity) getActivity()).updateUnreadLabel();

        return true;
    }
    return super.onContextItemSelected(item);
}