Java Code Examples for androidx.appcompat.widget.PopupMenu#show()
The following examples show how to use
androidx.appcompat.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: TVShowProgressFragment.java From Kore with Apache License 2.0 | 6 votes |
@Override public void onClick(final View v) { final PlaylistType.Item playListItem = new PlaylistType.Item(); playListItem.episodeid = (int)v.getTag(); final PopupMenu popupMenu = new PopupMenu(getActivity(), v); popupMenu.getMenuInflater().inflate(R.menu.musiclist_item, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_play: MediaPlayerUtils.play(TVShowProgressFragment.this, playListItem); return true; case R.id.action_queue: MediaPlayerUtils.queue(TVShowProgressFragment.this, playListItem, PlaylistType.GetPlaylistsReturnType.VIDEO); return true; } return false; } }); popupMenu.show(); }
Example 2
Source File: ConversationFragment.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
private boolean showBlockSubmenu(View view) { final Jid jid = conversation.getJid(); final boolean showReject = !conversation.isWithStranger() && conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); PopupMenu popupMenu = new PopupMenu(getActivity(), view); popupMenu.inflate(R.menu.block); popupMenu.getMenu().findItem(R.id.block_contact).setVisible(jid.getLocal() != null); popupMenu.getMenu().findItem(R.id.reject).setVisible(showReject); popupMenu.setOnMenuItemClickListener(menuItem -> { Blockable blockable; switch (menuItem.getItemId()) { case R.id.reject: activity.xmppConnectionService.stopPresenceUpdatesTo(conversation.getContact()); updateSnackBar(conversation); return true; case R.id.block_domain: blockable = conversation.getAccount().getRoster().getContact(jid.getDomain()); break; default: blockable = conversation; } BlockContactDialog.show(activity, blockable); return true; }); popupMenu.show(); return true; }
Example 3
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 4
Source File: CategoryOptionPopUp.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void show(Context context, View anchor) { PopupMenu menu = new PopupMenu(context, anchor); menu.setOnMenuItemClickListener(item -> { if (item.getOrder() == 0) { listener.onCategoryOptionClick(null); } else { listener.onCategoryOptionClick(options.get(item.getOrder() - 1)); } return false; }); menu.getMenu().add(Menu.NONE, Menu.NONE, 0, category != null ? category.displayName() : categoryName); for (CategoryOption option : options) { if(date == null || ((option.startDate() == null || date.after(option.startDate())) && (option.endDate() == null || date.before(option.endDate())))) menu.getMenu().add(Menu.NONE, Menu.NONE, options.indexOf(option) + 1, option.displayName()); } menu.show(); }
Example 5
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 6
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 7
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 8
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 9
Source File: ThemePreferencesManager.java From material-components-android with Apache License 2.0 | 5 votes |
@SuppressWarnings("RestrictTo") public void showChooseThemePopup(View anchor) { PopupMenu popupMenu = new PopupMenu(context, anchor); popupMenu.inflate(R.menu.mtrl_choose_theme_menu); if (popupMenu.getMenu() instanceof MenuBuilder) { MenuBuilder menuBuilder = (MenuBuilder) popupMenu.getMenu(); menuBuilder.setOptionalIconsVisible(true); ColorStateList defaultColor = AppCompatResources.getColorStateList( context, R.color.material_on_surface_emphasis_medium); int selectedColor = MaterialColors.getColor(anchor, resourceProvider.getPrimaryColor()); int currentThemeId = getCurrentThemeId(); for (int i = 0; i < menuBuilder.size(); i++) { MenuItem item = menuBuilder.getItem(i); if (item.getItemId() == currentThemeId) { DrawableCompat.setTint(item.getIcon(), selectedColor); SpannableString s = new SpannableString(item.getTitle()); s.setSpan(new ForegroundColorSpan(selectedColor), 0, s.length(), 0); item.setTitle(s); } else { DrawableCompat.setTintList(item.getIcon(), defaultColor); } } } popupMenu.setOnMenuItemClickListener( item -> { saveAndApplyTheme(item.getItemId()); return false; }); popupMenu.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: 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 12
Source File: NowPlayingControllerViewModel.java From Jockey with Apache License 2.0 | 5 votes |
public View.OnClickListener onMoreInfoClick() { return v -> { if (mSong == null) { return; } PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END); menu.inflate(mSong.isInLibrary() ? R.menu.instance_song_now_playing : R.menu.instance_song_now_playing_remote); menu.setOnMenuItemClickListener(onMoreInfoItemClick(mSong)); menu.show(); }; }
Example 13
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 14
Source File: BackupManageAppFragment.java From SAI with GNU General Public License v3.0 | 5 votes |
private void showMenu(View anchor) { PopupMenu popupMenu = new PopupMenu(requireContext(), anchor); popupMenu.getMenuInflater().inflate(R.menu.app_details, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener((menuItem) -> { switch (menuItem.getItemId()) { case R.id.menu_backup_open_app_in_system_settings: openAppInSystemSettings(); break; } return true; }); popupMenu.show(); }
Example 15
Source File: CommonUtils.java From CommonUtils with Apache License 2.0 | 5 votes |
public static void showPopupOffset(@NonNull PopupMenu menu, int xoff, int yoff) { try { Field field = menu.getClass().getDeclaredField("mPopup"); field.setAccessible(true); MenuPopupHelper helper = (MenuPopupHelper) field.get(menu); if (helper == null) throw new IllegalStateException(); Method method; try { method = helper.getClass().getDeclaredMethod("show", int.class, int.class); method.setAccessible(true); } catch (NoSuchMethodException ex) { try { method = helper.getClass().getDeclaredMethod("tryShow", int.class, int.class); method.setAccessible(true); } catch (NoSuchMethodException exx) { menu.show(); return; } } method.invoke(helper, xoff, yoff); } catch (NoSuchFieldException | IllegalAccessException | InvocationTargetException ignored) { menu.show(); } }
Example 16
Source File: PlayingNowList.java From Bop with Apache License 2.0 | 5 votes |
public void playlistOptions(View view) { PopupMenu popup = new PopupMenu(view.getContext(), view); popup.inflate(R.menu.current_playlist_options); popup.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.one: showPlaylistDialog(); default: return false; } }); popup.show(); }
Example 17
Source File: FileManagerFragment.java From PHONK with GNU General Public License v3.0 | 4 votes |
public void showMenuForItem(View fromView, final int index) { File file = new File(mCurrentFileList.get(index).path); PopupMenu myPopup = new PopupMenu(getContext(), fromView); myPopup.inflate(R.menu.filemanager_actions); myPopup.setOnMenuItemClickListener(menuItem -> { switch (menuItem.getItemId()) { case R.id.filemanager_action_open: return true; case R.id.filemanager_action_open_with: viewFile(index); return true; case R.id.filemanager_action_copy: return true; case R.id.filemanager_action_cut: return true; case R.id.filemanager_action_delete: DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { switch (which) { case DialogInterface.BUTTON_POSITIVE: deleteFile(index); break; case DialogInterface.BUTTON_NEGATIVE: break; } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return true; default: return false; } }); myPopup.show(); }
Example 18
Source File: ProjectItem.java From PHONK with GNU General Public License v3.0 | 4 votes |
private void showMenu(View fromView) { Context wrapper = new ContextThemeWrapper(mContext, R.style.phonk_PopupMenu); PopupMenu myPopup = new PopupMenu(wrapper, fromView); myPopup.inflate(R.menu.project_actions); myPopup.setOnMenuItemClickListener(menuItem -> { int itemId = menuItem.getItemId(); switch (itemId) { case R.id.menu_project_list_run: // EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_RUN, mProject)); PhonkAppHelper.launchScript(getContext(), mProject); return true; case R.id.menu_project_list_edit: PhonkAppHelper.launchEditor(getContext(), mProject); // EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_EDIT, 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)); //mPlf.removeItem(mProject); 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(mContext); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return true; case R.id.menu_project_list_add_shortcut: PhonkScriptHelper.addShortcut(mContext, mProject.getFolder(), mProject.getName()); return true; case R.id.menu_project_list_share_with: PhonkScriptHelper.shareMainJsDialog(mContext, mProject.getFolder(), mProject.getName()); return true; case R.id.menu_project_list_share_proto_file: PhonkScriptHelper.shareProtoFileDialog(mContext, mProject.getFolder(), mProject.getName()); return true; case R.id.menu_project_list_show_info: PhonkAppHelper.launchScriptInfoActivity(mContext, mProject); return true; default: return true; } }); myPopup.show(); }
Example 19
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(); }
Example 20
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(); }