Example usage for android.widget PopupMenu setOnMenuItemClickListener

List of usage examples for android.widget PopupMenu setOnMenuItemClickListener

Introduction

In this page you can find the example usage for android.widget PopupMenu setOnMenuItemClickListener.

Prototype

public void setOnMenuItemClickListener(OnMenuItemClickListener listener) 

Source Link

Document

Sets a listener that will be notified when the user selects an item from the menu.

Usage

From source file:org.xbmc.kore.ui.sections.audio.AlbumSongsListFragment.java

private void showPopupMenu(View v) {
    final ViewHolder viewHolder = (ViewHolder) v.getTag();

    final PlaylistType.Item playListItem = new PlaylistType.Item();

    final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.song_item, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//  w  w  w  .  j a  va  2 s.c  om
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_play_song:
                MediaPlayerUtils.play(AlbumSongsListFragment.this, playListItem);
                return true;
            case R.id.action_add_to_playlist:
                MediaPlayerUtils.queue(AlbumSongsListFragment.this, playListItem,
                        PlaylistType.GetPlaylistsReturnType.AUDIO);
                return true;
            case R.id.download:
                ArrayList<FileDownloadHelper.SongInfo> songInfoList = new ArrayList<>();
                songInfoList.add(viewHolder.songInfo);
                UIUtils.downloadSongs(getActivity(), songInfoList,
                        HostManager.getInstance(getActivity()).getHostInfo(), callbackHandler);
            }
            return false;
        }
    });
    popupMenu.show();
}

From source file:org.xbmc.kore.ui.sections.audio.SongsListFragment.java

private void showPopupMenu(View v) {
    final ViewHolder viewHolder = (ViewHolder) v.getTag();

    final PlaylistType.Item playListItem = new PlaylistType.Item();
    playListItem.songid = viewHolder.songInfo.songId;

    final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.song_item, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*  w  ww.  j a  v a  2  s . com*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_play_song:
                MediaPlayerUtils.play(SongsListFragment.this, playListItem);
                return true;
            case R.id.action_add_to_playlist:
                MediaPlayerUtils.queue(SongsListFragment.this, playListItem,
                        PlaylistType.GetPlaylistsReturnType.AUDIO);
                return true;
            case R.id.download:
                ArrayList<FileDownloadHelper.SongInfo> songInfoList = new ArrayList<>();
                songInfoList.add(viewHolder.songInfo);
                UIUtils.downloadSongs(getActivity(), songInfoList,
                        HostManager.getInstance(getActivity()).getHostInfo(), callbackHandler);
            }
            return false;
        }
    });
    popupMenu.show();
}

From source file:com.tlongdev.bktf.ui.fragment.FavoritesFragment.java

@Override
public void onMoreClicked(View view, final Item item) {
    PopupMenu menu = new PopupMenu(getActivity(), view);
    menu.getMenuInflater().inflate(R.menu.popup_item, menu.getMenu());
    menu.getMenu().findItem(R.id.favorite).setTitle("Remove from favorites");
    menu.getMenu().findItem(R.id.calculator).setEnabled(!Utility.isInCalculator(getActivity(), item));
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from ww  w.ja va2  s  .  c  o m
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.history:
                Intent i = new Intent(getActivity(), PriceHistoryActivity.class);
                i.putExtra(PriceHistoryActivity.EXTRA_ITEM, item);
                startActivity(i);
                break;
            case R.id.favorite:
                Utility.removeFromFavorites(getActivity(), item);
                mAdapter.removeItem(item);
                break;
            case R.id.calculator:
                Utility.addToCalculator(getActivity(), item);
                menuItem.setEnabled(false);
                break;
            case R.id.backpack_tf:
                CustomTabActivityHelper.openCustomTab(getActivity(), new CustomTabsIntent.Builder().build(),
                        Uri.parse(item.getBackpackTfUrl()), new WebViewFallback());
                break;
            case R.id.wiki:
                CustomTabActivityHelper.openCustomTab(getActivity(), new CustomTabsIntent.Builder().build(),
                        Uri.parse(item.getTf2WikiUrl()), new WebViewFallback());
                break;
            }
            return true;
        }
    });

    menu.show();
}

From source file:in.tanjo.sushi.MainActivity.java

private void updateMainAdapter() {
    MainAdapter mainAdapter = new MainAdapter(mNoteManager.getActiveNote().getSushis());
    mainAdapter.setOnRecyclerViewAdapterItemClickListener(
            new OnRecyclerViewAdapterItemClickListener<CountableSushi>() {
                @Override/*from   w w w . j a  v  a 2 s.  c  om*/
                public void onItemClick(View v, RecyclerView.Adapter adapter, int position,
                        CountableSushi model) {
                    model.setCount(model.getCount() + 1);
                    changeItem(position, model);
                }

                @Override
                public void onItemLongClick(View v, RecyclerView.Adapter adapter, final int position,
                        final CountableSushi model) {
                    PopupMenu popupMenu = new PopupMenu(MainActivity.this, v);
                    popupMenu.getMenuInflater().inflate(R.menu.popup_countable_sushi_model_menu,
                            popupMenu.getMenu());
                    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                            case R.id.popup_menu_sushi_delete:
                                removeItem(position, model);
                                snackbar(model.getName() + "????");
                                break;
                            case R.id.popup_menu_sushi_plus1:
                                model.setCount(model.getCount() + 1);
                                changeItem(position, model);
                                break;
                            case R.id.popup_menu_sushi_minus1:
                                if (model.getCount() - 1 >= 0) {
                                    model.setCount(model.getCount() - 1);
                                }
                                changeItem(position, model);
                                break;
                            }
                            return true;
                        }
                    });
                    popupMenu.show();
                }
            });
    mMainRecyclerView.setAdapter(mainAdapter);
}

From source file:org.hawkular.client.android.fragment.AlertDetailFragment.java

private void showAlertMenu(final View view) {
    PopupMenu alertMenu = new PopupMenu(getActivity(), view);

    alertMenu.getMenuInflater().inflate(R.menu.popup_alerts, alertMenu.getMenu());

    alertMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//w  w  w .  ja  v a  2 s . co m
        public boolean onMenuItemClick(MenuItem menuItem) {

            switch (menuItem.getItemId()) {
            case R.id.menu_resolve:
                BackendClient.of(AlertDetailFragment.this).resolveAlert(alert,
                        new AlertActionCallback(R.string.alert_state_res));
                return true;

            case R.id.menu_acknowledge:
                BackendClient.of(AlertDetailFragment.this).acknowledgeAlert(alert,
                        new AlertActionCallback(R.string.alert_state_ack));
                return true;

            default:
                return false;
            }
        }
    });

    alertMenu.show();
}

From source file:org.videolan.vlc.gui.video.VideoGridFragment.java

@TargetApi(11)
public void onContextPopupMenu(View anchor, final int position) {
    if (!Util.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();//from ww  w .j  a  va 2 s.  c o m
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}

From source file:org.messic.android.smartphone.activities.main.fragments.explore.ExploreFragment.java

@Override
public void moreTouch(final MDMAlbum album, View anchor, int index) {
    // Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(ExploreFragment.this.getActivity(), anchor);

    // Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.activity_explore_menu_album, popup.getMenu());

    // registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_album_item_play:
                presenter.playAction(album);
                break;
            case R.id.menu_album_item_playnow:
                presenter.longPlayAction(album);
                break;
            case R.id.menu_album_item_download:
                presenter.downloadAlbum(album);
                break;
            }/*from ww  w. jav a2s .c  o m*/
            return true;
        }

    });

    popup.show();// showing popup menu
}

From source file:sharedcode.turboeditor.activity.SelectFileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    ThemeUtils.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_file);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);/*from ww  w.ja v  a 2 s. c o  m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = action == Actions.SelectFile;

    listView = (ListView) findViewById(android.R.id.list);
    listView.setOnItemClickListener(this);
    listView.setTextFilterEnabled(true);

    FloatingActionButton mFab = (FloatingActionButton) findViewById(R.id.fabbutton);
    mFab.setColor(getResources().getColor(R.color.fab_light));
    mFab.setDrawable(getResources().getDrawable(R.drawable.ic_fab_add));

    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SelectFileActivity.this, v);

            popup.getMenuInflater().inflate(R.menu.popup_new_file, popup.getMenu());

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    int i = item.getItemId();
                    if (i == R.id.im_new_file) {
                        EditTextDialog.newInstance(EditTextDialog.Actions.NewFile)
                                .show(getFragmentManager().beginTransaction(), "dialog");
                        return true;
                    } else if (i == R.id.im_new_folder) {
                        EditTextDialog.newInstance(EditTextDialog.Actions.NewFolder)
                                .show(getFragmentManager().beginTransaction(), "dialog");
                        return true;
                    } else {
                        return false;
                    }
                }
            });

            popup.show();
        }
    });

    mFab.listenTo(listView);

    String lastNavigatedPath = PreferenceHelper.getWorkingFolder(this);

    File file = new File(lastNavigatedPath);

    if (!file.exists()) {
        PreferenceHelper.setWorkingFolder(this, PreferenceHelper.SD_CARD_ROOT);
        file = new File(PreferenceHelper.SD_CARD_ROOT);
    }

    new UpdateList().execute(file.getAbsolutePath());
}

From source file:com.android.calculator3.Calculator2.java

private PopupMenu constructPopupMenu() {
    final PopupMenu popupMenu = new PopupMenu(this, mOverflowMenuButton);
    mOverflowMenuButton.setOnTouchListener(popupMenu.getDragToOpenListener());
    final Menu menu = popupMenu.getMenu();
    popupMenu.inflate(R.menu.menu);/*from   w w  w.  j a va  2  s.c om*/
    popupMenu.setOnMenuItemClickListener(this);
    onPrepareOptionsMenu(menu);
    return popupMenu;
}

From source file:syncthing.android.ui.sessionsettings.SettingsPresenter.java

public void showApiKeyOverflow(final View btn) {
    PopupMenu m = new PopupMenu(btn.getContext(), btn);
    m.inflate(R.menu.apikey_overflow);/*from   w w  w .j  av a  2 s .  com*/
    m.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.copy:
                copyApiKey(btn);
                return true;
            case R.id.generate:
                regenApiKey(btn);
                return true;
            default:
                return false;
            }
        }
    });
    m.show();
}