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:de.aw.monma.mainscreen.ActivityMainScreen.java

@Override
public boolean onRecyclerItemLongClick(RecyclerView recyclerView, View view, int position, long id,
        int viewHolderLayoutID) {
    switch (viewHolderLayoutID) {
    case R.layout.reportlist_item:
        PopupMenu popUpMenu = new PopupMenu(this, view);
        Menu menu = popUpMenu.getMenu();
        popUpMenu.getMenuInflater().inflate(R.menu.context_fragment_report_selection, menu);
        for (int i = 0; i < menu.size(); i++) {
            Intent intent = new Intent();
            intent.putExtra(ID, id);//  w w  w.ja  v a  2 s . c o  m
            menu.getItem(i).setIntent(intent);
        }
        popUpMenu.setOnMenuItemClickListener(this);
        popUpMenu.show();
        return true;
    case R.layout.finanzuebersicht_item:
        DialogFragmentKontoEdit d = DialogFragmentKontoEdit.newInstance(new Account((int) id));
        d.show(getSupportFragmentManager(), null);
        return true;
    case R.layout.hbcipassport_item:
        final long mID = id;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.HBCIZugangDelete);
        builder.setMessage(R.string.HBCIZugangDeleteMsg);
        builder.setPositiveButton(getString(R.string.awlib_btnAccept), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                try {
                    MonMaPassport passport = new MonMaPassport(mID);
                    passport.delete(DBHelper.getInstance());
                } catch (GeschaeftsObjekt.LineNotFoundException e) {
                    //TODO Execption bearbeiten
                    e.printStackTrace();
                }
            }
        });
        builder.setNegativeButton(getString(R.string.awlib_btnCancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.create().show();
        return true;
    default:
        return false;
    }
}

From source file:com.notalenthack.blaster.CommandActivity.java

@Override
public void onClick(View v) {
    Integer position = (Integer) v.getTag();
    if (v.getId() == R.id.btnEditCommand) {
        final Command cmd = mListAdapter.getCommand(position);
        Log.d(TAG, "Edit button click for position " + position);
        //Creating the instance of PopupMenu
        PopupMenu popup = new PopupMenu(this, v);
        //Inflating the Popup using xml file
        popup.getMenuInflater().inflate(R.menu.edit_delete, popup.getMenu());
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override/*from   ww  w .j av a2 s  .c om*/
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.edit) {
                    editCommand(cmd);
                } else if (item.getItemId() == R.id.delete) {
                    mListAdapter.deleteCommand(cmd);
                } else {
                    return false;
                }
                saveCommands(); // update commands in pref for presistent
                mListAdapter.notifyDataSetChanged();
                return true;
            }
        });

        // show the popup
        popup.show();

    } else if (v.getId() == R.id.btnCommandAction) {
        Log.d(TAG, "Play button click for position " + position);
        handlePlayCommand(position);
    }
}

From source file:com.silentcircle.contacts.editor.RawContactEditorView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void showAddInformationPopupWindow() {
    final ArrayList<KindSectionView> fields = getSectionViewsWithoutFields();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        showAddInformationPopupWindow(fields);
    } else {// ww  w. ja  v  a2  s. co m
        final PopupMenu popupMenu = new PopupMenu(getContext(), mAddFieldButton);
        final Menu menu = popupMenu.getMenu();
        for (int i = 0; i < fields.size(); i++) {
            menu.add(Menu.NONE, i, Menu.NONE, fields.get(i).getTitle());
        }

        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                final KindSectionView view = fields.get(item.getItemId());
                if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(view.getKind().mimeType)) {
                    mPhoneticNameAdded = true;
                    updatePhoneticNameVisibility();
                } else {
                    view.addItem();
                }

                // If this was the last section without an entry, we just added one, and therefore
                // there's no reason to show the button.
                if (fields.size() == 1) {
                    mAddFieldButton.setVisibility(GONE);
                }

                return true;
            }
        });
        popupMenu.show();
    }
}

From source file:com.zigvine.zagriculture.UIActivity.java

@TargetApi(11)
private void showPopupMenu() {
    final PopupMenu popupMenu = new PopupMenu(this, mOverflowMenuButton);
    final Menu menu = popupMenu.getMenu();
    // popupMenu.inflate(R.menu.main_menu);
    popupMenu.getMenuInflater().inflate(R.menu.main_menu, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from ww  w .ja v a  2  s.  c om*/
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    onPrepareOptionsMenu(menu);
    if (popupMenu != null) {
        popupMenu.show();
    }
}

From source file:com.filemanager.free.adapters.Recycleradapter.java

void showPopup(View v, final Layoutelements rowItem) {
    v.setOnClickListener(new View.OnClickListener() {
        @Override/* w  w w . j  av a 2s .c  o m*/
        public void onClick(View view) {
            PopupMenu popupMenu = new PopupMenu(main.getActivity(), view);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.about:
                        main.utils.showProps((rowItem).generateBaseFile(), rowItem.getPermissions(), main,
                                main.ROOT_MODE);
                        return true;
                    case R.id.share:
                        ArrayList<File> arrayList = new ArrayList<File>();
                        arrayList.add(new File(rowItem.getDesc()));
                        main.utils.shareFiles(arrayList, main.MAIN_ACTIVITY, main.theme1,
                                Color.parseColor(main.fabSkin));
                        return true;
                    case R.id.rename:
                        main.rename(rowItem.generateBaseFile());
                        return true;
                    case R.id.cpy:
                        MainActivity MAIN_ACTIVITY = main.MAIN_ACTIVITY;
                        main.MAIN_ACTIVITY.MOVE_PATH = null;
                        ArrayList<BaseFile> copies = new ArrayList<>();
                        copies.add(rowItem.generateBaseFile());
                        MAIN_ACTIVITY.COPY_PATH = copies;
                        MAIN_ACTIVITY.supportInvalidateOptionsMenu();
                        return true;
                    case R.id.cut:
                        MainActivity MAIN_ACTIVITY1 = main.MAIN_ACTIVITY;
                        MAIN_ACTIVITY1.COPY_PATH = null;
                        ArrayList<BaseFile> copie = new ArrayList<>();
                        copie.add(rowItem.generateBaseFile());
                        MAIN_ACTIVITY1.MOVE_PATH = copie;
                        MAIN_ACTIVITY1.supportInvalidateOptionsMenu();
                        return true;
                    case R.id.ex:
                        main.MAIN_ACTIVITY.mainActivityHelper.extractFile(new File(rowItem.getDesc()));
                        return true;
                    case R.id.book:
                        DataUtils.addBook(new String[] { rowItem.getTitle(), rowItem.getDesc() }, true);
                        main.MAIN_ACTIVITY.updateDrawer();
                        Toast.makeText(main.getActivity(),
                                main.utils.getString(main.getActivity(), R.string.bookmarksadded),
                                Toast.LENGTH_LONG).show();
                        return true;

                    }
                    return false;
                }
            });
            popupMenu.inflate(R.menu.item_extras);
            String x = rowItem.getDesc().toLowerCase();
            if (rowItem.isDirectory())
                popupMenu.getMenu().findItem(R.id.share).setVisible(false);
            if (x.endsWith(".zip") || x.endsWith(".jar") || x.endsWith(".apk") || x.endsWith(".rar")
                    || x.endsWith(".tar") || x.endsWith(".tar.gz"))
                popupMenu.getMenu().findItem(R.id.ex).setVisible(true);
            popupMenu.show();
        }
    });

}

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 .j av a 2  s . co 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:net.sourceforge.lifeograph.ActivityDiary.java

public void CreateCtgMenu(View v) {
    mElemMenu = (DiaryElement) v.getTag();

    PopupMenu popup = new PopupMenu(getActivity(), v);
    popup.setOnMenuItemClickListener(this);

    if (mElemMenu.get_type() == DiaryElement.Type.TAG_CTG)
        popup.inflate(R.menu.menu_tag_ctg);
    else/*from ww  w.j a v  a  2s  . c  o  m*/
        popup.inflate(R.menu.menu_chapter_ctg);

    popup.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 {//w  w  w. jav  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:com.appunite.appunitevideoplayer.PlayerActivity.java

private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener,
        final int trackType) {
    if (player == null) {
        return;/*from  www. ja v  a  2  s . c  o m*/
    }
    int trackCount = player.getTrackCount(trackType);
    if (trackCount == 0) {
        return;
    }
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return (customActionClickListener != null && customActionClickListener.onMenuItemClick(item))
                    || onTrackItemClick(item, trackType);
        }
    });
    Menu menu = popup.getMenu();
    // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0)
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.TRACK_DISABLED + ID_OFFSET, Menu.NONE, R.string.off);
    for (int i = 0; i < trackCount; i++) {
        menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE,
                buildTrackName(player.getTrackFormat(trackType, i)));
    }
    menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
    menu.findItem(player.getSelectedTrack(trackType) + ID_OFFSET).setChecked(true);
}

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