Example usage for android.view MenuItem getMenuInfo

List of usage examples for android.view MenuItem getMenuInfo

Introduction

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

Prototype

public ContextMenuInfo getMenuInfo();

Source Link

Document

Gets the extra information linked to this menu item.

Usage

From source file:com.groksolutions.grok.mobile.instance.InstanceListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (isMenuVisible() && item.getItemId() == R.id.menu_add_annotation) {
        // Get instance from context menu position
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);

        // Get timestamp from the selected bar on the anomaly chart
        AnomalyChartView view = (AnomalyChartView) info.targetView.findViewById(R.id.anomaly_chart_view);
        long selectedTimestamp = view.getSelectedTimestamp();
        if (selectedTimestamp == -1) {
            // Should not happen
            Log.w(TAG, "Failed to get annotation timestamp from chart view. Using current time instead");
            return true;
        }/*from   w w w .  java 2s . c  o m*/

        // Open "Add  Annotation" activity
        Intent addAnnotation = new Intent(getActivity(), AddAnnotationActivity.class);
        addAnnotation.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        addAnnotation.putExtra(AddAnnotationActivity.EXTRA_INSTANCE_ID, instance.getId());
        addAnnotation.putExtra(AddAnnotationActivity.EXTRA_TIMESTAMP, selectedTimestamp);
        getActivity().startActivity(addAnnotation);
    }

    return super.onContextItemSelected(item);
}

From source file:com.normalexception.app.rx8club.fragment.category.CategoryFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    ThreadModel tv = (ThreadModel) lv.getAdapter().getItem(info.position);

    switch (item.getItemId()) {
    case MENU_FAVE:
        FavoriteFactory.getInstance().addFavorite(tv);
        return true;
    case MENU_FILTER_USER:
        ThreadFilterFactory.getInstance()
                .addFilter(new ThreadFilter(ThreadFilter.RuleType.OWNER, tv.getStartUser()));
        return true;
    case MENU_FILTER_TITLE:
        ThreadFilterFactory.getInstance()
                .addFilter(new ThreadFilter(ThreadFilter.RuleType.TITLE, tv.getTitle()));
        return true;
    case MENU_FILTER_LASTUSER:
        ThreadFilterFactory.getInstance()
                .addFilter(new ThreadFilter(ThreadFilter.RuleType.LASTUSER, tv.getLastUser()));
    default://w w  w  .  j  av a2s. c  o m
        return super.onContextItemSelected(item);
    }
}

From source file:com.flowzr.activity.BlotterFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (!super.onContextItemSelected(item)) {
        AdapterView.AdapterContextMenuInfo mi = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        switch (item.getItemId()) {
        case MENU_DUPLICATE:
            duplicateTransaction(mi.id, 1);
            return true;
        case MENU_SAVE_AS_TEMPLATE:
            new BlotterOperations(this, db, mi.id).duplicateAsTemplate();
            Toast.makeText(this.getActivity(), R.string.save_as_template_success, Toast.LENGTH_SHORT).show();
            return true;
        }//from w  w w . j  a v  a  2  s  .  c om
    }
    return false;
}

From source file:org.videolan.vlc.gui.audio.AudioBrowserFragment.java

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

    ContextMenuInfo menuInfo = item.getMenuInfo();
    if (menuInfo == null)
        return super.onContextItemSelected(item);

    int startPosition;
    int groupPosition;
    int childPosition;
    List<String> medias;
    int id = item.getItemId();

    boolean useAllItems = (id == R.id.audio_list_browser_play_all || id == R.id.audio_list_browser_append_all);
    boolean append = (id == R.id.audio_list_browser_append || id == R.id.audio_list_browser_append_all);

    if (ExpandableListContextMenuInfo.class.isInstance(menuInfo)) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
        if (childPosition < 0)
            childPosition = 0;//from   w  w  w .j a  v  a2  s. co m
    } else {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        groupPosition = info.position;
        childPosition = 0;
    }

    if (id == R.id.audio_list_browser_delete) {
        AlertDialog alertDialog = CommonDialogs.deleteMedia(getActivity(),
                mSongsAdapter.getLocation(groupPosition).get(0),
                new VlcRunnable(mSongsAdapter.getItem(groupPosition)) {
                    @Override
                    public void run(Object o) {
                        Media aMedia = (Media) o;
                        mMediaLibrary.getMediaItems().remove(aMedia);
                        updateLists();
                    }
                });
        alertDialog.show();
        return true;
    }

    if (id == R.id.audio_list_browser_set_song) {
        AudioUtil.setRingtone(mSongsAdapter.getItem(groupPosition), getActivity());
        return true;
    }

    if (useAllItems) {
        startPosition = groupPosition;
        medias = mSongsAdapter.getLocations();
    } else {
        startPosition = 0;
        switch (mFlingViewGroup.getPosition()) {
        case MODE_SONG:
            medias = mSongsAdapter.getLocation(groupPosition);
            break;
        case MODE_ARTIST:
            medias = mArtistsAdapter.getPlaylist(groupPosition, childPosition);
            break;
        case MODE_ALBUM:
            medias = mAlbumsAdapter.getPlaylist(groupPosition, childPosition);
            break;
        case MODE_GENRE:
            medias = mGenresAdapter.getPlaylist(groupPosition, childPosition);
            break;
        default:
            return true;
        }
    }

    if (append)
        mAudioController.append(medias);
    else
        mAudioController.load(medias, startPosition);

    AudioPlayerActivity.start(getActivity());
    return super.onContextItemSelected(item);
}

From source file:com.akop.bach.fragment.xboxlive.AchievementsFragment.java

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

    if (mGameTitle != null && info.targetView.getTag() instanceof ViewHolder) {
        ViewHolder vh = (ViewHolder) info.targetView.getTag();

        switch (menuItem.getItemId()) {
        case R.id.google_achievement:
            Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
            searchIntent.putExtra(SearchManager.QUERY,
                    getString(R.string.google_achievement_f, mGameTitle, vh.title.getText()));
            startActivity(searchIntent);
            return true;
        }//from w  ww.j ava2  s  .c  om
    }

    return super.onContextItemSelected(menuItem);
}

From source file:com.numenta.taurus.instance.InstanceListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get instance from context menu position
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);
    Tracker t = TaurusApplication.getInstance().getGoogleAnalyticsTracker();

    switch (item.getItemId()) {
    case R.id.menu_add_favorite:
        TaurusApplication.addInstanceToFavorites(instance.getId());
        t.send(new HitBuilders.EventBuilder().setCategory("Favorites").setAction("Add")
                .setLabel(instance.getTicker()).build());
        return true;
    case R.id.menu_remove_favorite:
        TaurusApplication.removeInstanceFromFavorites(instance.getId());
        t.send(new HitBuilders.EventBuilder().setCategory("Favorites").setAction("Remove")
                .setLabel(instance.getTicker()).build());
        return true;
    }/*from  w ww. j a  v a  2 s .c  o m*/
    return super.onContextItemSelected(item);

}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.detailsMessage) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        showMessageDetails(info.id);// w  ww  .  jav a 2 s  .c  o  m
        return true;
    } else if (item.getItemId() == R.id.copyMessage) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        copyMessageBody(info.id);
        return true;
    } else if (item.getItemId() == R.id.clearMessageHistory) {
        clearMessageHistory();
        return true;
    } else {
        return super.onContextItemSelected(item);
    }
}

From source file:org.videolan.vlc2.gui.audio.AudioPlayer.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    if (info == null) // info can be null
        return super.onContextItemSelected(item);
    int id = item.getItemId();

    if (id == R.id.audio_player_mini_remove) {
        Log.d(TAG, "Context menu removing " + info.position);
        mAudioController.remove(info.position);
        return true;
    }/*from ww w . java2 s .c om*/
    return super.onContextItemSelected(item);
}

From source file:org.dvbviewer.controller.ui.fragments.ChannelEpg.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getMenuInfo() != null) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        selectedPosition = info.position;
    }/*w ww  .  j av a2 s . c  om*/
    Cursor c;
    c = mAdapter.getCursor();
    c.moveToPosition(selectedPosition);
    Timer timer;
    if (getUserVisibleHint()) {
        switch (item.getItemId()) {
        case R.id.menuRecord:
            timer = cursorToTimer(c);
            String url = timer.getId() <= 0l ? ServerConsts.URL_TIMER_CREATE : ServerConsts.URL_TIMER_EDIT;
            String title = timer.getTitle();
            String days = String.valueOf(DateUtils.getDaysSinceDelphiNull(timer.getStart()));
            String start = String.valueOf(DateUtils.getMinutesOfDay(timer.getStart()));
            String stop = String.valueOf(DateUtils.getMinutesOfDay(timer.getEnd()));
            String endAction = String.valueOf(timer.getTimerAction());
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("ch", String.valueOf(timer.getChannelId())));
            params.add(new BasicNameValuePair("dor", days));
            params.add(new BasicNameValuePair("encoding", "255"));
            params.add(new BasicNameValuePair("enable", "1"));
            params.add(new BasicNameValuePair("start", start));
            params.add(new BasicNameValuePair("stop", stop));
            params.add(new BasicNameValuePair("title", title));
            params.add(new BasicNameValuePair("endact", endAction));
            if (timer.getId() > 0) {
                params.add(new BasicNameValuePair("id", String.valueOf(timer.getId())));
            }

            String query = URLEncodedUtils.format(params, "utf-8");
            String request = url + query;
            RecordingServiceGet rsGet = new RecordingServiceGet(request);
            Thread executionThread = new Thread(rsGet);
            executionThread.start();
            return true;
        case R.id.menuTimer:
            timer = cursorToTimer(c);
            if (!UIUtils.isTablet(getActivity())) {
                Intent timerIntent = new Intent(getActivity(), TimerDetailsActivity.class);
                timerIntent.putExtra(TimerDetails.EXTRA_TITLE, timer.getTitle());
                timerIntent.putExtra(TimerDetails.EXTRA_CHANNEL_NAME, timer.getChannelName());
                timerIntent.putExtra(TimerDetails.EXTRA_CHANNEL_ID, timer.getChannelId());
                timerIntent.putExtra(TimerDetails.EXTRA_START, timer.getStart().getTime());
                timerIntent.putExtra(TimerDetails.EXTRA_END, timer.getEnd().getTime());
                startActivity(timerIntent);
            }
            return true;
        case R.id.menuDetails:
            Intent details = new Intent(getActivity(), IEpgDetailsActivity.class);
            c = mAdapter.getCursor();
            c.moveToPosition(selectedPosition);
            IEPG entry = cursorToEpgEntry(c);
            details.putExtra(IEPG.class.getSimpleName(), entry);
            startActivity(details);
            return true;
        default:
            break;
        }
    }
    return false;
}

From source file:com.afg.MngProductContentProvider.Fragments.ListPharmacy_Fragment.java

@Override
public boolean onContextItemSelected(final MenuItem item) {

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext());

    alertDialog.setTitle("Aviso");
    alertDialog.setMessage("Esta seguro que desea borrar esta farmacia?");

    alertDialog.setPositiveButton("Borrar", new DialogInterface.OnClickListener() {
        @Override// w  ww  . ja  v  a  2  s  .c  om
        public void onClick(DialogInterface dialogInterface, int i) {

            presenter.deletePharmacy((Pharmacy) adapter
                    .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position));

        }
    }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {

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