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:com.cyanogenmod.eleven.ui.HeaderBar.java

public void showPopupMenu() {
    // create the popup menu
    if (mPopupMenu == null) {
        mPopupMenu = new PopupMenu(mFragment.getActivity(), mMenuButton);
        mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override/*  w w w. j  a  v a 2  s. c  o  m*/
            public boolean onMenuItemClick(MenuItem item) {
                return onPopupMenuItemClick(item);
            }
        });
    }

    final Menu menu = mPopupMenu.getMenu();
    final MenuInflater inflater = mPopupMenu.getMenuInflater();

    menu.clear();

    // Shuffle all
    inflater.inflate(R.menu.shuffle_all, menu);
    if (MusicUtils.getQueueSize() > 0) {
        // save queue/clear queue
        inflater.inflate(R.menu.queue, menu);
    }
    // Settings
    inflater.inflate(R.menu.activity_base, menu);

    // show the popup
    mPopupMenu.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.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.apache.cordova.navigationmenu.NavigationMenu.java

/**
 * Displays popup menu.//from  www .ja  v  a2s.com
 *
 * @param items   The array of objects which describes menu items.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void showPopup(JSONArray items) {
    final PopupMenu popup = new PopupMenu(this.webView.getContext(), this.webView);

    PopupMenu.OnMenuItemClickListener handler = new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            int itemId = item.getItemId();
            webView.sendJavascript("menu.popupItemClick && menu.popupItemClick(" + itemId + ");");
            return false;
        }
    };
    popup.setOnMenuItemClickListener(handler);
    Menu popupMenu = popup.getMenu();
    for (int i = 0; i < items.length(); i++) {
        JSONObject menuItem = items.optJSONObject(i);
        if (menuItem != null) {
            appendItem(popupMenu, menuItem);
        }
    }

    this.cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            popup.show();
        }
    });

}

From source file:in.tanjo.sushi.MainActivity.java

private void updateMainAdapter() {
    MainAdapter mainAdapter = new MainAdapter(mNoteManager.getActiveNote().getSushis());
    mainAdapter.setOnRecyclerViewAdapterItemClickListener(
            new OnRecyclerViewAdapterItemClickListener<CountableSushi>() {
                @Override/*w ww.ja v a2 s  .c o m*/
                public void onItemClick(View v, RecyclerView.Adapter adapter, int position,
                        CountableSushi model) {
                    model.setCount(model.getCount() + 1);
                    changeItem(position, model);
                }

                @Override
                public void onItemLongClick(View v, RecyclerView.Adapter adapter, final int position,
                        final CountableSushi model) {
                    PopupMenu popupMenu = new PopupMenu(MainActivity.this, v);
                    popupMenu.getMenuInflater().inflate(R.menu.popup_countable_sushi_model_menu,
                            popupMenu.getMenu());
                    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                            case R.id.popup_menu_sushi_delete:
                                removeItem(position, model);
                                snackbar(model.getName() + "????");
                                break;
                            case R.id.popup_menu_sushi_plus1:
                                model.setCount(model.getCount() + 1);
                                changeItem(position, model);
                                break;
                            case R.id.popup_menu_sushi_minus1:
                                if (model.getCount() - 1 >= 0) {
                                    model.setCount(model.getCount() - 1);
                                }
                                changeItem(position, model);
                                break;
                            }
                            return true;
                        }
                    });
                    popupMenu.show();
                }
            });
    mMainRecyclerView.setAdapter(mainAdapter);
}

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 a2 s  .co  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());
}

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);//  ww  w  .j  av  a  2  s.c o 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:com.google.reviewit.PagedChangeDetailsFragment.java

private void init() {
    final Change change = getApp().getQueryHandler().getCurrentChange();
    checkArgument(change != null, "No change to display");

    ChangeEntry changeEntry = new ChangeEntry(getContext());
    changeEntry.init(getApp(), change);// w ww .  j  a  va  2  s  . c o  m
    vg(R.id.changeHeader).addView(changeEntry);

    final List<PageFragment> fragments = new ArrayList<>();

    CommitMessageFragment commitMessageFragment = new CommitMessageFragment();
    commitMessageFragment.setChange(change);
    fragments.add(commitMessageFragment);

    FileListFragment fileListFragment = new FileListFragment();
    fileListFragment.setChange(change);
    fragments.add(fileListFragment);

    ApprovalsFragment approvalsFragment = new ApprovalsFragment();
    approvalsFragment.setChange(change);
    fragments.add(approvalsFragment);

    ReplyFragment replyFragment = new ReplyFragment();
    replyFragment.setChange(change);
    fragments.add(replyFragment);

    // TODO add more tabs, e.g. for change messages

    ViewPager pager = ((ViewPager) v(R.id.pager));
    pager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return getString(fragments.get(position).getTitle());
        }
    });

    SlidingTabLayout tabs = ((SlidingTabLayout) v(R.id.tabs));
    tabs.setTextColor(widgetUtil.color(R.color.tab));
    tabs.setSelectedIndicatorColors(widgetUtil.color(R.color.tab));
    tabs.setBorderColor(widgetUtil.color(R.color.tab));
    tabs.setDividerColors(widgetUtil.color(R.color.tabDivider));
    tabs.setBottomBorderThickness(widgetUtil.dpToPx(1));
    tabs.setSelectedIndicatorThickness(widgetUtil.dpToPx(5));
    tabs.setViewPager(pager);

    final View more = v(R.id.more);
    more.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(getContext(), more);
            popup.getMenuInflater().inflate(R.menu.menu_paged_change_details, popup.getMenu());

            popup.getMenu().findItem(R.id.action_abandon).setVisible(
                    change.info.status == ChangeStatus.NEW || change.info.status == ChangeStatus.SUBMITTED);
            popup.getMenu().findItem(R.id.action_restore)
                    .setVisible(change.info.status == ChangeStatus.ABANDONED);

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_abandon:
                        display(AbandonFragment.create(PagedChangeDetailsFragment.class));
                        return true;
                    case R.id.action_restore:
                        display(RestoreFragment.create(PagedChangeDetailsFragment.class));
                        return true;
                    default:
                        return true;
                    }
                }
            });
            popup.show();
        }
    });
}

From source file:org.alfresco.mobile.android.application.fragments.site.browser.SiteAdapter.java

@Override
protected void updateTopText(TwoLinesViewHolder vh, Site item) {
    super.updateTopText(vh, item);

    if (mode == ListingModeFragment.MODE_IMPORT || mode == ListingModeFragment.MODE_PICK) {
        UIUtils.setBackground(vh.choose, null);
        return;//w  w  w  .  j a va2 s . co  m
    }

    vh.choose.setImageResource(R.drawable.ic_more_options);
    vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light);
    int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16);
    vh.choose.setPadding(d_16, d_16, d_16, d_16);
    vh.choose.setVisibility(View.VISIBLE);
    AccessibilityUtils.addContentDescription(vh.choose,
            String.format(getContext().getString(R.string.more_options_site), item.getTitle()));
    vh.choose.setTag(R.id.site_action, item);
    vh.choose.setOnClickListener(new OnClickListener() {

        @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        @Override
        public void onClick(View v) {
            Site item = (Site) v.getTag(R.id.site_action);
            selectedOptionItems.add(item);
            PopupMenu popup = new PopupMenu(getContext(), v);
            getMenu(popup.getMenu(), item);

            popup.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    selectedOptionItems.clear();
                }
            });

            popup.setOnMenuItemClickListener(SiteAdapter.this);

            popup.show();
        }
    });
}

From source file:at.ac.uniklu.mobile.sportal.DashboardActivity.java

@TargetApi(11)
@Override// w  w  w  .ja  v  a  2  s  .c o  m
public void openOptionsMenu() {
    // Honeycomb and ICS tablet menu workaround
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        /* Android >= 3 with holo theme doesn't support the options menu, so 
         * display a popup menu below the overflow action button. */
        PopupMenu m = new PopupMenu(this, findViewById(R.id.actionbar_overflow));
        m.getMenuInflater().inflate(R.menu.dashboard_menu, m.getMenu());
        m.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                return onOptionsItemSelected(item);
            }
        });
        m.show();
    } else {
        // show default options menu on Android 2.x
        super.openOptionsMenu();
    }
}

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 ww.  j  a  v a2  s.  c om

    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());
}