Java Code Examples for android.widget.PopupMenu#getMenu()
The following examples show how to use
android.widget.PopupMenu#getMenu() .
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: SettingsDialog.java From xposed-aweme with Apache License 2.0 | 6 votes |
/** * 显示更多菜单 */ private void showMoreMenu() { PopupMenu popupMenu = new PopupMenu(getApplicationContext(), mMoreButton, Gravity.RIGHT); Menu menu = popupMenu.getMenu(); menu.add(1, 1, 1, "关于"); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // 显示关于 DialogUtil.showAboutDialog(getContext()); return true; } }); popupMenu.show(); }
Example 2
Source File: PlayerActivity.java From Exoplayer_VLC with Apache License 2.0 | 6 votes |
public void showAudioPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu(); menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio); final MenuItem backgroundAudioItem = menu.findItem(0); backgroundAudioItem.setCheckable(true); backgroundAudioItem.setChecked(enableBackgroundAudio); OnMenuItemClickListener clickListener = new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item == backgroundAudioItem) { enableBackgroundAudio = !item.isChecked(); return true; } return false; } }; configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO); popup.show(); }
Example 3
Source File: FloatingActionMode.java From Telegram with GNU General Public License v2.0 | 6 votes |
public FloatingActionMode(Context context, ActionMode.Callback2 callback, View originatingView, FloatingToolbar floatingToolbar) { mContext = context; mCallback = callback; PopupMenu p = new PopupMenu(context, null); mMenu = p.getMenu(); setType(ActionMode.TYPE_FLOATING); p.setOnMenuItemClickListener(menuItem -> mCallback.onActionItemClicked(FloatingActionMode.this, menuItem)); mContentRect = new Rect(); mContentRectOnScreen = new Rect(); mPreviousContentRectOnScreen = new Rect(); mViewPositionOnScreen = new int[2]; mPreviousViewPositionOnScreen = new int[2]; mRootViewPositionOnScreen = new int[2]; mViewRectOnScreen = new Rect(); mPreviousViewRectOnScreen = new Rect(); mScreenRect = new Rect(); mOriginatingView = originatingView; mOriginatingView.getLocationOnScreen(mViewPositionOnScreen); mBottomAllowance = AndroidUtilities.dp(20); mDisplaySize = new Point(); setFloatingToolbar(floatingToolbar); }
Example 4
Source File: PlayerActivity.java From Android-Example-HLS-ExoPlayer with Apache License 2.0 | 6 votes |
public void showVerboseLogPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu(); menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal); menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose); menu.setGroupCheckable(Menu.NONE, true, true); menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true); popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == 0) { VerboseLogUtil.setEnableAllTags(false); } else { VerboseLogUtil.setEnableAllTags(true); } return true; } }); popup.show(); }
Example 5
Source File: PlayerActivity.java From Android-Example-HLS-ExoPlayer with Apache License 2.0 | 6 votes |
public void showAudioPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu(); menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio); final MenuItem backgroundAudioItem = menu.findItem(0); backgroundAudioItem.setCheckable(true); backgroundAudioItem.setChecked(enableBackgroundAudio); OnMenuItemClickListener clickListener = new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item == backgroundAudioItem) { enableBackgroundAudio = !item.isChecked(); return true; } return false; } }; configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO); popup.show(); }
Example 6
Source File: AlbumsRecyclerAdapter.java From PainlessMusicPlayer with Apache License 2.0 | 6 votes |
private void onMenuClick(@NonNull final View btnView, final int position) { final PopupMenu popup = new PopupMenu(btnView.getContext(), btnView); final Menu popupMenu = popup.getMenu(); final MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.list_item_album, popupMenu); final long id = getItemId(position); final Cursor item = getCursor(); if (item != null && item.moveToPosition(position)) { final String albumName = item.getString(AlbumsProviderKt.COLUMN_ALBUM); popup.setOnMenuItemClickListener(menuItem -> onMenuItemClick(menuItem, id, albumName)); popup.show(); } }
Example 7
Source File: StoryListActivity.java From scanvine-android with MIT License | 6 votes |
public void openTimePopup() { final String[] times = {"Firehose","Latest","Last Day","Last Week","Last Month"}; final String[] timeKeys = {"Firehose","Latest","Last1","Last7","Last30"}; PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_time)); Menu menu = popupMenu.getMenu(); for (int i=0; i<times.length; i++) { boolean addCheck = currentTime!=null && currentTime.equalsIgnoreCase(timeKeys[i]); menu.add(Menu.NONE, i, Menu.NONE, addCheck ? times[i]+"✓" : times[i]); } popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { currentTime = timeKeys[item.getItemId()]; StoryListFragment slf = (StoryListFragment) getSupportFragmentManager().findFragmentById(R.id.story_list); slf.refreshList(currentTime, currentSection, getSourceSlug()); return false; } }); popupMenu.show(); }
Example 8
Source File: StoryListActivity.java From scanvine-android with MIT License | 6 votes |
public void openSectionsPopup() { final String[] sections = {"All","World","Tech","Business","Entertainment","Sports","Life"}; PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section)); Menu menu = popupMenu.getMenu(); for (int i=0; i<sections.length; i++) { boolean addCheck = sections[i].equalsIgnoreCase(currentSection) || currentSection==null && i==0; menu.add(Menu.NONE, i, Menu.NONE, addCheck ? sections[i]+"✓" : sections[i]); } popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { currentSection = item.getItemId()==0 ? null : (""+item.getTitle()).replace("✓",""); StoryListFragment slf = (StoryListFragment) getSupportFragmentManager().findFragmentById(R.id.story_list); slf.refreshList(currentTime, currentSection, getSourceSlug()); return false; } }); popupMenu.show(); }
Example 9
Source File: SectionAdapter.java From Popeens-DSub with GNU General Public License v3.0 | 6 votes |
private void postBindView(UpdateView updateView, T item) { if(updateView.isCheckable()) { setChecked(updateView, selected.contains(item)); } View moreButton = updateView.findViewById(R.id.item_more); if(moreButton != null) { if(onItemClickedListener != null) { PopupMenu popup = new PopupMenu(context, moreButton); Menu menu = popup.getMenu(); onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item); if (menu.size() == 0) { moreButton.setVisibility(View.GONE); } else { moreButton.setVisibility(View.VISIBLE); } } else { moreButton.setVisibility(View.VISIBLE); } } }
Example 10
Source File: SectionAdapter.java From Audinaut with GNU General Public License v3.0 | 6 votes |
private void postBindView(UpdateView updateView, T item) { if (updateView.isCheckable()) { setChecked(updateView, selected.contains(item)); } View moreButton = updateView.findViewById(R.id.item_more); if (moreButton != null) { if (onItemClickedListener != null) { PopupMenu popup = new PopupMenu(context, moreButton); Menu menu = popup.getMenu(); onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item); if (menu.size() == 0) { moreButton.setVisibility(View.GONE); } else { moreButton.setVisibility(View.VISIBLE); } } else { moreButton.setVisibility(View.VISIBLE); } } }
Example 11
Source File: SourceListActivity.java From scanvine-android with MIT License | 6 votes |
public void openSectionPopup() { final String[] sections = {"All","World","Tech","Business","Entertainment","Sports","Life"}; PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section)); Menu menu = popupMenu.getMenu(); for (int i=0; i<sections.length; i++) { boolean addCheck = currentSection!=null && (currentSection.equalsIgnoreCase(sections[i]) || currentSection.length()==0 && "All".equalsIgnoreCase(sections[i])); menu.add(Menu.NONE, i, Menu.NONE, addCheck ? sections[i]+"✓" : sections[i]); } popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { currentSection = item.getItemId()==0 ? null : (""+item.getTitle()).replace("✓",""); SourceListFragment slf = (SourceListFragment) getSupportFragmentManager().findFragmentById(R.id.source_list); slf.refreshList(currentSection); return false; } }); popupMenu.show(); }
Example 12
Source File: FloatingActionMode.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public FloatingActionMode(Context context, ActionMode.Callback2 callback, View originatingView, FloatingToolbar floatingToolbar) { mContext = context; mCallback = callback; PopupMenu p = new PopupMenu(context, null); mMenu = p.getMenu(); setType(ActionMode.TYPE_FLOATING); p.setOnMenuItemClickListener(menuItem -> mCallback.onActionItemClicked(FloatingActionMode.this, menuItem)); mContentRect = new Rect(); mContentRectOnScreen = new Rect(); mPreviousContentRectOnScreen = new Rect(); mViewPositionOnScreen = new int[2]; mPreviousViewPositionOnScreen = new int[2]; mRootViewPositionOnScreen = new int[2]; mViewRectOnScreen = new Rect(); mPreviousViewRectOnScreen = new Rect(); mScreenRect = new Rect(); mOriginatingView = originatingView; mOriginatingView.getLocationOnScreen(mViewPositionOnScreen); mBottomAllowance = AndroidUtilities.dp(20); mDisplaySize = new Point(); setFloatingToolbar(floatingToolbar); }
Example 13
Source File: TopicFragment.java From android-discourse with Apache License 2.0 | 5 votes |
protected void showPopupActioinMenu(View v) { int position = getPositionForView(v); L.d("postion %d at all %d", position, mAdapter.getCount()); Post post = (Post) mAdapter.getItem(position); mMenuPost = post; int links; if (position == 0) { mMenuTopicDetails = mData.mTopicDetails; links = mData.getTopicLinksSize(); } else { links = post.getLinksSize(); mMenuTopicDetails = null; } PopupMenu menu = new PopupMenu(getActivity(), v); menu.inflate(R.menu.post_action_menu); Menu m = menu.getMenu(); m.findItem(R.id.menu_post_flag).setVisible(post.showFlag() && false);// TODO 第一个版本 不支持该功能 MenuItem bookmark = m.findItem(R.id.menu_post_bookmark); bookmark.setVisible(App.isLogin()); bookmark.setChecked(post.bookmarked); MenuItem link = m.findItem(R.id.menu_post_links); link.setVisible(links > 0); link.setTitle(getResources().getString(R.string.menu_links, links)); MenuItem posters = m.findItem(R.id.menu_poster_count); if (position == 0) { posters.setVisible(false);// TODO 应该为true,第一个版本不支持该功能 int posterSize = mData.getPosterSize(); posters.setTitle(getResources().getString(R.string.menu_poster_count, posterSize)); } else { posters.setVisible(false); } m.findItem(R.id.menu_post_delete).setVisible(post.can_delete); menu.setOnMenuItemClickListener(mMenuListener); menu.show(); }
Example 14
Source File: PopupMenuDemoActivity.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
private void createPopupMenuFromMixture() { mPopupMenu3 = new PopupMenu(this, findViewById(R.id.btn_popupmenu3)); Menu menu = mPopupMenu3.getMenu(); // 通过代码添加菜单项 menu.add(Menu.NONE, MENU_ITEM_COPY_ID, 0, "唐僧"); menu.add(Menu.NONE, MENU_ITEM_PASTE_ID, 1, "孙悟空"); // 通过XML文件添加菜单项 MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.popupmenu, menu); }
Example 15
Source File: QueueRecyclerAdapter.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
private void onMenuClick(@NonNull final View itemView, final int position) { final PopupMenu popup = new PopupMenu(itemView.getContext(), itemView); final Menu popupMenu = popup.getMenu(); final MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.list_item_media, popupMenu); final Media item = getItem(position); popup.setOnMenuItemClickListener(menuItem -> onMenuItemClick(menuItem, item)); popup.show(); }
Example 16
Source File: CustomActionsPopup.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
public boolean show() { List<AccessibilityAction> actions = getActionList(); if (actions.isEmpty()) { return false; } PopupMenu popup = new PopupMenu(mLauncher, mIcon); popup.setOnMenuItemClickListener(this); Menu menu = popup.getMenu(); for (AccessibilityAction action : actions) { menu.add(Menu.NONE, action.getId(), Menu.NONE, action.getLabel()); } popup.show(); return true; }
Example 17
Source File: PlayerActivity.java From Android-Example-HLS-ExoPlayer with Apache License 2.0 | 5 votes |
private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener, final int trackType) { if (player == null) { return; } int trackCount = player.getTrackCount(trackType); if (trackCount == 0) { return; } popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return (customActionClickListener != null && customActionClickListener.onMenuItemClick(item)) || onTrackItemClick(item, trackType); } }); Menu menu = popup.getMenu(); // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0). menu.add(MENU_GROUP_TRACKS, DemoPlayer.TRACK_DISABLED + ID_OFFSET, Menu.NONE, R.string.off); for (int i = 0; i < trackCount; i++) { menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, buildTrackName(player.getTrackFormat(trackType, i))); } menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true); menu.findItem(player.getSelectedTrack(trackType) + ID_OFFSET).setChecked(true); }
Example 18
Source File: MainActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
@Override public boolean onGesture(Gesture gesture, MotionEvent event) { mMap.getMapPosition(mMapPosition); // override default behavior to adjust pivot point if (gesture == Gesture.DOUBLE_TAP) { zoomMap(2.0, event.getX() - (mMap.getScreenWidth() >> 1), event.getY() - (mMap.getScreenHeight() >> 1)); return true; } else if (gesture == Gesture.TWO_FINGER_TAP) { zoomMap(0.5, 0f, 0f); return true; } else if (gesture == Gesture.TRIPLE_TAP) { float scale = Configuration.getRememberedScale(); double scaleBy = scale / mMapPosition.getScale(); float x = scaleBy > 1 ? event.getX() - (mMap.getScreenWidth() >> 1) : 0f; float y = scaleBy > 1 ? event.getY() - (mMap.getScreenHeight() >> 1) : 0f; zoomMap(scaleBy, x, y); return true; } else if (gesture == Gesture.LONG_PRESS) { if (!mMap.getEventLayer().moveEnabled() || !mObjectInteractionEnabled) return true; mViews.popupAnchor.setX(event.getX() + mFingerTipSize); mViews.popupAnchor.setY(event.getY() - mFingerTipSize); mSelectedPoint = mMap.viewport().fromScreenPoint(event.getX(), event.getY()); showMarker(mSelectedPoint, null, false); PopupMenu popup = new PopupMenu(this, mViews.popupAnchor); popup.inflate(R.menu.context_menu_map); Menu popupMenu = popup.getMenu(); if (mLocationState == LocationState.DISABLED || mLocationState == LocationState.SEARCHING || mLocationService == null || !isOnline()) popupMenu.removeItem(R.id.actionFindRouteHere); if ((int) Configuration.getRememberedScale() == (int) mMapPosition.getScale()) popupMenu.removeItem(R.id.actionRememberScale); if (mLocationState != LocationState.TRACK || mAutoTilt == -1f || MathUtils.equals(mAutoTilt, mMapPosition.getTilt())) popupMenu.removeItem(R.id.actionRememberTilt); popup.setOnMenuItemClickListener(this); popup.setOnDismissListener(menu -> removeMarker()); popup.show(); return true; } return false; }
Example 19
Source File: PluginSettingsDialog.java From xposed-rimet with Apache License 2.0 | 5 votes |
/** * 显示更多菜单 */ private void showMoreMenu() { PopupMenu popupMenu = new PopupMenu(getApplicationContext(), mMoreButton, Gravity.RIGHT); Menu menu = popupMenu.getMenu(); menu.add(1, 1, 1, "关于"); popupMenu.setOnMenuItemClickListener(item -> { handlerMoreMenu(item); return true; }); popupMenu.show(); }
Example 20
Source File: Launcher.java From TurboLauncher with Apache License 2.0 | 4 votes |
public void onClickSortModeButton(View v) { final PopupMenu popupMenu = new PopupMenu(this, v); final Menu menu = popupMenu.getMenu(); popupMenu.inflate(R.menu.apps_customize_sort_mode); switch (mAppsCustomizeContent.getSortMode()) { case Title: menu.findItem(R.id.sort_mode_title).setChecked(true); break; case LaunchCount: menu.findItem(R.id.sort_mode_launch_count).setChecked(true); break; case InstallTime: menu.findItem(R.id.sort_mode_install_time).setChecked(true); break; } popupMenu .setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.sort_mode_title: mAppsCustomizeContent .setSortMode(AppsCustomizePagedView.SortMode.Title); break; case R.id.sort_mode_install_time: mAppsCustomizeContent .setSortMode(AppsCustomizePagedView.SortMode.InstallTime); break; case R.id.sort_mode_launch_count: mAppsCustomizeContent .setSortMode(AppsCustomizePagedView.SortMode.LaunchCount); break; } mOverviewSettingsPanel.notifyDataSetInvalidated(); SettingsProvider.putInt(getBaseContext(), SettingsProvider.SETTINGS_UI_DRAWER_SORT_MODE, mAppsCustomizeContent.getSortMode().getValue()); return true; } }); popupMenu.show(); }