Example usage for android.widget PopupMenu show

List of usage examples for android.widget PopupMenu show

Introduction

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

Prototype

public void show() 

Source Link

Document

Show the menu popup anchored to the view specified during construction.

Usage

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

public void showVerboseLogPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();/*from w w w . ja  va  2 s.  c om*/
    menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal);
    menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose);
    menu.setGroupCheckable(Menu.NONE, true, true);
    menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == 0) {
                VerboseLogUtil.setEnableAllTags(false);
            } else {
                VerboseLogUtil.setEnableAllTags(true);
            }
            return true;
        }
    });
    popup.show();
}

From source file:de.spiritcroc.ownlog.ui.view.EditTagsView.java

private void showAddTagMenu() {
    // Ensure we have a tags provider
    if (mTagsProvider == null) {
        Log.e(TAG, "Cannot load tags: no tags provider");
        return;//ww w  . j  ava  2s  .  c  o m
    }
    // Use context from activity instead of getContext() to separate popup from
    // this view's theme (padding etc.)
    PopupMenu popupMenu = new PopupMenu(mTagsProvider.getActivity(), mAddTagButton);
    Menu menu = popupMenu.getMenu();
    final List<TagItem> availableTags = mTagsProvider.getAvailableTags();
    final List<TagItem> setTags = mTagsProvider.getSetTags();
    final HashMap<String, TagItem> tagMap = new HashMap<>();
    for (TagItem tag : availableTags) {
        if (mAvailableTagsFilter.shouldShowTag(tag)) {
            menu.add(tag.name);
            tagMap.put(tag.name, tag);
        }
    }
    menu.add(R.string.edit_log_tags_add_new);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            String name = menuItem.getTitle().toString();
            if (tagMap.containsKey(name)) {
                setTags.add(tagMap.get(name));
                mTagsProvider.onSetTagsChanged();
                updateContent();
            } else {
                new TagItemEditFragment().show(mTagsProvider.getActivity().getFragmentManager(),
                        "TagItemEditFragment");
            }
            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//from   w  ww .j  a  v  a 2  s.c  om
        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:free.yhc.feeder.ChannelListActivity.java

private void onOpt_category(final View anchor) {
    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_category, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from  w ww.jav  a2 s.c  o  m
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.add:
                onOpt_category_add(anchor);
                break;
            case R.id.rename:
                onOpt_category_rename(anchor);
                break;
            case R.id.delete:
                onOpt_category_delete(anchor);
                break;
            default:
                eAssert(false);
            }
            return true;
        }
    });
    popup.show();
}

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  .  ja v  a 2 s .  co 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();
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

public void showAudioPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();/*from  w ww  . ja v  a 2 s . co m*/
    menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
    final MenuItem backgroundAudioItem = menu.findItem(0);
    backgroundAudioItem.setCheckable(true);
    backgroundAudioItem.setChecked(enableBackgroundAudio);
    OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item == backgroundAudioItem) {
                enableBackgroundAudio = !item.isChecked();
                return true;
            }
            return false;
        }
    };
    configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
    popup.show();
}

From source file:org.gateshipone.odyssey.views.NowPlayingView.java

/**
 * Called to open the popup menu on the top right corner.
 *
 * @param v View to which the popup menu should be attached
 *//*from  w w w  .  j ava  2  s  .co m*/
private void showAdditionalOptionsMenu(View v) {
    PopupMenu menu = new PopupMenu(getContext(), v);
    // Inflate the menu from a menu xml file
    menu.inflate(R.menu.popup_menu_nowplaying_view);
    // Set the main NowPlayingView as a listener (directly implements callback)
    menu.setOnMenuItemClickListener(this);
    // Open the menu itself
    menu.show();
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_addChannel(final View anchor) {
    if (0 == mAb.getNavigationItemCount()) {
        eAssert(false);//  www  .  j a v  a 2  s. co m
        return;
    }

    if (0 > mAb.getSelectedNavigationIndex()) {
        UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_select_category_to_add);
        return;
    }

    if (!Utils.isNetworkAvailable()) {
        // TODO Handling error
        UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_network_unavailable);
        return;
    }

    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_addchannel, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.predefined:
                onOpt_addChannel_predefined(anchor);
                break;
            case R.id.url:
                onOpt_addChannel_url(anchor);
                break;
            case R.id.youtube:
                onOpt_addChannel_youtube(anchor);
                break;
            default:
                eAssert(false);
            }
            return true;
        }
    });
    popup.show();
}

From source file:com.maskyn.fileeditorpro.activity.SelectFileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    currentFolder = PreferenceHelper.defaultFolder(this);

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);//from  w w  w. j ava  2  s.co  m

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = true; //action == Actions.SelectFile;
    mfabOkMode = false;
    folderOpenMode = getIntent().getBooleanExtra("foldermode", false);
    if (folderOpenMode)
        setTitle("Open Folder");

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

    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) {
            if (!mfabOkMode) {
                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();
            }
            if (mfabOkMode) {
                finishWithResult(selectedFile);
            }
        }
    });

    mFab.listenTo(listView);

    String lastNavigatedPath = PreferenceHelper.getWorkingFolder(this);

    File file = new File(lastNavigatedPath);

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

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