Java Code Examples for android.widget.PopupMenu#OnMenuItemClickListener

The following examples show how to use android.widget.PopupMenu#OnMenuItemClickListener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TraitAdapter.java    From Field-Book with GNU General Public License v2.0 6 votes vote down vote up
private PopupMenu.OnMenuItemClickListener createTraitListListener(
        final ViewGroup parent, final ViewHolder holder,
        final View v, final int position) {
    return new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getTitle().equals(TraitEditorActivity.thisActivity.getString(R.string.traits_options_copy))) {
                copyTrait(position);
            } else if (item.getTitle().equals(TraitEditorActivity.thisActivity.getString(R.string.traits_options_delete))) {
                deleteTrait(holder);
            } else if (item.getTitle().equals(TraitEditorActivity.thisActivity.getString(R.string.traits_options_edit))) {
                listener.onItemClick((AdapterView) parent, v, position, v.getId());
            }

            return false;
        }
    };
}
 
Example 2
Source File: FieldAdapter.java    From Field-Book with GNU General Public License v2.0 6 votes vote down vote up
private PopupMenu.OnMenuItemClickListener makeSelectMenuListener(final int position) {
    return new PopupMenu.OnMenuItemClickListener() {
        // Do it when selecting Delete or Statistics
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final Activity thisActivity = FieldEditorActivity.thisActivity;
            final String strDel = thisActivity.getString(R.string.fields_delete);

            if (item.getTitle().equals(strDel)) {
                AlertDialog alert = createDeleteItemAlertDialog(position);
                alert.show();
                DialogUtils.styleDialogs(alert);
            }

            return false;
        }
    };
}
 
Example 3
Source File: SearchBox.java    From WeGit with Apache License 2.0 4 votes vote down vote up
public void setOverflowMenuItemClickListener(PopupMenu.OnMenuItemClickListener onMenuItemClickListener) {
    popupMenu.setOnMenuItemClickListener(onMenuItemClickListener);
}
 
Example 4
Source File: PanelMenuFragment.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
    PopupMenu.OnMenuItemClickListener listener = (PopupMenu.OnMenuItemClickListener) getActivity();
    mFragmentHolder.popCurrent();
    listener.onMenuItemClick(mMenuItems.get(position));
}
 
Example 5
Source File: Settings.java    From Hangar with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final AppsRowItem rowItem = (AppsRowItem) parent.getItemAtPosition(position);

    PopupMenu popup = new PopupMenu(mContext, view);
    popup.getMenuInflater().inflate(R.menu.app_action, popup.getMenu());
    MenuItem pinItem = popup.getMenu().getItem(0);

    if (rowItem.getPinned()) pinItem.setTitle(R.string.action_unpin);
    PopupMenu.OnMenuItemClickListener menuAction = new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            db = TasksDataSource.getInstance(mContext);
            db.open();

            switch (item.getItemId()) {
                case R.id.action_pin:
                    Boolean isPinned = rowItem.getPinned();
                    rowItem.setPinned(!isPinned);
                    new Tools().togglePinned(mContext, rowItem.getPackageName(), prefs.editorGet());
                    break;
                case R.id.action_pick_icon:
                    mIconTask = rowItem;
                    pickIcon(mInstance, rowItem);
                    return true;
                case R.id.action_blacklist:
                    Boolean isBlackListed = rowItem.getBlacklisted();
                    rowItem.setBlacklisted(!isBlackListed);
                    db.blacklistTask(rowItem, !isBlackListed);
                    db.close();
                    break;
                case R.id.action_reset_stats:
                    rowItem.setStats(null);
                    rowItem.setBarContWidth(0);
                    db.resetTaskStats(rowItem);
                    db.close();
                    break;
            }
            lv.invalidateViews();
            myService.execute(SERVICE_BUILD_REORDER_LAUNCH);
            return true;
        }
    };
    popup.setOnMenuItemClickListener(menuAction);
    popup.show();
}