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:layout.FragmentBoardItemList.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    if (info.targetView.getParent() == listViewBoardItems) {
        BoardItem bi = boardItems.get(info.position);
        switch (item.getItemId()) {
        case R.id.menu_copy:
            System.out.println("Post copiado");
            ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData cd = ClipData.newPlainText("Reply", boardItems.get(info.position).getMessage());
            cm.setPrimaryClip(cd);//from  ww  w .  ja v  a 2s .  co m
            break;
        case R.id.menu_reply:
            Intent in = new Intent(getActivity().getApplicationContext(), ResponseActivity.class);
            Bundle b = new Bundle();
            b.putParcelable("theReply", boardItems.get(info.position));
            b.putBoolean("quoting", true);
            in.putExtras(b);
            getActivity().startActivity(in);
            break;
        case R.id.menu_savereply:
            try {
                File txt = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/"
                        + bi.getParentBoard().getBoardDir() + "_" + bi.getId() + ".txt");
                FileOutputStream stream = new FileOutputStream(txt);
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(stream);
                outputStreamWriter.write(bi.getMessage());
                outputStreamWriter.close();
                stream.close();
                Toast.makeText(getContext(),
                        bi.getParentBoard().getBoardDir() + "_" + bi.getId() + ".txt guardado.",
                        Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case R.id.menu_delpost:
            deletePost(false, bi);
            break;
        case R.id.menu_delimage:
            deletePost(true, bi);
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:moe.johnny.tombstone.ui.PreventFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (mActivity == null || item == null) {
        return false;
    }/*from   ww  w  .  ja va2  s  .  c o  m*/
    ViewHolder holder = (ViewHolder) ((AdapterContextMenuInfo) item.getMenuInfo()).targetView.getTag();
    return onContextItemSelected(holder, holder.packageName, item.getItemId());
}

From source file:org.mariotaku.twidere.fragment.AbsActivitiesFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (!getUserVisibleHint())
        return false;
    final ParcelableActivitiesAdapter adapter = getAdapter();
    final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo = (ExtendedRecyclerView.ContextMenuInfo) item
            .getMenuInfo();//from   w w  w  .  ja  v a2  s. c  om
    final int position = contextMenuInfo.getPosition();

    switch (adapter.getItemViewType(position)) {
    case ParcelableActivitiesAdapter.ITEM_VIEW_TYPE_STATUS: {
        final ParcelableStatus status = getActivityStatus(position);
        if (status == null)
            return false;
        if (item.getItemId() == R.id.share) {
            final Intent shareIntent = Utils.createStatusShareIntent(getActivity(), status);
            final Intent chooser = Intent.createChooser(shareIntent, getString(R.string.share_status));
            Utils.addCopyLinkIntent(getContext(), chooser, LinkCreator.getStatusWebLink(status));
            startActivity(chooser);
            return true;
        }
        return MenuUtils.handleStatusClick(getActivity(), this, getFragmentManager(), mUserColorNameManager,
                mTwitterWrapper, status, item);
    }
    }
    return false;
}

From source file:com.piusvelte.taplock.client.core.TapLockSettings.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case REMOVE_ID:
        // remove device
        int deviceIdx = (int) ((AdapterContextMenuInfo) item.getMenuInfo()).id;
        mDevices.remove(deviceIdx);//  w  ww  .j  a v  a2  s  .  c  om
        storeDevices();
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:com.googlecode.android_scripting.activity.ScriptManager.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {/*from  w  w  w.j  a v a  2s.c o  m*/
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e("Bad menuInfo", e);
        return false;
    }
    File file = (File) mAdapter.getItem(info.position);
    int itemId = item.getItemId();
    if (itemId == MenuId.DELETE.getId()) {
        delete(file);
        return true;
    } else if (itemId == MenuId.RENAME.getId()) {
        rename(file);
        return true;
    } else if (itemId == MenuId.DECOMPILE.getId()) {
        if (!file.getAbsolutePath().endsWith(".pyc") && !file.isDirectory()) {
            // ??pyc????
            Crouton.cancelAllCroutons();
            Crouton.showText(this, getString(R.string.s_Cannotdecompile), Style.ALERT);
            return true;
        }
        Decompile.show(this, file.getAbsolutePath());
        return true;
    } else if (itemId == MenuId.BUILD.getId()) {
        // 
    }
    return false;
}

From source file:com.xorcode.andtweet.TweetListActivity.java

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

    mCurrentId = info.id;

    Uri uri;
    Cursor c;

    switch (item.getItemId()) {
    case CONTEXT_MENU_ITEM_REPLY:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID }, null, null, null);
        try {
            c.moveToFirst();
            String reply = "@" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " ";
            long replyId = c.getLong(c.getColumnIndex(Tweets._ID));
            mTweetEditor.startEditing(reply, replyId);
        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_RETWEET:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null,
                null, null);
        try {
            c.moveToFirst();

            StringBuilder message = new StringBuilder();
            String reply = "RT @" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " ";
            message.append(reply);
            CharSequence text = c.getString(c.getColumnIndex(Tweets.MESSAGE));
            int len = 140 - reply.length() - 3;
            if (text.length() < len) {
                len = text.length();
            }
            message.append(text, 0, len);
            if (message.length() == 137) {
                message.append("...");
            }
            mTweetEditor.startEditing(message.toString(), 0);
        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_DESTROY_STATUS:
        sendCommand(new CommandData(CommandEnum.DESTROY_STATUS, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_FAVORITE:
        sendCommand(new CommandData(CommandEnum.CREATE_FAVORITE, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_DESTROY_FAVORITE:
        sendCommand(new CommandData(CommandEnum.DESTROY_FAVORITE, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_SHARE:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null,
                null, null);
        try {
            c.moveToFirst();

            StringBuilder subject = new StringBuilder();
            StringBuilder text = new StringBuilder();
            String message = c.getString(c.getColumnIndex(Tweets.MESSAGE));

            subject.append(getText(R.string.button_create_tweet));
            subject.append(" - " + message);
            int maxlength = 80;
            if (subject.length() > maxlength) {
                subject.setLength(maxlength);
                // Truncate at the last space
                subject.setLength(subject.lastIndexOf(" "));
                subject.append("...");
            }

            text.append(message);
            text.append("\n-- \n" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)));
            text.append("\n URL: " + "http://twitter.com/" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID))
                    + "/status/" + c.getString(c.getColumnIndex(Tweets._ID)));

            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("text/plain");
            share.putExtra(Intent.EXTRA_SUBJECT, subject.toString());
            share.putExtra(Intent.EXTRA_TEXT, text.toString());
            startActivity(Intent.createChooser(share, getText(R.string.menu_item_share)));

        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_UNFOLLOW:
    case CONTEXT_MENU_ITEM_BLOCK:
    case CONTEXT_MENU_ITEM_DIRECT_MESSAGE:
    case CONTEXT_MENU_ITEM_PROFILE:
        Toast.makeText(this, R.string.unimplemented, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}

From source file:org.gateshipone.malp.application.activities.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }//  www  .j a  va 2 s .co m

    CurrentPlaylistView currentPlaylistView = (CurrentPlaylistView) findViewById(R.id.now_playing_playlist);

    if (currentPlaylistView != null && mNowPlayingDragStatus == DRAG_STATUS.DRAGGED_UP) {

        MPDTrack track = (MPDTrack) currentPlaylistView.getItem(info.position);

        switch (item.getItemId()) {

        case R.id.action_song_play_next:
            MPDQueryHandler.playIndexAsNext(info.position);
            return true;
        case R.id.action_add_to_saved_playlist:
            // open dialog in order to save the current playlist as a playlist in the mediastore
            ChoosePlaylistDialog choosePlaylistDialog = new ChoosePlaylistDialog();
            Bundle args = new Bundle();
            args.putBoolean(ChoosePlaylistDialog.EXTRA_SHOW_NEW_ENTRY, true);
            choosePlaylistDialog.setCallback(new AddPathToPlaylist(track, this));
            choosePlaylistDialog.setArguments(args);
            choosePlaylistDialog.show(getSupportFragmentManager(), "ChoosePlaylistDialog");
            return true;
        case R.id.action_remove_song:
            MPDQueryHandler.removeSongFromCurrentPlaylist(info.position);
            return true;
        case R.id.action_remove_album:
            currentPlaylistView.removeAlbumFrom(info.position);
            return true;
        case R.id.action_show_artist:
            onArtistSelected(new MPDArtist(track.getTrackArtist()));
            return true;
        case R.id.action_show_album:
            MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
            if (!track.getTrackAlbumArtist().isEmpty()) {
                tmpAlbum.setArtistName(track.getTrackAlbumArtist());
            } else {
                tmpAlbum.setArtistName(track.getTrackArtist());
            }
            tmpAlbum.setMBID(track.getTrackAlbumMBID());
            onAlbumSelected(tmpAlbum);
            return true;
        case R.id.action_show_details:
            // Open song details dialog
            SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
            Bundle songArgs = new Bundle();
            songArgs.putParcelable(SongDetailsDialog.EXTRA_FILE, (MPDTrack) track);
            songDetailsDialog.setArguments(songArgs);
            songDetailsDialog.show(getSupportFragmentManager(), "SongDetails");
            return true;
        }
    }
    return false;
}

From source file:com.github.mjdev.libaums.usbfileman.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    final UsbFile entry = adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case R.id.delete_item:
        try {/*from  w w w . j a va 2s  . c  o  m*/
            entry.delete();
            adapter.refresh();
        } catch (IOException e) {
            Log.e(TAG, "error deleting!", e);
        }
        return true;
    case R.id.rename_item:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Rename");
        builder.setMessage("Please enter a name for renaming");
        final EditText input = new EditText(this);
        input.setText(entry.getName());
        builder.setView(input);

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                try {
                    entry.setName(input.getText().toString());
                    adapter.refresh();
                } catch (IOException e) {
                    Log.e(TAG, "error renaming!", e);
                }
            }

        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.dismiss();
            }
        });
        builder.setCancelable(false);
        builder.create().show();
        return true;
    case R.id.move_item:
        MoveClipboard cl = MoveClipboard.getInstance();
        cl.setFile(entry);
        return true;
    case R.id.start_http_server:
        startHttpServer(entry);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:gov.cdc.epiinfo.RecordList.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case DELETE_ID:
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        mDbHelper.deleteRecord(info.id);
        fillData();//from  ww w.  j a va  2  s . co  m
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:com.sastra.app.timetable.TimetableActivity.java

public boolean onContextItemSelected(android.view.MenuItem item) {
    data.open();//from w  w  w  .  j av  a  2s .c  om
    int day = currentDay = mPager.getCurrentItem();
    System.out.println(day);
    results = data.selectAllFromDay(day);
    data.close();
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    String course = results.get(info.position).get("SName").toString();
    String type = results.get(info.position).get("HType").toString();
    String classroom = results.get(info.position).get("HClass").toString();
    String startH = results.get(info.position).get("HStart").toString();
    String endH = results.get(info.position).get("HEnd").toString();

    switch (item.getItemId()) {
    case 1:

        action = "edit";
        data.open();
        ArrayList<HashMap<String, Object>> arrayS = data.selectSubjects();
        data.close();
        arraySubjects = new String[arrayS.size()];
        colo = new String[arrayS.size()];
        Iterator<HashMap<String, Object>> it = arrayS.iterator();
        int i = 0;
        while (it.hasNext()) {
            HashMap<String, Object> hm = it.next();
            arraySubjects[i] = hm.get("SName").toString();
            colo[i] = hm.get("SColor").toString();
            i++;
        }

        newSpinnerAdapter maa = new newSpinnerAdapter(this, R.id.text1, arraySubjects);
        SName.setAdapter(maa);
        //                   Sarrayadapter = new ArrayAdapter<String>(this,R.layout.timetable_spinner_layout,arraySubjects);
        //                   Sarrayadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //                   SName.setAdapter(Sarrayadapter);
        SName.setSelection(maa.getPosition(course));
        String dayS = IDay2SDay(day);
        HDay.setSelection(arrayadapter.getPosition(dayS));
        CharSequence fhour = startH.subSequence(0, 2);
        CharSequence fminutes = startH.subSequence(3, 5);
        CharSequence thour = endH.subSequence(0, 2);
        CharSequence tminutes = endH.subSequence(3, 5);
        int fhourInt;
        int fminutesInt;
        try {
            fhourInt = Integer.parseInt((String) fhour);
            fminutesInt = Integer.parseInt((String) fminutes);
        } catch (Exception e) {
            fhourInt = 12;
            fminutesInt = 0;
        }
        int thourInt;
        int tminutesInt;
        try {
            thourInt = Integer.parseInt((String) thour);
            tminutesInt = Integer.parseInt((String) tminutes);
        } catch (Exception e) {
            thourInt = 12;
            tminutesInt = 0;
        }
        fromDialog.updateTime(fhourInt, fminutesInt);
        toDialog.updateTime(thourInt, tminutesInt);
        start.setText(startH);
        end.setText(endH);
        HType.setText(type);
        HClass.setText(classroom);
        addDialog.setTitle("Edit Class");
        OLDSName = course;
        OLDHType = type;
        OLDHClass = classroom;
        OLDHDay = day;
        OLDHStart = startH;
        OLDHEnd = endH;
        addDialog.show();
        break;
    case 2:
        OLDSName = course;
        OLDHType = type;
        OLDHClass = classroom;
        OLDHDay = day;
        OLDHStart = startH;
        OLDHEnd = endH;
        alert2.show();
        break;
    }

    mAdapter.notifyDataSetChanged();
    mAdapter.finishUpdate(mPager);
    //update();
    return true;
}