Java Code Examples for android.support.v7.widget.PopupMenu#show()

The following examples show how to use android.support.v7.widget.PopupMenu#show() . 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: TasksFragment.java    From mobius-android-sample with Apache License 2.0 6 votes vote down vote up
private void showFilteringPopUpMenu() {
  PopupMenu popup = new PopupMenu(getContext(), getActivity().findViewById(R.id.menu_filter));
  popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());

  popup.setOnMenuItemClickListener(
      item -> {
        switch (item.getItemId()) {
          case R.id.active:
            onFilterSelected(TasksFilterType.ACTIVE_TASKS);
            break;
          case R.id.completed:
            onFilterSelected(TasksFilterType.COMPLETED_TASKS);
            break;
          default:
            onFilterSelected(TasksFilterType.ALL_TASKS);
            break;
        }
        return true;
      });

  popup.show();
}
 
Example 2
Source File: TasksFragment.java    From AndroidProjects with MIT License 6 votes vote down vote up
@Override
public void showFilteringPopUpMenu() {
    PopupMenu popup = new PopupMenu(getContext(), getActivity().findViewById(R.id.menu_filter));
    popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.active:
                    mPresenter.setFiltering(TasksFilterType.ACTIVE_TASKS);
                    break;
                case R.id.completed:
                    mPresenter.setFiltering(TasksFilterType.COMPLETED_TASKS);
                    break;
                default:
                    mPresenter.setFiltering(TasksFilterType.ALL_TASKS);
                    break;
            }
            mPresenter.loadTasks(false);
            return true;
        }
    });

    popup.show();
}
 
Example 3
Source File: AudioAlbumFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor, position);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example 4
Source File: AppFileListAdapter.java    From AppPlus with MIT License 6 votes vote down vote up
/**
 * 显示弹出式菜单
 * @param entity
 * @param ancho
 */
private void showPopMenu(final AppEntity entity,View ancho) {
    PopupMenu popupMenu = new PopupMenu(mContext,ancho);
    popupMenu.getMenuInflater().inflate(R.menu.item_pop_file_menu,popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if(mClickPopupMenuItem!=null){
                mClickPopupMenuItem.onClickMenuItem(item.getItemId(),entity);
            }
            return false;
        }
    });

    makePopForceShowIcon(popupMenu);
    popupMenu.show();
}
 
Example 5
Source File: CommentViewHolder.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public void showPopup(final Activity activity, View view, final int commentId, String author, boolean showReply) {
    PopupMenu popup = new PopupMenu(view.getContext(), view);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (!AptoideUtils.AccountUtils.isLoggedInOrAsk(activity)) return false;
            if (!(activity instanceof AddCommentVoteCallback)) {
                throw new IllegalStateException("activity is not an instanceof AddCommentVoteCallback");
            }

            final AddCommentVoteCallback voteCallback = (AddCommentVoteCallback) activity;
            int i = item.getItemId();
            if (i == R.id.menu_vote_up) {
                voteCallback.voteComment(commentId, AddApkCommentVoteRequest.CommentVote.up);
                return true;
            } else if (i == R.id.menu_vote_down) {
                voteCallback.voteComment(commentId, AddApkCommentVoteRequest.CommentVote.down);
                return true;
            }
            return false;
        }
    });
    popup.inflate(R.menu.menu_comments);
    popup.show();
    if (!showReply) {
        popup.getMenu().findItem(R.id.menu_reply).setVisible(false);
    }
}
 
Example 6
Source File: MainActivity.java    From Bluefruit_LE_Connect_Android with MIT License 5 votes vote down vote up
public void onClickFilterNameSettings(View view) {
    PopupMenu popup = new PopupMenu(this, view);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            boolean processed = true;
            switch (item.getItemId()) {
                case R.id.scanfilter_name_contains:
                    mPeripheralList.setFilterNameExact(false);
                    break;
                case R.id.scanfilter_name_exact:
                    mPeripheralList.setFilterNameExact(true);
                    break;
                case R.id.scanfilter_name_sensitive:
                    mPeripheralList.setFilterNameCaseInsensitive(false);
                    break;
                case R.id.scanfilter_name_insensitive:
                    mPeripheralList.setFilterNameCaseInsensitive(true);
                    break;
                default:
                    processed = false;
                    break;
            }
            updateFilters();
            return processed;
        }
    });
    MenuInflater inflater = popup.getMenuInflater();
    Menu menu = popup.getMenu();
    inflater.inflate(R.menu.menu_scan_filters_name, menu);
    final boolean isFilterNameExact = mPeripheralList.isFilterNameExact();
    menu.findItem(isFilterNameExact ? R.id.scanfilter_name_exact : R.id.scanfilter_name_contains).setChecked(true);
    final boolean isFilterNameCaseInsensitive = mPeripheralList.isFilterNameCaseInsensitive();
    menu.findItem(isFilterNameCaseInsensitive ? R.id.scanfilter_name_insensitive : R.id.scanfilter_name_sensitive).setChecked(true);
    popup.show();
}
 
Example 7
Source File: CalendarFragment.java    From memoir with Apache License 2.0 5 votes vote down vote up
@Override
public void onLongClicked(View view, int position) {
    final int finalPosition = position - 1;
    final Context context = getContext();
    PopupMenu popupMenu = new PopupMenu(context, view);
    popupMenu.inflate(R.menu.menu_delete);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {

                case R.id.note_delete:
                    new AlertDialog.Builder(context)
                            .setTitle("Delete Note")
                            .setMessage("Are you sure you want to delete the note?")
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    NotesDatabase.getInstance(context).deleteNoteAt(finalPosition);
                                    adapter.notifyItemRemoved(finalPosition);
                                }
                            })
                            .setNegativeButton(android.R.string.no, null)
                            .show();
                    return true;

                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example 8
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public void onAudioSubClick(View anchor){
    final AppCompatActivity context = this;
    PopupMenu popupMenu = new PopupMenu(this, anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audiosub_tracks, popupMenu.getMenu());
    popupMenu.getMenu().findItem(R.id.video_menu_audio_track).setEnabled(mService.getAudioTracksCount() > 0);
    popupMenu.getMenu().findItem(R.id.video_menu_subtitles).setEnabled(mService.getSpuTracksCount() > 0);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.video_menu_audio_track) {
                selectAudioTrack();
                return true;
            } else if (item.getItemId() == R.id.video_menu_subtitles) {
                selectSubtitles();
                return true;
            } else if (item.getItemId() == R.id.video_menu_subtitles_picker) {
                if (mUri == null)
                    return false;
                Intent filePickerIntent = new Intent(context, FilePickerActivity.class);
                if (TextUtils.equals(mUri.getScheme(), "file"))
                    filePickerIntent.setData(Uri.parse(Strings.getParent(mUri.toString())));
                context.startActivityForResult(filePickerIntent, 0);
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}
 
Example 9
Source File: StatusRecyclerAdapter.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v)
{
    PopupMenu popupMenu =  new PopupMenu(activity, v);
    popupMenu.getMenu().add(Menu.NONE, 1, Menu.NONE, R.string.status_more_option_like);
    popupMenu.getMenu().add(Menu.NONE, 2, Menu.NONE, R.string.status_more_option_save);
    popupMenu.getMenu().add(Menu.NONE, 3, Menu.NONE, R.string.status_more_option_delete);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            int pos = getAdapterPosition();
            switch (menuItem.getItemId()) {
                case 1:
                    EventBus.getDefault().post(new UserLikedStatus(statuses.get(pos)));
                    return true;
                case 2:
                    EventBus.getDefault().post(new UserSavedStatus(statuses.get(pos)));
                    return true;
                case 3:
                    EventBus.getDefault().post(new UserDeleteStatus(statuses.get(pos)));
                    return true;
                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example 10
Source File: LayersFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sync:
                for (Account account : mAccounts) {
                    Bundle settingsBundle = new Bundle();
                    settingsBundle.putBoolean(
                            ContentResolver.SYNC_EXTRAS_MANUAL, true);
                    settingsBundle.putBoolean(
                            ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

                    ContentResolver.requestSync(account, AUTHORITY, settingsBundle);
                }

                updateInfo();
                break;
            case R.id.new_layer:
                if (getActivity() != null) {
//                    View view = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
                    View view = getActivity().findViewById(R.id.new_layer);
                    PopupMenu popup = new PopupMenu(getActivity(), view);
                    UiUtil.setForceShowIcon(popup);
                    popup.getMenuInflater().inflate(R.menu.add_layer, popup.getMenu());
                    popup.setOnMenuItemClickListener(this);
                    if (!AccountUtil.isProUser(getActivity())) {
                        popup.getMenu().findItem(R.id.menu_add_ngw).setIcon(R.drawable.ic_lock_black_24dp);
                    }
                    popup.show();
                }

                break;
        }
    }
 
Example 11
Source File: MenuV4.java    From ui with Apache License 2.0 5 votes vote down vote up
private void showPopupMenu(View v){
		PopupMenu popupM = new PopupMenu(this, v);
		popupM.inflate(R.menu.popup);
		popupM.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

			@Override
			public boolean onMenuItemClick(MenuItem item) {
				Toast.makeText(getApplicationContext(), item.toString(),Toast.LENGTH_LONG).show();
				label1.append("\n you clicked "+item.toString());
				return true;
			}
		});

		popupM.show();
}
 
Example 12
Source File: MainActivity.java    From letterpress with Apache License 2.0 5 votes vote down vote up
private void showPopupMenu(View anchorView) {
    PopupMenu popup = new PopupMenu(MainActivity.this, anchorView);
    popup.getMenuInflater().inflate(R.menu.menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            // ...
            return true;
        }
    });

    // Apply custom font to popup menu
    FontUtil.applyTypeface(popup.getMenu(), mTypeface);
    popup.show();
}
 
Example 13
Source File: CodePresenter.java    From open-location-code with Apache License 2.0 5 votes vote down vote up
private void openShareMenu() {
    PopupMenu popup = new PopupMenu(mView.getContext(), mView.getShareButton());
    popup.setOnMenuItemClickListener(this);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.share_menu, popup.getMenu());
    popup.show();
}
 
Example 14
Source File: MotivationAlertTextsAdapter.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
public void showPopup(View v, Context c) {
    PopupMenu popup = new PopupMenu(c, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_card_motivation_text, popup.getMenu());
    popup.setOnMenuItemClickListener(this);
    popup.show();
}
 
Example 15
Source File: DashboardItemAdapter.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onClick(View view) {
    PopupMenu popupMenu = new PopupMenu(mContext, view);

    if (isItemShareable()) {
        popupMenu.getMenu().add(MENU_GROUP_ID,
                MENU_SHARE_ITEM_ID, MENU_SHARE_ITEM_ORDER,
                R.string.share_interpretation);
    }

    if (isDashboardUpdatable()) {
        popupMenu.getMenu().add(MENU_GROUP_ID,
                MENU_DELETE_ITEM_ID, MENU_DELETE_ITEM_ORDER,
                R.string.delete);
    }

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (mListener == null) {
                return false;
            }

            if (menuItem.getItemId() == MENU_SHARE_ITEM_ID) {
                mListener.onItemShareClick(mDashboardItem);
            } else if (menuItem.getItemId() == MENU_DELETE_ITEM_ID) {
                mListener.onItemDeleteClick(mDashboardItem);
            }

            return true;
        }
    });

    popupMenu.show();
}
 
Example 16
Source File: TrainingOverviewAdapter.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
public void showPopup(View v, Context c) {
    PopupMenu popup = new PopupMenu(c, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_card_training_session, popup.getMenu());
    popup.setOnMenuItemClickListener(this);
    popup.show();
}
 
Example 17
Source File: ReminderPickerDialog.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void showDatePicker(View v) {
    PopupMenu popupM = new PopupMenu(Objects.requireNonNull(getContext()), v);
    popupM.inflate(R.menu.date_picker_menu);

    popupM.getMenu().getItem(0).setTitle(String.format(getString(R.string.today_with_date), TimeUtils.getShortDate(getContext(), TimeUtils.today())));
    popupM.getMenu().getItem(1).setTitle(String.format(getString(R.string.tomorrow_with_date), TimeUtils.getShortDate(getContext(), TimeUtils.tomorrow())));
    popupM.getMenu().getItem(2).setTitle(String.format(getString(R.string.this_friday_with_date), TimeUtils.getShortDate(getContext(), TimeUtils.thisFriday())));
    popupM.getMenu().getItem(3).setTitle(String.format(getString(R.string.this_sunday_with_date), TimeUtils.getShortDate(getContext(), TimeUtils.thisSunday())));
    popupM.getMenu().getItem(4).setTitle(String.format(getString(R.string.next_monday_with_date), TimeUtils.getShortDate(getContext(), TimeUtils.nextMonday())));

    popupM.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()){
            case R.id.item_today:
                onDatePicked(TimeUtils.today());
                break;
            case R.id.item_tomorrow:
                onDatePicked(TimeUtils.tomorrow());
                break;
            case R.id.item_this_friday:
                onDatePicked(TimeUtils.thisFriday());
                break;
            case R.id.item_this_sunday:
                onDatePicked(TimeUtils.thisSunday());
                break;
            case R.id.item_next_monday:
                onDatePicked(TimeUtils.nextMonday());
                break;
            case R.id.item_custom:
                showCustomDateDialog();
                return true;
            case R.id.item_clear_date:break; // invisible
        }
        displayAlarmInfo();
        return true;
    });
    popupM.show();
}
 
Example 18
Source File: PrayerFragment.java    From android with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.btn_settings)
void onSettingsButtonClicked() {
    PopupMenu menu = new PopupMenu(getActivity(), mSettingsButton);
    mSettingsButton.setOnTouchListener(menu.getDragToOpenListener());

    menu.inflate(R.menu.menu_main);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });

    menu.show();
}
 
Example 19
Source File: BaseFuncActivity.java    From TimetableView with MIT License 4 votes vote down vote up
/**
 * 显示弹出菜单
 */
public void showPopmenu() {
    PopupMenu popup = new PopupMenu(this, moreButton);
    popup.getMenuInflater().inflate(R.menu.popmenu_base_func, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.top1:
                    addSubject();
                    break;
                case R.id.top2:
                    deleteSubject();
                    break;

                case R.id.top4:
                    hideNonThisWeek();
                    break;
                case R.id.top5:
                    showNonThisWeek();
                    break;
                case R.id.top6:
                    setMaxItem(8);
                    break;
                case R.id.top7:
                    setMaxItem(10);
                    break;
                case R.id.top8:
                    setMaxItem(12);
                    break;
                case R.id.top9:
                    showTime();
                    break;
                case R.id.top10:
                    hideTime();
                    break;
                case R.id.top11:
                    showWeekView();
                    break;
                case R.id.top12:
                    hideWeekView();
                    break;
                case R.id.top13:
                    setMonthWidth();
                    break;
                case R.id.top16:
                    resetMonthWidth();
                    break;
                case R.id.top14:
                    hideWeekends();
                    break;
                case R.id.top15:
                    showWeekends();
                    break;
                default:
                    break;
            }
            return true;
        }
    });

    popup.show();
}
 
Example 20
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 4 votes vote down vote up
public void showPopupMenu(View view) {
    PopupMenu popupMenu = new PopupMenu(MainActivity.this,view);
    popupMenu.inflate(R.menu.menu_popup);
    popupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
    popupMenu.show();
}