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.shanet.relayremote.RelayGroupsFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get the selected relay
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    RelayGroup selectedGroup = ((Main) getActivity()).getRelayGroups().get(menuInfo.position);

    switch (item.getItemId()) {
    case R.id.deleteGroup:
        DialogUtils.showDeleteDialog(getActivity(), selectedGroup);
        return true;

    case R.id.editGroup:
        // Pass the group id (gid) of the selected group to the edit activity
        Intent intent = new Intent(getActivity(), EditRelayGroup.class);
        intent.putExtra("gid", selectedGroup.getGid());

        // Start the add/edit activity
        getActivity().startActivityForResult(intent, Constants.ADD_EDIT_CODE);
        return true;

    case R.id.createNFCGroup:
        if (Utils.hasNfcSupport(getActivity())) {
            DialogUtils.displayNfcTypeDialog(getActivity(), Constants.NFC_GROUP, selectedGroup.getGid());
        }//from  www.j  a  v a  2  s. com

        return true;

    default:
        return false;
    }
}

From source file:com.racoon.ampdroid.views.PlaylistsView.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Playlist selected = controller.getPlaylists().get((int) info.id);
    String urlString = controller.getServer().getHost() + "/server/xml.server.php?action=playlist_songs&auth="
            + controller.getServer().getAuthKey() + "&filter=" + String.valueOf(selected.getId());
    Log.d("url", urlString);
    switch (item.getItemId()) {
    case R.id.contextMenuAdd:
        controller.parsePlaylistSongs(urlString, controller.getPlayNow());
        Context context = getView().getContext();
        CharSequence text = getResources().getString(R.string.playlistsViewPlaylistAdded);
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();/*  ww w  .  j av  a  2  s  .  c  om*/
        return true;
    case R.id.contextMenuOpen:
        controller.getSelectedSongs().clear();
        controller.parsePlaylistSongs(urlString, controller.getSelectedSongs());
        // Create new fragment and transaction
        SelectedSongsView newFragment = new SelectedSongsView();
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.adaway.ui.TcpdumpLogFragment.java

/**
 * Context Menu Items// w ww  . j av a 2 s .c om
 */
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    String hostname = mAdapter.getItem(info.position);

    switch (item.getItemId()) {
    case R.id.tcpdump_log_context_blacklist:
        ProviderHelper.insertBlacklistItem(mActivity, hostname);
        Toast toastBlacklist = Toast.makeText(mActivity, R.string.toast_tcpdump_added_to_blacklist,
                Toast.LENGTH_SHORT);
        toastBlacklist.show();
        return true;
    case R.id.tcpdump_log_context_whitelist:
        ProviderHelper.insertWhitelistItem(mActivity, hostname);
        Toast toastWhitelist = Toast.makeText(mActivity, R.string.toast_tcpdump_added_to_whitelist,
                Toast.LENGTH_SHORT);
        toastWhitelist.show();
        return true;
    case R.id.tcpdump_log_context_browser:
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("http://" + hostname));
        startActivity(i);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.shanet.relayremote.RelaysFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get the selected relay
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    Relay selectedRelay = ((Main) getActivity()).getRelays().get(menuInfo.position);

    switch (item.getItemId()) {
    case R.id.deleteRelay:
        DialogUtils.showDeleteDialog(getActivity(), selectedRelay);
        return true;

    case R.id.editRelay:
        // Pass the relay id (rid) of the selected relay to the edit activity
        Intent intent = new Intent(getActivity(), EditRelay.class);
        intent.putExtra("rid", selectedRelay.getRid());

        // Start the add/edit activity
        getActivity().startActivityForResult(intent, Constants.ADD_EDIT_CODE);
        return true;

    case R.id.createNFC:
        if (Utils.hasNfcSupport(getActivity())) {
            DialogUtils.displayNfcTypeDialog(getActivity(), Constants.NFC_RELAY, selectedRelay.getRid());
        }/*from ww w  .  j ava  2 s.com*/

        return true;

    default:
        return false;
    }
}

From source file:org.microg.gms.ui.GcmRegisteredAppsFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    final GcmData.AppInfo appInfo = appsAdapter.getItem(info.position);

    new AsyncTask<Void, Void, Void>() {

        @Override//from  w  ww.jav  a2 s .  c o m
        protected Void doInBackground(Void... params) {
            PushRegisterService.unregister(getContext(), appInfo.app, appInfo.appSignature, null, null);
            return null;
        }

        protected void onPostExecute(Void result) {
            updateListView();
        }
    }.execute();
    return true;
}

From source file:com.racoon.ampdroid.views.ArtistsView.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Artist a = controller.getArtists().get((int) info.id);
    switch (item.getItemId()) {
    case R.id.contextMenuAdd:
        for (Song s : controller.findSongs(a)) {
            controller.getPlayNow().add(s);
        }//w  ww. ja  v  a 2  s.com
        Context context = getView().getContext();
        CharSequence text = getResources().getString(R.string.artistsViewArtistSongsAdded);
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
        return true;
    case R.id.contextMenuOpen:
        controller.getSelectedSongs().clear();
        for (Song s : controller.findSongs(a)) {
            controller.getSelectedSongs().add(s);
        }
        // Create new fragment and transaction
        SelectedSongsView newFragment = new SelectedSongsView();
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.sensapp.android.sensappdroid.fragments.ServerDataFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    //String title = getGraphTitleByID(info.id);
    switch (item.getItemId()) {
    case MENU_DELETE_ID:
        //Delete the graph
        //new DeleteGraphSensorsTask(getActivity(), SensAppContract.Graph.CONTENT_URI).execute(SensAppContract.Graph.ID + " = " + info.id);
        //Delete Graph Sensors attached
        //new DeleteGraphSensorsTask(getActivity(), SensAppContract.GraphSensor.CONTENT_URI).execute(SensAppContract.GraphSensor.GRAPH + " = " + info.id);
        return true;
    case MENU_MANAGE_ID:
        //ManageGraphSensorFragment.newInstance(title, info.id).show(getFragmentManager(), "ManageGraphDialog");
        return true;
    }/*from  w  w w.  jav a 2s.  c  o  m*/
    return super.onContextItemSelected(item);
}

From source file:org.gateshipone.odyssey.fragments.BookmarksFragment.java

/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 *//*from   w w  w . ja  va  2  s  .  c o  m*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
    case R.id.bookmarks_context_menu_action_resume:
        resumeBookmark(info.position);
        return true;
    case R.id.bookmarks_context_menu_action_delete:
        deleteBookmark(info.position);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.sensapp.android.sensappdroid.fragments.GraphsListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    String title = getGraphTitleByID(info.id);
    switch (item.getItemId()) {
    case MENU_DELETE_ID:
        //Delete the graph
        new DeleteGraphSensorsTask(getActivity(), SensAppContract.Graph.CONTENT_URI)
                .execute(SensAppContract.Graph.ID + " = " + info.id);
        //Delete Graph Sensors attached
        new DeleteGraphSensorsTask(getActivity(), SensAppContract.GraphSensor.CONTENT_URI)
                .execute(SensAppContract.GraphSensor.GRAPH + " = " + info.id);
        return true;
    case MENU_MANAGE_ID:
        ManageGraphSensorFragment.newInstance(title, info.id).show(getFragmentManager(), "ManageGraphDialog");
        return true;
    }//from   www.jav  a2 s. c  om
    return super.onContextItemSelected(item);
}

From source file:com.ecoplayer.beta.AlbumSongsFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.cm_item_addSongQueue:
        // Add the song to the end of the queue
        Song song = songsArrayAdap.getItem(info.position);
        if (!playQueue.addSongQueue(song)) {
            // The songs cannot be added to the play list, List too full
            // or song null;
            Toast.makeText(AlbumSongsFragment.this.getActivity(), getResources().getString(R.string.queue_full),
                    Toast.LENGTH_LONG).show();
        }/*from  w  w  w  .  j a va2s.c o  m*/
        // Add buttons fragment to main activity if the play queue is not
        // empty
        mainActivity.addButtonsFragmentIfNotEmpty();
        return true;
    case R.id.cm_item_addAlbumQueue:
        // Add all songs of the album to the end of the queue
        if (!playQueue.addAllSongsQueue(songsArrayAdap.getCollection())) {
            // The songs cannot be added to the play list, List too full
            // or collection adapter empty.
            Toast.makeText(AlbumSongsFragment.this.getActivity(), getResources().getString(R.string.queue_full),
                    Toast.LENGTH_LONG).show();
        }
        // Add buttons fragment to main activity if the play queue is not
        // empty
        mainActivity.addButtonsFragmentIfNotEmpty();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}