List of usage examples for android.widget PopupMenu inflate
public void inflate(@MenuRes int menuRes)
From source file:com.fastbootmobile.encore.utils.Utils.java
public static void showSongOverflow(final FragmentActivity context, final View parent, final Song song, final boolean hideArtist) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.track_overflow); if (song.getArtist() == null || hideArtist) { // This song has no artist information, hide the entry Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_open_artist); }//from ww w .ja v a2 s . co m if (song.getAlbum() == null) { // This song has no album information, hide the entry Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_add_album_to_queue); } popupMenu.show(); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { final ProviderAggregator aggregator = ProviderAggregator.getDefault(); switch (menuItem.getItemId()) { case R.id.menu_play_now: PlaybackProxy.playSong(song); break; case R.id.menu_play_next: PlaybackProxy.playNext(song); break; case R.id.menu_open_artist: Intent intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(), context.getResources().getColor(R.color.default_album_art_background)); context.startActivity(intent); break; case R.id.menu_add_to_queue: PlaybackProxy.queueSong(song, false); Toast.makeText(context, R.string.toast_song_added_to_queue, Toast.LENGTH_SHORT).show(); break; case R.id.menu_add_album_to_queue: PlaybackProxy.queueAlbum(aggregator.retrieveAlbum(song.getAlbum(), song.getProvider()), false); Toast.makeText(context, R.string.toast_album_added_to_queue, Toast.LENGTH_SHORT).show(); break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song); fragment.show(context.getSupportFragmentManager(), song.getRef()); break; default: return false; } return true; } }); }
From source file:com.fastbootmobile.encore.utils.Utils.java
public static void showCurrentSongOverflow(final Context context, final View parent, final Song song, final boolean showArtist) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.queue_overflow); if (song.getAlbum() == null) { Log.d(TAG, "No album information, removing album options"); // This song has no album information, hide the entries Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_add_album_to_queue); menu.removeItem(R.id.menu_open_album); }// ww w.j av a2 s . c o m if (!showArtist) { Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_open_artist); } popupMenu.show(); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { final ProviderAggregator aggregator = ProviderAggregator.getDefault(); switch (menuItem.getItemId()) { case R.id.menu_open_album: final Resources res = context.getResources(); Intent intent = AlbumActivity.craftIntent(context, ((BitmapDrawable) res.getDrawable(R.drawable.album_placeholder)).getBitmap(), song.getAlbum(), song.getProvider(), res.getColor(R.color.default_album_art_background)); context.startActivity(intent); break; case R.id.menu_open_artist: intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(), context.getResources().getColor(R.color.default_album_art_background)); context.startActivity(intent); break; case R.id.menu_add_album_to_queue: PlaybackProxy.queueAlbum(aggregator.retrieveAlbum(song.getAlbum(), song.getProvider()), false); Toast.makeText(context, R.string.toast_album_added_to_queue, Toast.LENGTH_SHORT).show(); break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song); if (context instanceof FragmentActivity) { FragmentActivity act = (FragmentActivity) context; fragment.show(act.getSupportFragmentManager(), song.getRef()); } else { throw new IllegalArgumentException("Context must be an instance of FragmentActivity"); } break; default: return false; } return true; } }); }
From source file:com.oceansky.yellow.utils.Utils.java
public static void showSongOverflow(final FragmentActivity context, final View parent, final Song song, final boolean hideArtist) { if (song == null) { return;//from ww w . j ava 2 s . co m } PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.track_overflow); if (song.getArtist() == null || hideArtist) { // This song has no artist information, hide the entry Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_open_artist); } if (song.getAlbum() == null) { // This song has no album information, hide the entry Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_add_album_to_queue); } popupMenu.show(); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { final ProviderAggregator aggregator = ProviderAggregator.getDefault(); switch (menuItem.getItemId()) { case R.id.menu_play_now: PlaybackProxy.playSong(song); break; case R.id.menu_play_next: PlaybackProxy.playNext(song); break; case R.id.menu_open_artist: Intent intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(), context.getResources().getColor(R.color.default_album_art_background)); context.startActivity(intent); break; case R.id.menu_add_to_queue: PlaybackProxy.queueSong(song, false); Toast.makeText(context, R.string.toast_song_added_to_queue, Toast.LENGTH_SHORT).show(); break; case R.id.menu_add_album_to_queue: PlaybackProxy.queueAlbum(aggregator.retrieveAlbum(song.getAlbum(), song.getProvider()), false); Toast.makeText(context, R.string.toast_album_added_to_queue, Toast.LENGTH_SHORT).show(); break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song); fragment.show(context.getSupportFragmentManager(), song.getRef()); break; default: return false; } return true; } }); }
From source file:MainActivity.java
public void showPopupMenu(View view) { PopupMenu popupMenu = new PopupMenu(MainActivity.this, view); popupMenu.inflate(R.menu.menu_popup); popupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener); popupMenu.show();/*w ww . ja v a 2 s. co m*/ }
From source file:org.y20k.transistor.helpers.StationContextMenu.java
public void show() { PopupMenu popup = new PopupMenu(mActivity, mView); popup.inflate(R.menu.menu_main_list_item); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*w ww . j a va 2 s .c o m*/ public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { // CASE ICON case R.id.menu_icon: // send local broadcast (needed by MainActivityFragment) Intent i = new Intent(); i.setAction(ACTION_IMAGE_CHANGE_REQUESTED); i.putExtra(STATION_ID, mStationID); LocalBroadcastManager.getInstance(mActivity.getApplication()).sendBroadcast(i); return true; // CASE RENAME case R.id.menu_rename: // get name of station String stationName = mCollection.getStations().get(mStationID).getStationName(); // construct rename dialog DialogRename dialogRename = new DialogRename(mActivity, mCollection, stationName, mStationID); dialogRename.setStationRenamedListener(new DialogRename.StationRenamedListener() { @Override public void stationRenamed() { if (mStationChangedListener != null) { mStationChangedListener.stationChanged(); } } }); // run dialog dialogRename.show(); return true; // CASE DELETE case R.id.menu_delete: // construct delete dialog DialogDelete dialogDelete = new DialogDelete(mActivity, mCollection, mStationID); // run dialog dialogDelete.show(); return true; // CASE DEFAULT default: return false; } } }); popup.show(); }
From source file:app.umitems.greenclock.DeskClockFragment.java
/** * Installs click and touch listeners on a fake overflow menu button. * * @param menuButton the fragment's fake overflow menu button *///from www. j ava 2s . c o m public void setupFakeOverflowMenuButton(View menuButton) { final PopupMenu fakeOverflow = new PopupMenu(menuButton.getContext(), menuButton) { @Override public void show() { getActivity().onPrepareOptionsMenu(getMenu()); super.show(); } }; fakeOverflow.inflate(R.menu.desk_clock_menu); fakeOverflow.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return getActivity().onOptionsItemSelected(item); } }); menuButton.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(fakeOverflow)); menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fakeOverflow.show(); } }); }
From source file:com.owncloud.android.ui.trashbin.TrashbinActivity.java
@Override public void onOverflowIconClicked(TrashbinFile file, View view) { PopupMenu popup = new PopupMenu(this, view); popup.inflate(R.menu.trashbin_actions_menu); popup.setOnMenuItemClickListener(item -> { trashbinPresenter.removeTrashbinFile(file); return true; });/*w w w .ja v a 2s.c o m*/ popup.show(); }
From source file:com.ultramegasoft.flavordex2.fragment.PhotoFragment.java
/** * Show the PopupMenu for the photo.//from ww w . ja va2 s . c o m * * @param v The View to attach the menu to */ private void showMenu(@NonNull View v) { final PopupMenu popupMenu = new PopupMenu(getContext(), v); popupMenu.setOnMenuItemClickListener(this); popupMenu.inflate(R.menu.photo_menu); popupMenu.show(); }
From source file:de.schildbach.wallet.ui.monitor.BlockListFragment.java
@Override public void onBlockMenuClick(final View view, final Sha256Hash blockHash) { final PopupMenu popupMenu = new PopupMenu(activity, view); popupMenu.inflate(R.menu.blocks_context); popupMenu.getMenu().findItem(R.id.blocks_context_browse).setVisible(Constants.ENABLE_BROWSE); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override//from w w w . j a va 2 s . co m public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.blocks_context_browse: final Uri blockExplorerUri = config.getBlockExplorer(); log.info("Viewing block {} on {}", blockHash, blockExplorerUri); startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "block/" + blockHash))); return true; } return false; } }); popupMenu.show(); }
From source file:com.tcity.android.ui.overview.buildconfiguration.BuildConfigurationOverviewActivity.java
void optionsClick(@NotNull String id, @NotNull View anchor) { PopupMenu menu = new PopupMenu(this, anchor); menu.inflate(R.menu.menu_concept); menu.setOnMenuItemClickListener(new PopupMenuListener(WebLocator.getBuildUrl(id, new Preferences(this)))); menu.show();/*from w ww. j a v a 2s.c o m*/ }