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.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java

/**
 * Run during fragment initialization, this sets up the cover art popup menu and the coverArt
 * ImageView.//from w  w w.  j av  a2 s  .  c om
 *
 * @param view The view to setup the coverArt ImageView in.
 * @return The resulting ImageView.
 */
private ImageView getCoverArt(final View view) {
    final ImageView coverArt = (ImageView) view.findViewById(R.id.albumCover);
    final PopupMenu coverMenu = new PopupMenu(mActivity, coverArt);
    final Menu menu = coverMenu.getMenu();

    coverArt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            scrollToNowPlaying();
        }
    });

    menu.add(Menu.NONE, POPUP_COVER_BLACKLIST, Menu.NONE, R.string.otherCover);
    menu.add(Menu.NONE, POPUP_COVER_SELECTIVE_CLEAN, Menu.NONE, R.string.resetCover);
    coverMenu.setOnMenuItemClickListener(this);
    coverArt.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            final boolean isConsumed;

            if (mCurrentSong != null) {
                menu.setGroupVisible(Menu.NONE, new AlbumInfo(mCurrentSong).isValid());
                coverMenu.show();
                isConsumed = true;
            } else {
                isConsumed = false;
            }

            return isConsumed;
        }
    });

    return coverArt;
}

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

private void showViewMenu() {
    View menuView = findViewById(R.id.action_view);
    PopupMenu popup = new PopupMenu(menuView.getContext(), menuView);

    final List<IExperimentSensor> experimentRuns = getActiveSensors();
    for (int i = 0; i < experimentRuns.size(); i++) {
        IExperimentSensor experiment = experimentRuns.get(i);

        MenuItem item = popup.getMenu().add(1, i, i, experiment.getClass().getSimpleName());
        item.setCheckable(true);//from   w ww .  j ava 2 s .  c  om
    }
    popup.getMenu().setGroupCheckable(1, true, true);
    IExperimentSensor currentExperimentSensor = experiment.getCurrentExperimentSensor();
    if (currentExperimentSensor != null)
        popup.getMenu().getItem(experimentRuns.indexOf(currentExperimentSensor)).setChecked(true);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            int itemPosition = menuItem.getItemId();
            IExperimentSensor experimentRun = experimentRuns.get(itemPosition);
            setCurrentSensor(experimentRun);
            pager.requestLayout();
            pager.setCurrentItem(itemPosition, true);
            return true;
        }
    });

    popup.show();
}

From source file:com.pranavpandey.smallapp.sample.SmallAppSample.java

private void setupOptionMenu() {
    View header = LayoutInflater.from(this).inflate(R.layout.header, new LinearLayout(this), false);

    final View optionMenu = header.findViewById(R.id.option_menu);

    optionMenu.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//from w  w w  . j ava 2 s  . co  m
        public boolean onLongClick(View v) {
            SmallTheme.getInstance().showHeaderHint(v, R.string.sas_options);
            return false;
        }
    });

    optionMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(getContext(), optionMenu);
            try {
                Field[] fields = popup.getClass().getDeclaredFields();
                for (Field field : fields) {
                    if ("mPopup".equals(field.getName())) {
                        field.setAccessible(true);
                        Object menuPopupHelper = field.get(popup);
                        Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
                        Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
                        setForceIcons.invoke(menuPopupHelper, true);
                        break;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.menu_settings:
                        showSettings();
                        break;

                    case R.id.menu_about:
                        new AboutDialog(SmallAppSample.this, R.mipmap.ic_launcher, R.string.app_name, Type.LIST)
                                .show(getRootView());
                        break;

                    case R.id.menu_sources:
                        SmallUtils.openLink(SmallAppSample.this, getRootView(), SOURCES_LINK, null, Type.GRID);
                        break;
                    }

                    return true;
                }
            });
            popup.show();
        }
    });
    getWindow().setHeaderView(header);
}

From source file:com.javielinux.fragments.MyActivityFragment.java

private void showMenuOptions(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        PopupMenu popupMenu = new PopupMenu(getActivity(), v);
        popupMenu.getMenuInflater().inflate(R.menu.my_activity_more_options, popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override/*from   w ww .  j  ava 2  s  . c  o  m*/
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.popupmenu_more_options_size) {
                    showSizeText();
                } else if (item.getItemId() == R.id.popupmenu_more_options_theme) {
                    showThemeDialog();
                } else if (item.getItemId() == R.id.popupmenu_more_options_preferences) {
                    Intent i = new Intent(getActivity(), Preferences.class);
                    startActivity(i);
                } else if (item.getItemId() == R.id.popupmenu_more_options_exit) {
                    showDialogExit();
                }
                return true;
            }
        });
        popupMenu.show();
    } else {
        AlertDialogFragment frag = new AlertDialogFragment();
        Bundle args = new Bundle();
        args.putInt(AlertDialogFragment.KEY_ALERT_TITLE, R.string.actions);
        args.putBoolean(AlertDialogFragment.KEY_ALERT_HAS_POSITIVE_BUTTON, false);
        args.putBoolean(AlertDialogFragment.KEY_ALERT_CANCELABLE, false);
        args.putInt(AlertDialogFragment.KEY_ALERT_ARRAY_ITEMS, R.array.popupmenu_my_activity_more_options);
        frag.setArguments(args);
        frag.setAlertButtonListener(new AlertDialogFragment.AlertButtonListener() {
            @Override
            public void OnAlertButtonOk() {
            }

            @Override
            public void OnAlertButtonCancel() {
            }

            @Override
            public void OnAlertButtonNeutral() {
            }

            @Override
            public void OnAlertItems(int which) {
                if (which == 0) {
                    showSizeText();
                } else if (which == 1) {
                    Intent i = new Intent(getActivity(), Preferences.class);
                    startActivity(i);
                } else if (which == 2) {
                    showThemeDialog();
                } else if (which == 3) {
                    showDialogExit();
                }
            }
        });
        frag.show(getFragmentManager(), "dialog");
    }
}

From source file:com.android.music.MusicBrowserActivity.java

/**
 * M: Create fake menu.// ww  w.  ja v a 2  s .  c o  m
 */
private void createFakeMenu() {

    if (mPermissionReqProcessed == true) {
        if (mHasMenukey) {
            MusicLogUtils.d(TAG, "createFakeMenu Quit when there has Menu Key");
            return;
        }
        if (mOrientaiton == Configuration.ORIENTATION_LANDSCAPE) {
            mOverflowMenuButtonId = R.id.overflow_menu;
            mOverflowMenuButton = findViewById(R.id.overflow_menu);
        } else {
            mOverflowMenuButtonId = R.id.overflow_menu_nowplaying;
            mOverflowMenuButton = findViewById(R.id.overflow_menu_nowplaying);
            View parent = (View) mOverflowMenuButton.getParent();
            if (parent != null) {
                parent.setVisibility(View.VISIBLE);
            }
        }
        mOverflowMenuButton.setVisibility(View.VISIBLE);
        mOverflowMenuButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                MusicLogUtils.d(TAG, "createFakeMenu:onClick()");
                if (v.getId() == mOverflowMenuButtonId) {
                    final PopupMenu popupMenu = new PopupMenu(MusicBrowserActivity.this, mOverflowMenuButton);
                    mPopupMenu = popupMenu;
                    final Menu menu = popupMenu.getMenu();
                    onCreateOptionsMenu(menu);
                    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                        public boolean onMenuItemClick(MenuItem item) {
                            return onOptionsItemSelected(item);
                        }
                    });
                    popupMenu.setOnDismissListener(new OnDismissListener() {
                        public void onDismiss(PopupMenu menu) {
                            mPopupMenuShowing = false;
                            MusicLogUtils.d(TAG, "createFakeMenu:onDismiss() called");
                            return;
                        }
                    });
                    onPrepareOptionsMenu(menu);
                    mPopupMenuShowing = true;
                    if (popupMenu != null) {
                        MusicLogUtils.d(TAG, "createFakeMenu:popupMenu.show()");
                        popupMenu.show();
                    }
                }
            }
        });
    }
}

From source file:im.vector.fragments.GroupsFragment.java

@SuppressLint("NewApi")
private void displayGroupPopupMenu(final Group group, final View actionView) {
    final Context context = getActivity();
    final PopupMenu popup;

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        popup = new PopupMenu(context, actionView, Gravity.END);
    } else {/*from www.  ja v a  2 s . c o m*/
        popup = new PopupMenu(context, actionView);
    }
    popup.getMenuInflater().inflate(R.menu.vector_home_group_settings, popup.getMenu());
    CommonActivityUtils.tintMenuIcons(popup.getMenu(),
            ThemeUtils.getColor(context, R.attr.settings_icon_tint_color));

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.ic_action_select_remove_group: {
                leaveOrReject(group.getGroupId());
                break;
            }
            }
            return false;
        }
    });

    // force to display the icon
    try {
        Field[] fields = popup.getClass().getDeclaredFields();
        for (Field field : fields) {
            if ("mPopup".equals(field.getName())) {
                field.setAccessible(true);
                Object menuPopupHelper = field.get(popup);
                Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
                Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
                setForceIcons.invoke(menuPopupHelper, true);
                break;
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "## displayGroupPopupMenu() : failed " + e.getMessage());
    }

    popup.show();
}

From source file:com.pdftron.pdf.controls.UserBookmarkDialogFragment.java

public void onShowPopupMenu(final int position, View anchor) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    Menu menu = popupMenu.getMenu();

    final UserBookmarkItem bItem = mBookmarkViewAdapter.getItem(position);
    String[] menuItems = getResources().getStringArray(R.array.user_bookmark_dialog_context_menu);
    menu.add(Menu.NONE, CONTEXT_MENU_EDIT_ITEM, CONTEXT_MENU_EDIT_ITEM, menuItems[CONTEXT_MENU_EDIT_ITEM]);
    menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, CONTEXT_MENU_DELETE_ITEM,
            menuItems[CONTEXT_MENU_DELETE_ITEM]);
    menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ALL, CONTEXT_MENU_DELETE_ALL, menuItems[CONTEXT_MENU_DELETE_ALL]);
    MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
        @Override/*from   w  ww  .ja v a  2  s . c  o m*/
        public boolean onMenuItemClick(MenuItem item) {
            onPopupItemSelected(item, position);
            return true;
        }
    };
    menu.getItem(CONTEXT_MENU_EDIT_ITEM).setOnMenuItemClickListener(listener);
    menu.getItem(CONTEXT_MENU_DELETE_ITEM).setOnMenuItemClickListener(listener);
    menu.getItem(CONTEXT_MENU_DELETE_ALL).setOnMenuItemClickListener(listener);
    popupMenu.show();
}

From source file:com.keylesspalace.tusky.ComposeActivity.java

private void onMediaClick(QueuedMedia item, View view) {
    PopupMenu popup = new PopupMenu(this, view);
    final int addCaptionId = 1;
    final int removeId = 2;
    popup.getMenu().add(0, addCaptionId, 0, R.string.action_set_caption);
    popup.getMenu().add(0, removeId, 0, R.string.action_remove_media);
    popup.setOnMenuItemClickListener(menuItem -> {
        switch (menuItem.getItemId()) {
        case addCaptionId:
            makeCaptionDialog(item);/*from  ww w  .j a  v a 2  s .  co  m*/
            break;
        case removeId:
            removeMediaFromQueue(item);
            break;
        }
        return true;
    });
    popup.show();
}

From source file:org.y20k.transistor.helpers.StationContextMenu.java

public void show() {

    PopupMenu popup = new PopupMenu(mActivity, mView);
    popup.inflate(R.menu.menu_main_list_item);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from w ww .jav a  2s . co m*/
        public boolean onMenuItemClick(MenuItem item) {

            switch (item.getItemId()) {

            // CASE ICON
            case R.id.menu_icon:

                // send local broadcast (needed by MainActivityFragment)
                Intent i = new Intent();
                i.setAction(ACTION_IMAGE_CHANGE_REQUESTED);
                i.putExtra(STATION_ID, mStationID);
                LocalBroadcastManager.getInstance(mActivity.getApplication()).sendBroadcast(i);

                return true;

            // CASE RENAME
            case R.id.menu_rename:
                // get name of station
                String stationName = mCollection.getStations().get(mStationID).getStationName();
                // construct rename dialog
                DialogRename dialogRename = new DialogRename(mActivity, mCollection, stationName, mStationID);
                dialogRename.setStationRenamedListener(new DialogRename.StationRenamedListener() {
                    @Override
                    public void stationRenamed() {
                        if (mStationChangedListener != null) {
                            mStationChangedListener.stationChanged();
                        }
                    }
                });
                // run dialog
                dialogRename.show();
                return true;

            // CASE DELETE
            case R.id.menu_delete:
                // construct delete dialog
                DialogDelete dialogDelete = new DialogDelete(mActivity, mCollection, mStationID);
                // run dialog
                dialogDelete.show();
                return true;

            // CASE DEFAULT
            default:
                return false;
            }
        }
    });
    popup.show();
}

From source file:freed.viewer.gridview.GridViewFragment.java

private void showFileSelectionPopup(View v) {
    PopupMenu popup = new PopupMenu(getContext(), v);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*from w  ww .  j a v a2  s .  co  m*/
        public boolean onMenuItemClick(MenuItem item) {
            int i = item.getItemId();
            if (i == id.all) {
                filetypeButton.setText(string.ALL);
                formatsToShow = FormatTypes.all;
            } else if (i == id.raw) {
                filetypeButton.setText("RAW");
                formatsToShow = FormatTypes.raw;
            } else if (i == id.bayer) {
                filetypeButton.setText("BAYER");
                formatsToShow = FormatTypes.raw;
            } else if (i == id.dng) {
                filetypeButton.setText("DNG");
                formatsToShow = FormatTypes.dng;
            } else if (i == id.jps) {
                filetypeButton.setText("JPS");
                formatsToShow = FormatTypes.jps;
            } else if (i == id.jpg) {
                filetypeButton.setText("JPG");
                formatsToShow = FormatTypes.jpg;
            } else if (i == id.mp4) {
                filetypeButton.setText("MP4");
                formatsToShow = FormatTypes.mp4;
            }
            //if (savedInstanceFilePath != null)
            viewerActivityInterface.LoadFolder(folderToShow, formatsToShow);

            return false;

        }
    });
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(menu.filetypepopupmenu, popup.getMenu());
    popup.show();
}