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.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 ava2 s. c  o m*/
        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.battlelancer.seriesguide.ui.EpisodesFragment.java

@Override
public void onPopupMenuClick(View v, final int episodeTvdbId, final int episodeNumber, final long releaseTimeMs,
        final boolean isWatched, final boolean isCollected) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.episodes_popup_menu);

    Menu menu = popupMenu.getMenu();
    menu.findItem(R.id.menu_action_episodes_watched).setVisible(!isWatched);
    menu.findItem(R.id.menu_action_episodes_not_watched).setVisible(isWatched);
    menu.findItem(R.id.menu_action_episodes_collection_add).setVisible(!isCollected);
    menu.findItem(R.id.menu_action_episodes_collection_remove).setVisible(isCollected);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from   www. jav a2  s  .  com*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_action_episodes_watched: {
                onFlagEpisodeWatched(episodeTvdbId, episodeNumber, true);
                fireTrackerEventContextMenu("Flag watched");
                return true;
            }
            case R.id.menu_action_episodes_not_watched: {
                onFlagEpisodeWatched(episodeTvdbId, episodeNumber, false);
                fireTrackerEventContextMenu("Flag unwatched");
                return true;
            }
            case R.id.menu_action_episodes_collection_add: {
                onFlagEpisodeCollected(episodeTvdbId, episodeNumber, true);
                fireTrackerEventContextMenu("Flag collected");
                return true;
            }
            case R.id.menu_action_episodes_collection_remove: {
                onFlagEpisodeCollected(episodeTvdbId, episodeNumber, false);
                fireTrackerEventContextMenu("Flag uncollected");
                return true;
            }
            case R.id.menu_action_episodes_watched_previous: {
                onMarkUntilHere(releaseTimeMs);
                fireTrackerEventContextMenu("Flag previously aired");
                return true;
            }
            case R.id.menu_action_episodes_manage_lists: {
                ManageListsDialogFragment.showListsDialog(episodeTvdbId, ListItemTypes.EPISODE,
                        getFragmentManager());
                fireTrackerEventContextMenu("Manage lists");
                return true;
            }
            }
            return false;
        }
    });
    popupMenu.show();
}

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//from   w  w  w  . j  a 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.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;
            }//from ww  w  .ja v a  2  s  .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   w w  w.  ja v a 2  s  .  co  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: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();// w  ww . j  a  v  a  2 s .com
        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.alfresco.mobile.android.application.fragments.sync.SyncCursorAdapter.java

protected void updateBottomText(TwoLinesProgressViewHolder vh, final Cursor cursor) {
    int status = cursor.getInt(SyncContentSchema.COLUMN_STATUS_ID);
    String nodeId = cursor.getString(SyncContentSchema.COLUMN_NODE_ID_ID);
    long favoriteId = cursor.getLong(SyncContentSchema.COLUMN_ID_ID);
    boolean syncRoot = cursor.getInt(SyncContentSchema.COLUMN_IS_SYNC_ROOT_ID) > 0;

    if (syncRoot) {
        vh.favoriteIcon.setVisibility(View.VISIBLE);
        vh.favoriteIcon.setImageResource(R.drawable.ic_sync_light);
    } else {//from  ww w  .j  a  v  a  2  s.c om
        vh.favoriteIcon.setVisibility(View.GONE);
    }

    vh.progress.setVisibility(View.GONE);
    switch (status) {
    case SyncContentStatus.STATUS_PENDING:
        displayStatut(vh, R.drawable.sync_status_pending);
        break;
    case SyncContentStatus.STATUS_RUNNING:
        displayStatut(vh, R.drawable.sync_status_loading);
        vh.progress.setVisibility(View.VISIBLE);
        vh.favoriteIcon.setVisibility(View.GONE);
        long totalSize = cursor.getLong(SyncContentSchema.COLUMN_TOTAL_SIZE_BYTES_ID);
        if (totalSize == -1) {
            vh.progress.setIndeterminate(true);
        } else {
            long progress = cursor.getLong(SyncContentSchema.COLUMN_BYTES_DOWNLOADED_SO_FAR_ID);
            float value = (((float) progress / ((float) totalSize)) * 100);
            int percentage = Math.round(value);
            vh.progress.setIndeterminate(false);
            vh.progress.setMax(100);
            vh.progress.setProgress(percentage);
        }
        break;
    case SyncContentStatus.STATUS_HIDDEN:
        vh.favoriteIcon.setVisibility(View.GONE);
        vh.iconRight.setVisibility(View.GONE);
        break;
    case SyncContentStatus.STATUS_PAUSED:
        displayStatut(vh, R.drawable.sync_status_pending);
        break;
    case SyncContentStatus.STATUS_MODIFIED:
        displayStatut(vh, R.drawable.sync_status_pending);
        break;
    case SyncContentStatus.STATUS_SUCCESSFUL:
        displayStatut(vh, R.drawable.sync_status_success);
        break;
    case SyncContentStatus.STATUS_FAILED:
        displayStatut(vh, R.drawable.sync_status_failed);
        break;
    case SyncContentStatus.STATUS_CANCEL:
        displayStatut(vh, R.drawable.sync_status_failed);
        break;
    case SyncContentStatus.STATUS_REQUEST_USER:
        displayStatut(vh, R.drawable.sync_status_failed);
        break;
    default:
        break;
    }

    if (selectedItems != null && selectedItems.contains(nodeId)) {
        UIUtils.setBackground(((View) vh.icon.getParent()),
                context.getResources().getDrawable(R.drawable.list_longpressed_holo));
    } else {
        UIUtils.setBackground(((View) vh.icon.getParent()), null);
    }

    if (SyncContentStatus.STATUS_RUNNING != status) {
        vh.bottomText.setVisibility(View.VISIBLE);
        vh.bottomText.setText(createContentBottomText(context, cursor));
        AccessibilityUtils.addContentDescription(vh.bottomText,
                createContentDescriptionBottomText(context, cursor));
    } else {
        vh.bottomText.setVisibility(View.GONE);
    }

    if (mode == SyncFragment.MODE_LISTING && fragmentRef.get().getActivity() instanceof MainActivity) {
        if (status != SyncContentStatus.STATUS_REQUEST_USER) {
            UIUtils.setBackground(vh.choose, null);
            return;
        }

        vh.choose.setImageResource(R.drawable.ic_more_options);
        vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light);
        int d_16 = DisplayUtils.getPixels(context, R.dimen.d_16);
        vh.choose.setPadding(d_16, d_16, d_16, d_16);

        vh.choose.setVisibility(View.VISIBLE);
        vh.choose.setTag(R.id.node_action, nodeId);
        vh.choose.setTag(R.id.favorite_id, favoriteId);
        vh.choose.setTag(R.id.operation_status, status);
        vh.choose.setTag(R.id.is_synced, syncRoot);
        AccessibilityUtils.addContentDescription(vh.choose,
                String.format(context.getString(R.string.more_options_favorite),
                        cursor.getString(SyncContentSchema.COLUMN_TITLE_ID)));
        vh.choose.setOnClickListener(new OnClickListener() {
            @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            @Override
            public void onClick(View v) {
                String item = (String) v.getTag(R.id.node_action);
                Integer statut = (Integer) v.getTag(R.id.operation_status);
                long favoriteId = (Long) v.getTag(R.id.favorite_id);
                boolean rootSynced = (Boolean) v.getTag(R.id.is_synced);

                selectedOptionItems.add(item);
                selectedOptionItemId.add(favoriteId);

                PopupMenu popup = new PopupMenu(context, v);
                getMenu(popup.getMenu(), statut, rootSynced);
                popup.setOnDismissListener(new OnDismissListener() {
                    @Override
                    public void onDismiss(PopupMenu menu) {
                        selectedOptionItems.clear();
                    }
                });

                popup.setOnMenuItemClickListener(SyncCursorAdapter.this);

                popup.show();
            }
        });
    } else {
        UIUtils.setBackground(vh.choose, null);
    }
}

From source file:nz.ac.auckland.lablet.ExperimentAnalysisFragment.java

private void showDataMenu(ExperimentAnalysis experimentAnalysis) {
    final View menuView = getActivity().findViewById(R.id.action_data);
    PopupMenu popup = new PopupMenu(getActivity(), menuView);
    final ViewPager pager = ((ExperimentAnalysisActivity) getActivity()).getViewPager();

    final List<ExperimentAnalysis.AnalysisEntry> analysisList = experimentAnalysis
            .getAnalysisRunAt(analysisRef.runId).analysisList;
    int i = 0;/*from  w ww.ja v  a 2  s. c  o m*/
    for (ExperimentAnalysis.AnalysisEntry analysisEntry : analysisList) {
        MenuItem item = popup.getMenu().add(1, i, Menu.NONE, analysisEntry.analysis.getDisplayName());
        item.setCheckable(true);

        if (pager.getCurrentItem() == i)
            item.setChecked(true);
        i++;
    }
    popup.getMenu().setGroupCheckable(1, true, true);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            int item = menuItem.getItemId();
            pager.requestLayout();
            pager.setCurrentItem(item, true);
            return false;
        }
    });
    popup.show();
}

From source file:org.messic.android.smartphone.activities.main.MainActivity.java

private void openSettings() {
    View anchor = findViewById(R.id.action_settings);

    // Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(this, anchor);

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

    // registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_base_item_removedatabase:
                emptyDatabaseAction();//from   ww  w  .java2s . c  o  m
                break;
            case R.id.menu_base_item_logout:
                presenter.logout();

                Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                finish(); // call this to finish the current activity

                break;
            case R.id.menu_base_item_clearplaylist:
                presenter.clearQueue();
                break;
            case R.id.menu_base_item_playrandom:
                presenter.addRandomSongsToPlaylist();
                break;
            case R.id.menu_base_item_showlicense:
                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.gnu.org/licenses/gpl-3.0-standalone.html"));
                startActivity(browserIntent);

                break;
            }
            return true;
        }
    });

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

From source file:sharedcode.wyeditor.ui.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);// w  w w  .j  av a  2 s  . c o  m

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = true; //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.defaultFolder(this));
        file = new File(PreferenceHelper.defaultFolder(this));
    }

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