Example usage for android.widget PopupMenu getMenu

List of usage examples for android.widget PopupMenu getMenu

Introduction

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

Prototype

public Menu getMenu() 

Source Link

Document

Returns the Menu associated with this popup.

Usage

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   w w  w.java2s . c o m*/
            return true;
        }

    });

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

From source file:com.filepager.afilechooser.FileChooserActivity.java

public void showPopUp(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.file_type_selection, popup.getMenu());
    popup.show();/*w  ww  . ja  v  a  2s  . c om*/

}

From source file:com.owncloud.android.ui.adapter.UserListAdapter.java

private void onOverflowIconClicked(View view, AppCompatCheckBox allowEditsCheckBox, OCShare share) {
    // use grey as fallback for elements where custom theming is not available
    if (ThemeUtils.themingEnabled(context)) {
        context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
    }/*from   w  ww.j  a va  2s .co m*/
    PopupMenu popup = new PopupMenu(context, view);
    popup.inflate(R.menu.file_detail_sharing_menu);

    prepareOptionsMenu(popup.getMenu(), share);

    popup.setOnMenuItemClickListener(
            item -> optionsItemSelected(popup.getMenu(), item, allowEditsCheckBox, share));
    popup.show();
}

From source file:com.battlelancer.seriesguide.ui.ActivityFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) {
    PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
    Menu menu = popupMenu.getMenu();

    Cursor episode = (Cursor) mAdapter.getItem(position);
    if (episode == null) {
        return false;
    }//from   www  .  j  av  a  2s . com

    // only display the action appropriate for the items current state
    menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin);
    if (EpisodeTools.isWatched(episode.getInt(ActivityQuery.WATCHED))) {
        menu.add(0, CONTEXT_FLAG_UNWATCHED_ID, 1, R.string.action_unwatched);
    } else {
        menu.add(0, CONTEXT_FLAG_WATCHED_ID, 1, R.string.action_watched);
    }
    if (EpisodeTools.isCollected(episode.getInt(ActivityQuery.COLLECTED))) {
        menu.add(0, CONTEXT_COLLECTION_REMOVE_ID, 2, R.string.action_collection_remove);
    } else {
        menu.add(0, CONTEXT_COLLECTION_ADD_ID, 2, R.string.action_collection_add);
    }

    final int showTvdbId = episode.getInt(ActivityQuery.SHOW_ID);
    final int episodeTvdbId = episode.getInt(ActivityQuery._ID);
    final int seasonNumber = episode.getInt(ActivityQuery.SEASON);
    final int episodeNumber = episode.getInt(ActivityQuery.NUMBER);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case CONTEXT_CHECKIN_ID: {
                checkInEpisode((int) id);
                return true;
            }
            case CONTEXT_FLAG_WATCHED_ID: {
                updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                return true;
            }
            case CONTEXT_FLAG_UNWATCHED_ID: {
                updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                return true;
            }
            case CONTEXT_COLLECTION_ADD_ID: {
                updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                return true;
            }
            case CONTEXT_COLLECTION_REMOVE_ID: {
                updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                return true;
            }
            }
            return false;
        }
    });

    popupMenu.show();

    return true;
}

From source file:za.ac.uct.cs.lwsjam005.eshelf.activities.ReadActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        // go back home

        // ensure we are resuming the existing activity
        Intent intent = new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(ARG_CURRENT_PAGE, currentPage);
        intent.putExtra(ARG_BOOKMARKS, thisBook.getBookmarks());
        intent.setAction(MainActivity.ACTION_RETURN_FROM_READ);

        startActivity(intent);/*  www.ja v  a2 s  .c  o  m*/

        return true;

    case R.id.action_previous:
        // Go to the previous step in the wizard. If there is no previous
        // step,
        // setCurrentItem will do nothing.
        mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        return true;

    case R.id.action_next:
        // Advance to the next step in the wizard. If there is no next step,
        // setCurrentItem
        // will do nothing.
        mPager.setCurrentItem(mPager.getCurrentItem() + 1);
        return true;
    case R.id.action_bookmarks:
        PopupMenu popup = new PopupMenu(this, this.findViewById(R.id.action_bookmarks));
        popup.setOnMenuItemClickListener(this);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.popup_menu_bookmarks, popup.getMenu());

        popup.show();

        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.lytsing.android.weibo.ui.ComposeActivity.java

@Override
public void onClick(View view) {
    int viewId = view.getId();

    if (viewId == android.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return;//from w ww.ja  v a  2s .c om
    }

    if (viewId == R.id.ll_text_limit_unit) {
        mContent = mEdit.getText().toString();
        if (TextUtils.isEmpty(mContent))
            return;

        DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                mEdit.setText("");
            }
        };

        AlertUtil.showAlert(this, R.string.attention, R.string.delete_all, getString(R.string.ok), listener,
                getString(R.string.cancel), null);
    } else if (viewId == R.id.ib_insert_pic) {
        PopupMenu popup = new PopupMenu(this, view);
        popup.getMenuInflater().inflate(R.menu.pic, popup.getMenu());

        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(android.view.MenuItem item) {

                Intent galleryIntent = new Intent();
                galleryIntent.setType("image/*");
                galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
                galleryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                startActivityForResult(galleryIntent, 2);

                return true;
            }
        });

        popup.show();
    } else if (viewId == R.id.ib_face_keyboard) {
        showOrHideIMM();
    } else if (viewId == R.id.ib_insert_location) {
        if (mIsLocation) {
            aq.id(R.id.tv_location).gone();
            aq.id(R.id.ib_insert_location).image(R.drawable.btn_insert_location_nor);
            mIsLocation = false;
            mLatitude = "";
            mLongitude = "";
        } else {
            aq.id(R.id.ly_loadlocation).visible();
            location_ajax();
        }
    }
}

From source file:de.aw.monma.actions.FragmentWPList.java

/**
 * Bei Click wird das contextmenu gezeigt. In den jeweiligen extras sind folgende Informationen
 * enthalten: WPID, AMOUNT, WPNAME des gewaehlten Wertpapiers.
 *///from w  w  w . j  a  v a 2  s  . co m
@Override
public void onRecyclerItemClick(View view, int position, WertpapierListItem item) {
    super.onRecyclerItemClick(view, position, item);
    Intent intent = new Intent();
    intent.putExtra(WPID, item.getID());
    intent.putExtra(WPNAME, item.getWPName());
    intent.putExtra(ACCOUNTID, NOID);
    intent.putExtra(AMOUNT, item.getGewinn());
    PopupMenu popUpMenu = new PopupMenu(getActivity(), view);
    popUpMenu.inflate(R.menu.context_fragment_wpuebersicht);
    popUpMenu.inflate(R.menu.context_fragment_wpliste);
    Menu menu = popUpMenu.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setIntent(intent);
    }
    popUpMenu.setOnMenuItemClickListener(this);
    popUpMenu.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/* w  w w.  j ava 2 s .  c  o m*/
                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.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//from   ww  w  . j  ava2  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: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);//  www  .  ja  v  a2s . c  o m
    popupMenu.setOnMenuItemClickListener(this);
    onPrepareOptionsMenu(menu);
    return popupMenu;
}