Example usage for android.widget PopupMenu getMenuInflater

List of usage examples for android.widget PopupMenu getMenuInflater

Introduction

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

Prototype

public MenuInflater getMenuInflater() 

Source Link

Usage

From source file:com.vrs.reqdroid.fragments.RequisitosFragment.java

/**
 * Mostra o PopUpMenu das opcoes do requisito.
 * Funciona apenas para a versao 3.0 ou superior do Android.
 *
 * @param v a view do requisito/*from  w ww  .jav  a  2s  .co m*/
 *
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void exibePopupMenuOpcoes(final View v) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.menu_opcoes_requisito, popupMenu.getMenu());

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.opcaoEditarRequisito:
                menuEdita();
                break;
            case R.id.opcaoMoverRequisito:
                menuMove();
                break;
            case R.id.opcaoDeletarRequisito:
                menuDeleta();
                break;
            }
            return true;
        }
    });
    popupMenu.show();
}

From source file:com.vrs.reqdroid.fragments.RequisitosAtrasadosFragment.java

/**
 * Mostra o PopUpMenu das opcoes do requisito.
 * Funciona apenas para a versao 3.0 ou superior do Android.
 *
 * @param v a view do requisito//from w  w w. ja v a 2  s. c  om
 *
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void exibePopupMenuOpcoes(final View v) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.menu_opcoes_requisito_atrasado, popupMenu.getMenu());

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.opcaoEditarRequisitoAtrasado:
                menuEdita();
                break;
            case R.id.opcaoMoverRequisitoAtrasado:
                menuMove();
                break;
            case R.id.opcaoDeletarRequisitoAtrasado:
                menuDeleta();
                break;
            }
            return true;
        }
    });
    popupMenu.show();
}

From source file:com.vrs.reqdroid.fragments.HipotesesFragment.java

/**
 * Mostra o PopUpMenu das opcoes da hipotese
 * Funciona apenas para a versao 3.0 ou superior do Android.
 *
 * @param v a view da hipotese//ww  w. jav a 2  s .  co  m
 *
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
void exibePopupMenuOpcoes(final View v) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.menu_opcoes_hipotese, popupMenu.getMenu());

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.opcaoEditarHipotese:
                menuEdita();
                break;
            case R.id.opcaoValidarHipotese:
                menuValida();
                break;
            case R.id.opcaoDeletarHipotese:
                menuDeleta();
                break;
            }
            return true;
        }
    });
    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/*from ww  w.  ja  v  a  2 s  .  com*/
                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:com.dgsd.android.ShiftTracker.Fragment.WeekFragment.java

@Override
public void onItemClick(AdapterView<?> list, final View view, int pos, long id) {
    final WeekAdapter.ViewHolder holder = (WeekAdapter.ViewHolder) view.getTag();
    final Intent intent = getIntentFor(holder);
    if (!mHasTemplates || (holder != null && holder.shift != null)) {
        startActivity(intent);/*from  w  ww. ja  v a 2s. c o  m*/
        return;
    }

    final int jd = holder == null ? -1 : holder.julianDay;
    if (Api.isMin(Api.HONEYCOMB)) {
        PopupMenu popup = new PopupMenu(getActivity(), view.findViewById(R.id.text));
        popup.getMenuInflater().inflate(R.menu.week_list_item_popup, popup.getMenu());
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.template_shift) {
                    showTemplateChooser(jd);
                } else if (item.getItemId() == R.id.new_shift) {
                    startActivity(intent);
                }
                return false;
            }
        });

        popup.show();
    } else {
        mList.showContextMenuForChild(view);
    }
}

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();/*from w  ww  .  ja v a2 s.  c  om*/

}

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);/*  w  w w .j a v a  2 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.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;
            }/*w ww  .ja  v  a  2  s . c  om*/
            return true;
        }

    });

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

From source file:org.messic.android.smartphone.activities.main.fragments.downloaded.DownloadedFragment.java

@Override
public void onMoreAction(View caller, View anchor, final DownloadedAlbumViewHolder holder) {
    // Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(DownloadedFragment.this.getActivity(), anchor);

    // Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.activity_downloaded_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_remove:
                removeAlbum(holder.album, holder);
                break;
            case R.id.menu_album_item_play:
                presenter.playAction(holder.album);
                break;
            case R.id.menu_album_item_playnow:
                presenter.longPlayAction(holder.album);
                break;
            }/*  w  w  w  . j ava  2  s .  c o m*/
            return true;
        }

    });

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

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  v a2s.c o m
        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();
}