Example usage for android.widget PopupMenu PopupMenu

List of usage examples for android.widget PopupMenu PopupMenu

Introduction

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

Prototype

public PopupMenu(Context context, View anchor) 

Source Link

Document

Constructor to create a new popup menu with an anchor view.

Usage

From source file:systems.soapbox.ombuds.client.ui.BlockListFragment.java

@Override
public void onBlockMenuClick(final View view, final StoredBlock block) {
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.blocks_context);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*  w  w w. j  av a 2s.co m*/
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.blocks_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(config.getBlockExplorer(),
                        "block/" + block.getHeader().getHashAsString())));
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}

From source file:org.catnut.adapter.TweetAdapter.java

private void showPopupMenu(View view) {
    final Bean bean = (Bean) view.getTag();
    PopupMenu popup = new PopupMenu(mContext, view);
    Menu menu = popup.getMenu();//  w  w w.  j  a v a  2 s  . c om
    popup.getMenuInflater().inflate(R.menu.tweet_overflow, menu);
    MenuItem item = menu.findItem(R.id.action_favorite);
    item.setTitle(bean.favorited ? R.string.cancle_favorite : R.string.favorite);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_favorite:
                mRequestQueue.add(new CatnutRequest(mContext,
                        bean.favorited ? FavoritesAPI.destroy(bean.id) : FavoritesAPI.create(bean.id),
                        new StatusProcessor.FavoriteTweetProcessor(), new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                Toast.makeText(mContext, bean.favorited ? R.string.cancle_favorite_success
                                        : R.string.favorite_success, Toast.LENGTH_SHORT).show();
                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error);
                                Toast.makeText(mContext, weiboAPIError.error, Toast.LENGTH_LONG).show();
                            }
                        }));
                break;
            case R.id.action_like:
                Toast.makeText(mContext, "sina not provide this option...", Toast.LENGTH_SHORT).show();
                break;
            case android.R.id.copy:
                CatnutUtils.copy2ClipBoard(mContext, mContext.getString(R.string.tweet), bean.text,
                        mContext.getString(R.string.tweet_text_copied));
                break;
            default:
                break;
            }
            return false;
        }
    });
    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//  ww w .j  a  v a 2s  . c  o  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.aman.stockcalculator.Calculator.java

private PopupMenu constructPopupMenu() {
    final PopupMenu popupMenu = new PopupMenu(this, mOverflowMenuButton);
    final Menu menu = popupMenu.getMenu();
    popupMenu.inflate(R.menu.menu);//ww w . jav  a 2 s .  c  o m
    popupMenu.setOnMenuItemClickListener(this);
    onPrepareOptionsMenu(menu);
    return popupMenu;
}

From source file:org.hawkular.client.android.fragment.TriggersFragment.java

private void showTriggerMenu(final View triggerView, final int triggerPosition) {
    PopupMenu triggerMenu = new PopupMenu(getActivity(), triggerView);

    triggerMenu.getMenuInflater().inflate(R.menu.popup_add, triggerMenu.getMenu());

    triggerMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from  w ww.  j  a v a 2  s.c  o  m
        public boolean onMenuItemClick(MenuItem menuItem) {
            Trigger trigger = getTriggersAdapter().getItem(triggerPosition);

            switch (menuItem.getItemId()) {
            case R.id.menu_add:
                Context context = getActivity();
                SQLStore<Trigger> store = openStore(context);
                store.openSync();
                store.save(trigger);
                onRefresh();
                return true;

            default:
                return false;
            }
        }
    });

    triggerMenu.show();
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    this.mImageThumbSize = getResources().getDimensionPixelSize(dimen.image_thumbnail_size);
    viewerActivityInterface = (ActivityInterface) getActivity();
    executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);

    ImageButton gobackButton = (ImageButton) view.findViewById(id.button_goback);
    gobackButton.setOnClickListener(onGobBackClick);

    filetypeButton = (Button) view.findViewById(id.button_filetype);
    filetypeButton.setOnClickListener(new OnClickListener() {
        @Override/*from   w w  w.  j  a v a 2  s . c  o m*/
        public void onClick(View v) {
            showFileSelectionPopup(v);
        }
    });

    filesSelected = (TextView) view.findViewById(id.textView_filesSelected);

    optionsButton = (Button) view.findViewById(id.button_options);
    optionsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(getContext(), v);

            popup.getMenu().add(0, 0, 0, "Delete File");
            if (!isRootDir && VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN_MR2)
                popup.getMenu().add(0, 1, 1, "StackJpeg");
            if (!isRootDir)
                popup.getMenu().add(0, 2, 2, "Raw to Dng");
            if (!isRootDir)
                popup.getMenu().add(0, 3, 3, "DngStack");
            popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case 0:
                        onDeltedButtonClick.onClick(null);
                        break;
                    case 1:
                        onStackClick.onClick(null);
                        break;
                    case 2:
                        onRawToDngClick.onClick(null);
                        break;
                    case 3:
                        onDngStackClick.onClick(null);
                    }
                    return false;
                }
            });
            popup.show();
        }
    });

    doActionButton = (Button) view.findViewById(id.button_DoAction);
    doActionButton.setVisibility(View.GONE);
    firstload();

    return view;
}

From source file:com.tcity.android.ui.overview.project.ProjectOverviewActivity.java

void buildConfigurationOptionsClick(@NotNull String id, @NotNull View anchor) {
    PopupMenu menu = new PopupMenu(this, anchor);

    menu.inflate(R.menu.menu_concept);//from w  w w  .ja v a 2 s.  c om

    menu.setOnMenuItemClickListener(
            new PopupMenuListener(WebLocator.getBuildConfigurationUrl(id, new Preferences(this))));

    menu.show();
}

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);/*from ww  w.  j a  v  a  2  s.com*/

        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:com.owncloud.android.ui.trashbin.TrashbinActivity.java

@Override
public void onOverflowIconClicked(TrashbinFile file, View view) {
    PopupMenu popup = new PopupMenu(this, view);
    popup.inflate(R.menu.trashbin_actions_menu);

    popup.setOnMenuItemClickListener(item -> {
        trashbinPresenter.removeTrashbinFile(file);

        return true;
    });/*w  w  w. java  2 s.  c o  m*/
    popup.show();
}

From source file:net.sf.golly.SettingsActivity.java

public void doPasteMode(View view) {
    // display pop-up menu with these items: AND, COPY, OR, XOR
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.pastemode_menu, popup.getMenu());
    popup.show();//ww w  . j  a  v a 2s.  c  om
}