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:org.uguess.android.sysinfo.ProcessManager.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    int pos = ((AdapterContextMenuInfo) item.getMenuInfo()).position;

    if (pos < getListView().getCount()) {
        ProcessItem rap = (ProcessItem) getListView().getItemAtPosition(pos);

        if (item.getItemId() == MI_DISPLAY) {
            handleAction(rap, ACTION_SWITCH);

            return true;
        } else if (item.getItemId() == MI_ENDTASK) {
            handleAction(rap, ACTION_END);

            return true;
        } else if (item.getItemId() == MI_END_OTHERS) {
            handleAction(rap, ACTION_END_OTHERS);

            return true;
        } else if (item.getItemId() == MI_IGNORE) {
            handleAction(rap, ACTION_IGNORE);

            return true;
        } else if (item.getItemId() == MI_DETAILS) {
            handleAction(rap, ACTION_DETAILS);

            return true;
        }/*from   w  w  w .j a va2  s  . c  om*/
    }

    return super.onContextItemSelected(item);
}

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    final FileViewHolder holder = mContextViewHolder = (FileViewHolder) info.targetView.getTag();
    final boolean isDirectory = U1NodeKind.DIRECTORY == holder.kind;

    if (isDirectory) {
        switch (item.getItemId()) {
        case R.id.context_download:
            onDirectoryDownloadClicked(holder);
            break;
        case R.id.context_rename:
            onDirectoryRenameClicked(holder);
            break;
        case R.id.context_delete:
            onDirectoryDeleteClicked(holder);
            break;
        }//from   www .  ja  v a 2s .c o m
    } else {
        switch (item.getItemId()) {
        case R.id.context_download:
            onFileDownloadClicked(holder);
            break;
        case R.id.context_cancel_download:
            onFileCancelDownloadClicked(holder);
            break;
        case R.id.context_create_link:
            onFileCreateLinkClicked(holder);
            break;
        case R.id.context_share_link:
            onFileShareLinkClicked(holder);
            break;
        case R.id.context_disable_link:
            onFileDisableLinkClicked(holder);
            break;
        case R.id.context_rename:
            onFileRenameClicked(holder);
            break;
        case R.id.context_delete:
            onFileDeleteClicked(holder);
            break;
        case R.id.context_delete_from_device:
            onFileDeleteFromDeviceClicked(holder);
            break;
        }
    }

    return super.onContextItemSelected(item);
}

From source file:cgeo.geocaching.cgeocaches.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    ContextMenu.ContextMenuInfo info = item.getMenuInfo();

    // restore menu info for sub menu items, see
    // https://code.google.com/p/android/issues/detail?id=7139
    if (info == null) {
        info = lastMenuInfo;//from  ww w.j av a 2s  .  c om
        lastMenuInfo = null;
    }

    AdapterContextMenuInfo adapterInfo = null;
    try {
        adapterInfo = (AdapterContextMenuInfo) info;
    } catch (Exception e) {
        Log.w("cgeocaches.onContextItemSelected", e);
    }

    final Geocache cache = adapterInfo != null ? getCacheFromAdapter(adapterInfo) : null;

    // just in case the list got resorted while we are executing this code
    if (cache == null) {
        return true;
    }

    final int id = item.getItemId();
    switch (id) {
    case MENU_DEFAULT_NAVIGATION:
        NavigationAppFactory.startDefaultNavigationApplication(1, this, cache);
        break;
    case MENU_NAVIGATION:
        NavigationAppFactory.showNavigationMenu(this, cache, null, null);
        break;
    case MENU_CACHE_DETAILS:
        final Intent cachesIntent = new Intent(this, CacheDetailActivity.class);
        cachesIntent.putExtra(Intents.EXTRA_GEOCODE, cache.getGeocode());
        cachesIntent.putExtra(Intents.EXTRA_NAME, cache.getName());
        startActivity(cachesIntent);
        break;
    case MENU_DROP_CACHE:
        cache.drop(new Handler() {
            @Override
            public void handleMessage(Message msg) {
                adapter.notifyDataSetChanged();
                refreshCurrentList();
            }
        });
        break;
    case MENU_MOVE_TO_LIST:
        new StoredList.UserInterface(this).promptForListSelection(R.string.cache_menu_move_list,
                new RunnableWithArgument<Integer>() {

                    @Override
                    public void run(Integer newListId) {
                        cgData.moveToList(Collections.singletonList(cache), newListId);
                        adapter.setSelectMode(false);
                        refreshCurrentList();
                    }
                }, true, listId);
        break;
    case MENU_STORE_CACHE:
    case MENU_REFRESH:
        refreshStored(Collections.singletonList(cache));
        break;
    case MENU_EXPORT:
        ExportFactory.showExportMenu(Collections.singletonList(cache), this);
        return false;
    default:
        // we must remember the menu info for the sub menu, there is a bug
        // in Android:
        // https://code.google.com/p/android/issues/detail?id=7139
        lastMenuInfo = info;
        LoggingUI.onMenuItemSelected(item, this, cache);
    }

    return true;
}

From source file:com.plined.liftlog.WorkoutInstanceFragment.java

private ExerciseInstance getClickedExInt(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int position = info.position;

    //Figure out which we're trying to modify
    ExerciseInstanceCursorAdapter adapter = (ExerciseInstanceCursorAdapter) getListAdapter();
    ExerciseInstanceCursor exIntCursor = (ExerciseInstanceCursor) adapter.getItem(position - 1);
    return exIntCursor.getExerciseInstance();
}

From source file:pl.edu.agh.mindmapex.gui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.action_settings:
        Intent intent = new Intent(MainActivity.this, EditSheetScreen.class);
        if (sheet1.getStyleId() != null && styleSheet.findStyle(sheet1.getStyleId()) != null
                && styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor) != null) {
            intent.putExtra(BACKGROUNDCOLOR,
                    Color.parseColor(styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor)));
        } else {/*from   w w  w .  jav  a2s. co  m*/
            intent.putExtra(BACKGROUNDCOLOR, Color.WHITE);
        }
        startActivity(intent);
        return true;
    case R.id.action_undo:
        if (commandsUndo.size() == 1) {
            commandsUndo.getFirst().undo();
            if (commandsUndo.getFirst() instanceof EditBox) {
                Callback call = new Callback() {
                    @Override
                    public void execute() {
                        lay.updateBoxWithText(((EditBox) commandsUndo.getFirst()).box);
                        for (Box b : ((EditBox) commandsUndo.getLast()).edited) {
                            lay.updateBoxWithText(b);
                        }
                    }
                };
            } else if (commandsUndo.getFirst() instanceof EditSheet) {
                lay.setBackgroundColor((Color.parseColor(
                        MainActivity.styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor))));
            } else {
                Callback call = new Callback() {
                    @Override
                    public void execute() {
                    }
                };
                try {
                    AsyncInvalidate async = new AsyncInvalidate(MainActivity.this);
                    async.setCallback(call);
                    async.execute();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            commandsRedo.add(commandsUndo.getFirst());
            commandsUndo.removeFirst();
            menu.getItem(6).setVisible(true);
            menu.getItem(5).setVisible(false);
        } else {
            commandsUndo.getLast().undo();
            if (commandsUndo.getLast() instanceof EditBox) {
                lay.updateBoxWithText(((EditBox) commandsUndo.getLast()).box);
                for (Box b : ((EditBox) commandsUndo.getLast()).edited) {
                    lay.updateBoxWithText(b);
                }
            } else if (commandsUndo.getLast() instanceof EditSheet) {
                lay.setBackgroundColor(Integer.parseInt(sheet1.getTheme().getProperty(Styles.FillColor)));
            } else if (commandsUndo.getLast() instanceof AddBox || commandsUndo.getLast() instanceof RemoveLine
                    || commandsUndo.getLast() instanceof RemoveBox) {
            }
            commandsRedo.add(commandsUndo.getLast());
            menu.getItem(6).setVisible(true);
            commandsUndo.removeLast();
        }
        return true;
    case R.id.action_new:
        IStyle boxEditedStyle = workbook.getStyleSheet().findStyle(boxEdited.topic.getStyleId());
        Intent intent1 = new Intent(MainActivity.this, EditBoxScreen.class);
        if (boxEditedStyle != null) {

            intent1.putExtra(EditBoxScreen.BOX_COLOR, boxEditedStyle.getProperty(Styles.FillColor));
            intent1.putExtra(EditBoxScreen.TEXT_COLOR, boxEdited.topic.getTitleText());
            intent1.putExtra(EditBoxScreen.LINE_SHAPE, boxEditedStyle.getProperty(Styles.LineClass));
            intent1.putExtra(EditBoxScreen.LINE_COLOR, boxEditedStyle.getProperty(Styles.LineColor));
            intent1.putExtra(EditBoxScreen.BOX_SHAPE, boxEditedStyle.getProperty(Styles.ShapeClass));
            intent1.putExtra(EditBoxScreen.LINE_THICKNESS, boxEditedStyle.getProperty(Styles.LineWidth));
        }
        startActivity(intent1);
        // lay.invalidateDrawable(boxEdited.drawableShape);
        return true;
    case R.id.new_line:
        Properties properties1 = new Properties();
        properties1.put("child", MainActivity.toEditBoxes.getFirst());
        if (MainActivity.toEditBoxes.size() == 2) {
            properties1.put("parent", MainActivity.toEditBoxes.getLast());
        }
        AddLine addLine = new AddLine();
        addLine.execute(properties1);
        MainActivity.addCommendUndo(addLine);
        //   lay.invalidate();
        return true;
    case R.id.action_redo:
        if (commandsRedo.size() == 1) {
            commandsRedo.getFirst().redo();
            if (commandsRedo.getFirst() instanceof EditBox) {
                //     Callback call = new Callback() {
                //         @Override
                //        public void execute() {
                lay.updateBoxWithText(((EditBox) commandsRedo.getFirst()).box);
                for (Box b : ((EditBox) commandsRedo.getLast()).edited) {
                    lay.updateBoxWithText(b);
                }

            } else if (commandsRedo.getFirst() instanceof EditSheet) {
                lay.setBackgroundColor((Color.parseColor(
                        MainActivity.styleSheet.findStyle(sheet1.getStyleId()).getProperty(Styles.FillColor))));
            }
            //    lay.invalidate();
            commandsUndo.add(commandsRedo.getFirst());
            commandsRedo.removeFirst();
            menu.getItem(5).setVisible(true);
            menu.getItem(6).setVisible(false);
        } else {
            commandsRedo.getLast().redo();
            if (commandsRedo.getLast() instanceof EditBox) {
                lay.updateBoxWithText(((EditBox) commandsRedo.getLast()).box);
                for (Box b : ((EditBox) commandsRedo.getLast()).edited) {
                    lay.updateBoxWithText(b);
                }

            } else if (commandsRedo.getLast() instanceof EditSheet) {
                lay.setBackgroundColor(Integer.parseInt(sheet1.getTheme().getProperty(Styles.FillColor)));
            }
            //  lay.invalidate();
            commandsUndo.add(commandsRedo.getLast());
            menu.getItem(5).setVisible(true);
            commandsRedo.removeLast();
        }
        return true;
    case R.id.action_trash:
        RemoveBox removeBox = new RemoveBox();
        Properties properties = new Properties();
        HashMap<Box, Line> boxes = new HashMap<>();
        boxes.put(MainActivity.boxEdited, MainActivity.boxEdited.parent.getLines().get(MainActivity.boxEdited));
        for (Box b : MainActivity.toEditBoxes) {
            b.isSelected = false;
            boxes.put(b, b.parent.getLines().get(b));
            if (boxes.size() > 0) {
                properties.put("boxes", boxes);
                removeBox.execute(properties);
                MainActivity.addCommendUndo(removeBox);
            }
            //  return true;
        }
        menu.getItem(4).setVisible(false);
        menu.getItem(1).setVisible(false);
        menu.getItem(2).setVisible(false);
        menu.getItem(3).setVisible(false);
        MainActivity.toEditBoxes.clear();
        //   lay.invalidate();
        return true;
    case R.id.new_rel:
        if (!MainActivity.toEditBoxes.getFirst().relationships
                .containsValue(MainActivity.toEditBoxes.getLast())) {
            final Dialog dialog = DialogFactory.boxContentDialog(MainActivity.this);
            final Button btn = (Button) dialog.findViewById(R.id.dialogButtonOK);
            final EditText et = (EditText) dialog.findViewById(R.id.editText);
            et.requestFocus();
            final Button btn2 = (Button) dialog.findViewById(R.id.button2);
            btn2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Callback call = null;

                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
                    String text = (et.getText().toString());
                    AddRelationship addRel = new AddRelationship();
                    Properties p = new Properties();
                    p.put("boxes", MainActivity.toEditBoxes);
                    p.put("text", text);
                    addRel.execute(p);
                    MainActivity.addCommendUndo(addRel);
                    lay.drawRelationship(MainActivity.toEditBoxes.getFirst(), addRel.relation);
                    dialog.dismiss();

                }
            });

            final int MAX_LINES = 3;

            //ogranicza do 3 linii widok w zawartoci bloczka
            et.addTextChangedListener(new TextWatcher() {
                private int lines;

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    lines = Utils.countLines(s.toString());
                }

                @Override
                public void afterTextChanged(Editable s) {
                    int counter = Utils.countLines(s.toString());

                    int diff = lines - counter;
                    if (diff > 0) {
                        //w gore
                        if (counter < MAX_LINES - 1 && et.getLayoutParams().height > 75) {
                            LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) btn
                                    .getLayoutParams();
                            buttonLayoutParams.setMargins(buttonLayoutParams.leftMargin,
                                    buttonLayoutParams.topMargin - 30, buttonLayoutParams.rightMargin,
                                    buttonLayoutParams.bottomMargin);
                            btn.setLayoutParams(buttonLayoutParams);
                            btn2.setLayoutParams(buttonLayoutParams);
                            et.getLayoutParams().height -= 30;
                        }
                    } else if (diff < 0) {
                        //w dol
                        if (counter < MAX_LINES && et.getLayoutParams().height < 135) {
                            LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) btn
                                    .getLayoutParams();
                            buttonLayoutParams.setMargins(buttonLayoutParams.leftMargin,
                                    buttonLayoutParams.topMargin + 30, buttonLayoutParams.rightMargin,
                                    buttonLayoutParams.bottomMargin);
                            btn.setLayoutParams(buttonLayoutParams);
                            btn2.setLayoutParams(buttonLayoutParams);
                            et.getLayoutParams().height += 30;
                        }
                    }
                }
            });

            //                    et.setText(pair.first.topic.getNotes().getContent(INotes.PLAIN).getFormat());
            int k = Utils.countLines(et.getText().toString());
            int ile = Math.min(MAX_LINES - 1, k);

            et.getLayoutParams().height = 75 + ile * 30;
            LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) btn.getLayoutParams();
            buttonLayoutParams.setMargins(buttonLayoutParams.leftMargin,
                    buttonLayoutParams.topMargin + 30 * ((k < 2) ? 0 : (k == 2) ? ile - 1 : ile),
                    buttonLayoutParams.rightMargin, buttonLayoutParams.bottomMargin);
            btn.setLayoutParams(buttonLayoutParams);
            btn2.setLayoutParams(buttonLayoutParams);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);

            dialog.show();
        } else {
            RemoveRelationship remRel = new RemoveRelationship();
            Properties p = new Properties();
            p.put("boxes", MainActivity.toEditBoxes);
            remRel.execute(p);
            MainActivity.addCommendUndo(remRel);
        }

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

From source file:org.brandroid.openmanager.fragments.ContentFragment.java

public boolean createContextMenu(final OpenPath file, final AdapterView<?> list, final View view, final int pos,
        final int xOffset, final int yOffset) {
    Logger.LogInfo(getClassName() + ".onItemLongClick: " + file);

    final OpenContextMenuInfo info = new OpenContextMenuInfo(file);

    if (!OpenExplorer.USE_PRETTY_CONTEXT_MENUS) {
        if (Build.VERSION.SDK_INT > 10) {
            final PopupMenu pop = new PopupMenu(view.getContext(), view);
            pop.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    if (onOptionsItemSelected(item)) {
                        pop.dismiss();//  w  w w  . j av a  2 s.c o m
                        return true;
                    } else if (getExplorer() != null)
                        return getExplorer().onIconContextItemSelected(pop, item, item.getMenuInfo(), view);
                    return false;
                }
            });
            pop.getMenuInflater().inflate(R.menu.context_file, pop.getMenu());
            onPrepareOptionsMenu(pop.getMenu());
            if (DEBUG)
                Logger.LogDebug("PopupMenu.show()");
            pop.show();
            return true;
        } else
            return list.showContextMenu();
    } else if (OpenExplorer.BEFORE_HONEYCOMB || !OpenExplorer.USE_ACTIONMODE) {

        try {
            //View anchor = view; //view.findViewById(R.id.content_context_helper);
            //if(anchor == null) anchor = view;
            //view.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            //Rect r = new Rect(view.getLeft(),view.getTop(),view.getMeasuredWidth(),view.getMeasuredHeight());
            MenuBuilder cmm = IconContextMenu.newMenu(list.getContext(), R.menu.context_file);
            if (!file.canRead()) {
                MenuUtils.setMenuEnabled(cmm, false);
                MenuUtils.setMenuEnabled(cmm, true, R.id.menu_context_info);
            }
            MenuUtils.setMenuEnabled(cmm, file.canWrite(), R.id.menu_context_paste, R.id.menu_context_cut,
                    R.id.menu_context_delete, R.id.menu_context_rename);
            onPrepareOptionsMenu(cmm);

            //if(!file.isArchive()) hideItem(cmm, R.id.menu_context_unzip);
            if (getClipboard().size() > 0)
                MenuUtils.setMenuVisible(cmm, false, R.id.menu_multi);
            else
                MenuUtils.setMenuVisible(cmm, false, R.id.menu_context_paste);
            MenuUtils.setMenuEnabled(cmm, !file.isDirectory(), R.id.menu_context_edit, R.id.menu_context_view);
            final IconContextMenu cm = new IconContextMenu(list.getContext(), cmm, view);
            //cm.setAnchor(anchor);
            cm.setNumColumns(2);
            cm.setOnIconContextItemSelectedListener(getExplorer());
            cm.setInfo(info);
            cm.setTextLayout(R.layout.context_item);
            cm.setTitle(file.getName());
            if (!cm.show()) //r.left, r.top);
                return list.showContextMenu();
            else
                return true;
        } catch (Exception e) {
            Logger.LogWarning("Couldn't show Iconified menu.", e);
            return list.showContextMenu();
        }
    }

    if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) {
        if (!file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) {
            try {
                Method mStarter = getActivity().getClass().getMethod("startActionMode");
                mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() {
                    //@Override
                    public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
                        return false;
                    }

                    //@Override
                    public void onDestroyActionMode(android.view.ActionMode mode) {
                        mActionMode = null;
                        mActionModeSelected = false;
                    }

                    //@Override
                    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                        mode.getMenuInflater().inflate(R.menu.context_file, menu);

                        mActionModeSelected = true;
                        return true;
                    }

                    //@Override
                    public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
                        //ArrayList<OpenPath> files = new ArrayList<OpenPath>();

                        //OpenPath file = mLastPath.getChild(mode.getTitle().toString());
                        //files.add(file);

                        if (item.getItemId() != R.id.menu_context_cut && item.getItemId() != R.id.menu_multi
                                && item.getItemId() != R.id.menu_context_copy) {
                            mode.finish();
                            mActionModeSelected = false;
                        }
                        return executeMenu(item.getItemId(), mode, file);
                    }
                });
                Class cAM = Class.forName("android.view.ActionMode");
                Method mST = cAM.getMethod("setTitle", CharSequence.class);
                mST.invoke(mActionMode, file.getName());
            } catch (Exception e) {
                Logger.LogError("Error using ActionMode", e);
            }
        }
        return true;

    }

    if (file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) {
        if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) {
            try {
                Method mStarter = getActivity().getClass().getMethod("startActionMode");
                mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() {

                    //@Override
                    public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
                        return false;
                    }

                    //@Override
                    public void onDestroyActionMode(android.view.ActionMode mode) {
                        mActionMode = null;
                        mActionModeSelected = false;
                    }

                    //@Override
                    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                        mode.getMenuInflater().inflate(R.menu.context_file, menu);
                        menu.findItem(R.id.menu_context_paste).setEnabled(getClipboard().size() > 0);
                        //menu.findItem(R.id.menu_context_unzip).setEnabled(mHoldingZip);

                        mActionModeSelected = true;

                        return true;
                    }

                    //@Override
                    public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
                        return executeMenu(item.getItemId(), mode, file);
                    }
                });
                Class cAM = Class.forName("android.view.ActionMode");
                Method mST = cAM.getMethod("setTitle", CharSequence.class);
                mST.invoke(mActionMode, file.getName());
            } catch (Exception e) {
                Logger.LogError("Error using ActionMode", e);
            }
        }

        return true;
    }

    return false;
}

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

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

    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
    int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
    ChildItem childItem;/*from  w ww .j a  v  a 2s.c  o  m*/
    GroupItem groupItem;

    switch (item.getItemId()) {
    case R.id.app_copy_ip:
        childItem = (ChildItem) adapter.getChild(groupPos, childPos);
        copyIpAddress(childItem);
        return true;
    case R.id.app_whois_ip:
        childItem = (ChildItem) adapter.getChild(groupPos, childPos);
        whoisIpAddress(childItem);
        return true;
    case R.id.app_graph:
        groupItem = (GroupItem) adapter.getGroup(groupPos);
        showGraph(groupItem.app.uid);
        return true;
    case R.id.app_toggle_app_notifications:
        groupItem = (GroupItem) adapter.getGroup(groupPos);
        if (NetworkLogService.toastBlockedApps.remove(groupItem.app.packageName) == null) {
            NetworkLogService.toastBlockedApps.put(groupItem.app.packageName, groupItem.app.packageName);
        }
        new SelectToastApps().saveBlockedApps(NetworkLog.context, NetworkLogService.toastBlockedApps);
        return true;
    case R.id.app_toggle_app_logging:
        groupItem = (GroupItem) adapter.getGroup(groupPos);
        if (NetworkLogService.blockedApps.remove(groupItem.app.packageName) == null) {
            NetworkLogService.blockedApps.put(groupItem.app.packageName, groupItem.app.packageName);
        }
        new SelectBlockedApps().saveBlockedApps(NetworkLog.context, NetworkLogService.blockedApps);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.fsck.k9.activity.Accounts.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    // submenus don't actually set the menuInfo, so the "advanced"
    // submenu wouldn't work.
    if (menuInfo != null) {
        mSelectedContextAccount = (BaseAccount) getListView().getItemAtPosition(menuInfo.position);
    }//from w  ww  .j  a v a2 s  .  c o  m
    Account realAccount = null;
    if (mSelectedContextAccount instanceof Account) {
        realAccount = (Account) mSelectedContextAccount;
    }
    switch (item.getItemId()) {
    case R.id.delete_account:
        onDeleteAccount(realAccount);
        break;
    case R.id.account_settings:
        onEditAccount(realAccount);
        break;
    case R.id.activate:
        onActivateAccount(realAccount);
        break;
    case R.id.clear_pending:
        onClearCommands(realAccount);
        break;
    case R.id.empty_trash:
        onEmptyTrash(realAccount);
        break;
    case R.id.clear:
        onClear(realAccount);
        break;
    case R.id.recreate:
        onRecreate(realAccount);
        break;
    case R.id.export:
        onExport(false, realAccount);
        break;
    case R.id.move_up:
        onMove(realAccount, true);
        break;
    case R.id.move_down:
        onMove(realAccount, false);
        break;
    }
    return true;
}

From source file:com.piusvelte.sonet.core.SonetNotifications.java

@Override
public boolean onContextItemSelected(final MenuItem item) {
    if (item.getItemId() == CLEAR) {
        final ProgressDialog loadingDialog = new ProgressDialog(this);
        final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {

            @Override/*from   w w w . ja  va2 s  . co  m*/
            protected Void doInBackground(Void... arg0) {
                // clear all notifications
                ContentValues values = new ContentValues();
                values.put(Notifications.CLEARED, 1);
                SonetNotifications.this.getContentResolver().update(
                        Notifications.getContentUri(SonetNotifications.this), values, Notifications._ID + "=?",
                        new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) });
                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                if (loadingDialog.isShowing()) {
                    loadingDialog.dismiss();
                }
                SonetNotifications.this.finish();
            }
        };
        loadingDialog.setMessage(getString(R.string.loading));
        loadingDialog.setCancelable(true);
        loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (!asyncTask.isCancelled())
                    asyncTask.cancel(true);
            }
        });
        loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        loadingDialog.show();
        asyncTask.execute();
    }
    return super.onContextItemSelected(item);
    // clear
}

From source file:cgeo.geocaching.CacheListActivity.java

@Override
public boolean onContextItemSelected(final MenuItem item) {
    ContextMenu.ContextMenuInfo info = item.getMenuInfo();

    // restore menu info for sub menu items, see
    // https://code.google.com/p/android/issues/detail?id=7139
    if (info == null) {
        info = lastMenuInfo;//from  w w  w  .  j a  v  a2  s  .co  m
        lastMenuInfo = null;
    }

    AdapterContextMenuInfo adapterInfo = null;
    try {
        adapterInfo = (AdapterContextMenuInfo) info;
    } catch (final Exception e) {
        Log.w("CacheListActivity.onContextItemSelected", e);
    }

    final Geocache cache = adapterInfo != null ? getCacheFromAdapter(adapterInfo) : null;

    // just in case the list got resorted while we are executing this code
    if (cache == null || adapterInfo == null) {
        return true;
    }

    switch (item.getItemId()) {
    case R.id.menu_default_navigation:
        NavigationAppFactory.startDefaultNavigationApplication(1, this, cache);
        break;
    case R.id.menu_navigate:
        NavigationAppFactory.showNavigationMenu(this, cache, null, null);
        break;
    case R.id.menu_cache_details:
        CacheDetailActivity.startActivity(this, cache.getGeocode(), cache.getName());
        break;
    case R.id.menu_drop_cache:
        deleteCaches(Collections.singletonList(cache));
        break;
    case R.id.menu_move_to_list:
        moveCachesToOtherList(Collections.singletonList(cache));
        break;
    case R.id.menu_copy_to_list:
        copyCachesToOtherList(Collections.singletonList(cache));
        break;
    case R.id.menu_store_cache:
    case R.id.menu_refresh:
        refreshStored(Collections.singletonList(cache));
        break;
    default:
        // we must remember the menu info for the sub menu, there is a bug
        // in Android:
        // https://code.google.com/p/android/issues/detail?id=7139
        lastMenuInfo = info;
        final View selectedView = adapterInfo.targetView;
        LoggingUI.onMenuItemSelected(item, this, cache, new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(final DialogInterface dialog) {
                if (selectedView != null) {
                    final CacheListAdapter.ViewHolder holder = (CacheListAdapter.ViewHolder) selectedView
                            .getTag();
                    if (holder != null) {
                        CacheListAdapter.updateViewHolder(holder, cache, res);
                    }
                }
            }
        });
    }

    return true;
}