Java Code Examples for androidx.appcompat.widget.PopupMenu#setOnMenuItemClickListener()
The following examples show how to use
androidx.appcompat.widget.PopupMenu#setOnMenuItemClickListener() .
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: BasicActivity.java From intra42 with Apache License 2.0 | 6 votes |
private void openThemeBrightnessChoice(View view) { PopupMenu popupMenu = new PopupMenu(this, view, Gravity.END, 0, R.style.MyPopupMenu); popupMenu.inflate(R.menu.menu_change_theme_brightness); popupMenu.setOnMenuItemClickListener(item -> { AppSettings.Theme.EnumBrightness brightness = AppSettings.Theme.getBrightness(BasicActivity.this); switch (item.getItemId()) { case R.id.menu_theme_auth: brightness = AppSettings.Theme.EnumBrightness.SYSTEM; break; case R.id.menu_theme_dark: brightness = AppSettings.Theme.EnumBrightness.DARK; break; case R.id.menu_theme_light: brightness = AppSettings.Theme.EnumBrightness.LIGHT; break; } Analytics.setBrightness(brightness); AppSettings.Theme.setBrightness(BasicActivity.this, brightness); ThemeHelper.setTheme(app); recreate(); return true; }); popupMenu.show(); }
Example 2
Source File: ViewUtils.java From HgLauncher with GNU General Public License v3.0 | 6 votes |
/** * Creates a PopupMenu containing available search provider. * * @param activity Activity where the PopupMenu resides. * @param popupMenu The PopupMenu to populate and show. * @param query Search query to launch when a provider is selected. */ public static void createSearchMenu(final AppCompatActivity activity, PopupMenu popupMenu, final String query) { for (Map.Entry<String, String> provider : PreferenceHelper.getProviderList().entrySet()) { popupMenu.getMenu().add(provider.getKey()); } popupMenu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { Utils.doWebSearch(activity, PreferenceHelper.getProvider(menuItem.getTitle().toString()), query); return true; } }); popupMenu.show(); }
Example 3
Source File: TasksFragment.java From simple-stack with Apache License 2.0 | 6 votes |
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: tasksViewModel.setFiltering(TasksFilterType.ACTIVE_TASKS); break; case R.id.completed: tasksViewModel.setFiltering(TasksFilterType.COMPLETED_TASKS); break; default: tasksViewModel.setFiltering(TasksFilterType.ALL_TASKS); break; } tasksViewModel.reloadTasks(); return true; }); popup.show(); }
Example 4
Source File: PlaylistRecyclerViewAdapter.java From Bop with Apache License 2.0 | 6 votes |
private void openPopUPMenu(ViewHolder holder, View view, String playlist) { PopupMenu popup = new PopupMenu(view.getContext(), holder.more); popup.inflate(R.menu.playlist_options); popup.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.one: deletePlaylist(holder, view, playlist); return true; case R.id.two: editName(holder, view, playlist); return true; case R.id.three: showPlaylist(holder, view, playlist); return true; default: return false; } }); popup.show(); }
Example 5
Source File: MonthlyReportFragment.java From Medicine-Time- with Apache License 2.0 | 6 votes |
@Override public void showFilteringPopUpMenu() { PopupMenu popup = new PopupMenu(getContext(), getActivity().findViewById(R.id.menu_filter)); popup.getMenuInflater().inflate(R.menu.filter_history, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.all: presenter.setFiltering(FilterType.ALL_MEDICINES); break; case R.id.taken: presenter.setFiltering(FilterType.TAKEN_MEDICINES); break; case R.id.ignored: presenter.setFiltering(FilterType.IGNORED_MEDICINES); break; } presenter.loadHistory(true); return true; } }); popup.show(); }
Example 6
Source File: NowPlayingFragment.java From Jockey with Apache License 2.0 | 6 votes |
private void showRepeatMenu() { View anchor = mBinding.getRoot().findViewById(R.id.menu_now_playing_repeat); PopupMenu menu = new PopupMenu(getContext(), anchor, Gravity.END); menu.inflate(R.menu.activity_now_playing_repeat); menu.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.menu_item_repeat_all: changeRepeatMode(MusicPlayer.REPEAT_ALL, R.string.confirm_enable_repeat); return true; case R.id.menu_item_repeat_none: changeRepeatMode(MusicPlayer.REPEAT_NONE, R.string.confirm_disable_repeat); return true; case R.id.menu_item_repeat_one: changeRepeatMode(MusicPlayer.REPEAT_ONE, R.string.confirm_enable_repeat_one); return true; case R.id.menu_item_repeat_multi: showMultiRepeatDialog(); return true; default: return false; } }); menu.show(); }
Example 7
Source File: RecentFragment.java From NewFastFrame with Apache License 2.0 | 6 votes |
public void showPopMenu(View view, int position) { PopupMenu popupMenu = new PopupMenu(getContext(), view); popupMenu.getMenuInflater().inflate(R.menu.item_menu, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(item -> { if (item.getItemId() == R.id.menu_recent_delete) { RecentMessageEntity msg = mAdapter.getData(position); UserDBManager.getInstance().deleteRecentMessage(msg.getId()); mAdapter.removeData(msg); } else { ToastUtils.showShortToast("置顶"); } return true; }); popupMenu.setGravity(Gravity.END); popupMenu.show(); }
Example 8
Source File: SongItemViewModel.java From Jockey with Apache License 2.0 | 5 votes |
public View.OnClickListener onClickMenu() { return v -> { final PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END); menu.inflate(R.menu.instance_song); menu.setOnMenuItemClickListener(onMenuItemClick()); menu.show(); }; }
Example 9
Source File: MotivationAlertTextsAdapter.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 5 votes |
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 10
Source File: ConfigActivity.java From J2ME-Loader with Apache License 2.0 | 5 votes |
private void showScreenPresets(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu(); for (String preset : screenPresets) { menu.add(preset); } popup.setOnMenuItemClickListener(item -> { String string = item.getTitle().toString(); int separator = string.indexOf(" x "); tfScreenWidth.setText(string.substring(0, separator)); tfScreenHeight.setText(string.substring(separator + 3)); return true; }); popup.show(); }
Example 11
Source File: MainActivity.java From ui with Apache License 2.0 | 5 votes |
private void showPopupMenu(View v){ PopupMenu popupM = new PopupMenu(this, v); //note "this" is the activity context, if you are using this in a fragment. using getActivity() 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(); //textview.append("\n you clicked "+item.toString()); return true; } }); popupM.show(); }
Example 12
Source File: ReminderDialogFragment.java From Deadline with GNU General Public License v3.0 | 5 votes |
private void setupPopupMenu() { final PopupMenu popupMenu = new PopupMenu(getActivity(), mBinding.remindIntervalUnit, Gravity.CENTER, 0, android.R.style.Widget_Material_Light_PopupMenu_Overflow); popupMenu.inflate(R.menu.menu_reminder_units); mBinding.remindIntervalUnit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { popupMenu.show(); mViewModel.updateSelections(RemindType.SINGLE_REMIND); } }); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_remind_minutes: mViewModel.singleRemindUnit.set(RemindType.SINGLE_MIN); break; case R.id.action_remind_hours: mViewModel.singleRemindUnit.set(RemindType.SINGLE_HOUR); break; case R.id.action_remind_days: mViewModel.singleRemindUnit.set(RemindType.SINGLE_DAY); break; case R.id.action_remind_weeks: mViewModel.singleRemindUnit.set(RemindType.SINGLE_WEEK); break; } return true; } }); }
Example 13
Source File: MenuViewHolder.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Shows the menu specified with the <code>menuResourceId</code> starting * at the <code>anchor</code> * * @param anchor The view to show the popup menu from * @param menuResourceId The resource id for the menu to show */ protected void showMenu(@NonNull View anchor, @MenuRes int menuResourceId) { PopupMenu menu = new PopupMenu(anchor.getContext(), anchor); MenuInflater inflater = menu.getMenuInflater(); inflater.inflate(menuResourceId, menu.getMenu()); onPreparePopupMenu(menu.getMenu()); menu.setOnMenuItemClickListener(this); menu.show(); }
Example 14
Source File: GenreItemViewModel.java From Jockey with Apache License 2.0 | 5 votes |
public View.OnClickListener onClickMenu() { return v -> { final PopupMenu menu = new PopupMenu(mContext, v, Gravity.END); menu.inflate(R.menu.instance_genre); menu.setOnMenuItemClickListener(onMenuItemClick()); menu.show(); }; }
Example 15
Source File: ReportAdapter.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 5 votes |
public void showPopup(View v, Context c) { PopupMenu popup = new PopupMenu(c, v); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.menu_card_activity_summary, popup.getMenu()); popup.setOnMenuItemClickListener(this); if (mItemClickListener != null) { mItemClickListener.setActivityChartDataTypeChecked(popup.getMenu()); } popup.show(); }
Example 16
Source File: TransactionFragment.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
/** * date: 20/9/18 * author: chenli * description: 先开先平平仓处理逻辑 */ private void firstClosePosition(final View v) { if (mInstrumentIdTransaction != null && mInstrumentIdTransaction.contains("&")) { PopupMenu popupCombine = new PopupMenu(getActivity(), v); popupCombine.getMenuInflater().inflate(R.menu.fragment_transaction, popupCombine.getMenu()); popupCombine.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.bid_position: mDirection = DIRECTION_BUY_ZN; mIsClosePriceShow = true; mBinding.closeDirection.setText(ACTION_CLOSE_BUY); refreshCloseBidPrice(); defaultClosePosition(v); break; case R.id.ask_position: mDirection = DIRECTION_SELL_ZN; mIsClosePriceShow = true; mBinding.closeDirection.setText(ACTION_CLOSE_SELL); refreshCloseAskPrice(); defaultClosePosition(v); break; default: break; } return true; } }); popupCombine.show(); } else { ToastUtils.showToast(BaseApplication.getContext(), "您还没有此合约持仓~"); } }
Example 17
Source File: ChannelFragment.java From RoMote with Apache License 2.0 | 5 votes |
private void showMenu(final View v) { PopupMenu popup = new PopupMenu(getActivity(), v); // This activity implements OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_share: Channel channel = (Channel) v.getTag(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Install this Roku channel (" + channel.getTitle() + "):\n\n" + "http://romote/" + channel.getId() + "\n\n" + "Sent using RoMote."); intent.setType("text/plain"); startActivity(intent); return true; default: return false; } } }); popup.inflate(R.menu.channel_menu); popup.show(); }
Example 18
Source File: PlaylistItemViewModel.java From Jockey with Apache License 2.0 | 5 votes |
public View.OnClickListener onClickMenu() { return v -> { PopupMenu menu = new PopupMenu(mContext, v, Gravity.END); menu.inflate((mPlaylist instanceof AutoPlaylist) ? R.menu.instance_smart_playlist : R.menu.instance_playlist); menu.setOnMenuItemClickListener(onMenuItemClick(v)); menu.show(); }; }
Example 19
Source File: MenuMainDemoFragment.java From material-components-android with Apache License 2.0 | 4 votes |
@SuppressWarnings("RestrictTo") private void showMenu(View v, @MenuRes int menuRes) { PopupMenu popup = new PopupMenu(getContext(), v); // Inflating the Popup using xml file popup.getMenuInflater().inflate(menuRes, popup.getMenu()); // There is no public API to make icons show on menus. // IF you need the icons to show this works however it's discouraged to rely on library only // APIs since they might disappear in future versions. if (popup.getMenu() instanceof MenuBuilder) { MenuBuilder menuBuilder = (MenuBuilder) popup.getMenu(); //noinspection RestrictedApi menuBuilder.setOptionalIconsVisible(true); for (MenuItem item : menuBuilder.getVisibleItems()) { int iconMarginPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, ICON_MARGIN, getResources().getDisplayMetrics()); if (item.getIcon() != null) { if (VERSION.SDK_INT > VERSION_CODES.LOLLIPOP) { item.setIcon(new InsetDrawable(item.getIcon(), iconMarginPx, 0, iconMarginPx, 0)); } else { item.setIcon( new InsetDrawable(item.getIcon(), iconMarginPx, 0, iconMarginPx, 0) { @Override public int getIntrinsicWidth() { return getIntrinsicHeight() + iconMarginPx + iconMarginPx; } }); } } } } popup.setOnMenuItemClickListener( menuItem -> { Snackbar.make( getActivity().findViewById(android.R.id.content), menuItem.getTitle(), Snackbar.LENGTH_LONG) .show(); return true; }); popup.show(); }
Example 20
Source File: ProjectAdapterViewItem.java From PHONK with GNU General Public License v3.0 | 4 votes |
private void showMenu(View fromView) { PopupMenu myPopup = new PopupMenu(c, fromView); myPopup.inflate(R.menu.project_actions); myPopup.setOnMenuItemClickListener(menuItem -> { int itemId = menuItem.getItemId(); switch (itemId) { case R.id.menu_project_list_run: PhonkAppHelper.launchScript(getContext(), mProject); return true; case R.id.menu_project_list_edit: PhonkAppHelper.launchEditor(getContext(), mProject); return true; case R.id.menu_project_webeditor: PhonkAppHelper.openInWebEditor(getContext(), mProject); return true; case R.id.menu_project_list_delete: DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { switch (which) { case DialogInterface.BUTTON_POSITIVE: EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_DELETE, mProject)); MLog.d(TAG, "deleting " + mProject.getFullPath()); Toast.makeText(getContext(), mProject.getName() + " Deleted", Toast.LENGTH_LONG).show(); PhonkScriptHelper.deleteFileOrFolder(mProject.getFullPath()); break; case DialogInterface.BUTTON_NEGATIVE: break; } }; AlertDialog.Builder builder = new AlertDialog.Builder(c); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return true; case R.id.menu_project_list_add_shortcut: PhonkScriptHelper.addShortcut(c, mProject.getFolder(), mProject.getName()); return true; case R.id.menu_project_list_share_with: PhonkScriptHelper.shareMainJsDialog(c, mProject.getFolder(), mProject.getName()); return true; case R.id.menu_project_list_share_proto_file: PhonkScriptHelper.shareProtoFileDialog(c, mProject.getFolder(), mProject.getName()); return true; case R.id.menu_project_list_show_info: PhonkAppHelper.launchScriptInfoActivity(c, mProject); return true; default: return true; } }); myPopup.show(); }