List of usage examples for android.widget PopupMenu getMenu
public Menu getMenu()
From source file:com.example.ray.firstapp.bottombar.MiscUtils.java
/** * A hacky method for inflating menus from xml resources to an array * of BottomBarTabs./*from w w w . j a v a2s. c o m*/ * * @param activity the activity context for retrieving the MenuInflater. * @param menuRes the xml menu resource to inflate * @return an Array of BottomBarTabs. */ protected static BottomBarTab[] inflateMenuFromResource(Activity activity, @MenuRes int menuRes) { // A bit hacky, but hey hey what can I do PopupMenu popupMenu = new PopupMenu(activity, null); Menu menu = popupMenu.getMenu(); activity.getMenuInflater().inflate(menuRes, menu); int menuSize = menu.size(); BottomBarTab[] tabs = new BottomBarTab[menuSize]; for (int i = 0; i < menuSize; i++) { MenuItem item = menu.getItem(i); BottomBarTab tab = new BottomBarTab(item.getIcon(), String.valueOf(item.getTitle())); tab.id = item.getItemId(); tabs[i] = tab; } return tabs; }
From source file:com.tlongdev.bktf.util.Utility.java
public static PopupMenu createItemPopupMenu(final Activity activity, View anchor, final Item item) { PopupMenu menu = new PopupMenu(activity, anchor); menu.getMenuInflater().inflate(R.menu.popup_item, menu.getMenu()); menu.getMenu().findItem(R.id.favorite) .setTitle(isFavorite(activity, item) ? "Remove from favorites" : "Add to favorites"); menu.getMenu().findItem(R.id.calculator).setEnabled(!isInCalculator(activity, item)); menu.setOnMenuItemClickListener(new android.widget.PopupMenu.OnMenuItemClickListener() { @Override/* w w w . j a v a 2 s .c o m*/ public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.history: Intent i = new Intent(activity, PriceHistoryActivity.class); i.putExtra(PriceHistoryActivity.EXTRA_ITEM, item); activity.startActivity(i); break; case R.id.favorite: if (isFavorite(activity, item)) { removeFromFavorites(activity, item); } else { addToFavorites(activity, item); } break; case R.id.calculator: addToCalculator(activity, item); menuItem.setEnabled(false); break; case R.id.backpack_tf: CustomTabActivityHelper.openCustomTab(activity, new CustomTabsIntent.Builder().build(), Uri.parse(item.getBackpackTfUrl()), new WebViewFallback()); break; case R.id.wiki: CustomTabActivityHelper.openCustomTab(activity, new CustomTabsIntent.Builder().build(), Uri.parse(item.getTf2WikiUrl()), new WebViewFallback()); break; } return true; } }); return menu; }
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 w w w. ja v a 2s. c o 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.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 av a2 s .c o 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: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); }/*from w w w .j a v a2s.co 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.battlelancer.seriesguide.ui.MoviesCollectionFragment.java
@Override public void onPopupMenuClick(View v, final int movieTmdbId) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); popupMenu.getMenu().add(0, CONTEXT_COLLECTION_REMOVE_ID, 0, R.string.action_collection_remove); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* ww w . j a va 2 s . c o m*/ public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_COLLECTION_REMOVE_ID: { MovieTools.removeFromCollection(getActivity(), movieTmdbId); fireTrackerEvent("Remove from collection"); return true; } } return false; } }); popupMenu.show(); }
From source file:com.battlelancer.seriesguide.ui.MoviesWatchListFragment.java
@Override public void onPopupMenuClick(View v, final int movieTmdbId) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); popupMenu.getMenu().add(0, CONTEXT_WATCHLIST_REMOVE_ID, 0, R.string.watchlist_remove); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* ww w. ja va2 s. c om*/ public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_WATCHLIST_REMOVE_ID: { MovieTools.removeFromWatchlist(getActivity(), movieTmdbId); fireTrackerEvent("Remove from watchlist"); return true; } } return false; } }); popupMenu.show(); }
From source file:org.alfresco.mobile.android.application.fragments.site.browser.SiteAdapter.java
@Override protected void updateTopText(TwoLinesViewHolder vh, Site item) { super.updateTopText(vh, item); if (mode == ListingModeFragment.MODE_IMPORT || mode == ListingModeFragment.MODE_PICK) { UIUtils.setBackground(vh.choose, null); return;// w ww . j a v a 2 s. co m } vh.choose.setImageResource(R.drawable.ic_more_options); vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light); int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16); vh.choose.setPadding(d_16, d_16, d_16, d_16); vh.choose.setVisibility(View.VISIBLE); AccessibilityUtils.addContentDescription(vh.choose, String.format(getContext().getString(R.string.more_options_site), item.getTitle())); vh.choose.setTag(R.id.site_action, item); vh.choose.setOnClickListener(new OnClickListener() { @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onClick(View v) { Site item = (Site) v.getTag(R.id.site_action); selectedOptionItems.add(item); PopupMenu popup = new PopupMenu(getContext(), v); getMenu(popup.getMenu(), item); popup.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { selectedOptionItems.clear(); } }); popup.setOnMenuItemClickListener(SiteAdapter.this); popup.show(); } }); }
From source file:at.ac.uniklu.mobile.sportal.DashboardActivity.java
@TargetApi(11) @Override/* w w w .j a v a 2 s. c om*/ public void openOptionsMenu() { // Honeycomb and ICS tablet menu workaround if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { /* Android >= 3 with holo theme doesn't support the options menu, so * display a popup menu below the overflow action button. */ PopupMenu m = new PopupMenu(this, findViewById(R.id.actionbar_overflow)); m.getMenuInflater().inflate(R.menu.dashboard_menu, m.getMenu()); m.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); m.show(); } else { // show default options menu on Android 2.x super.openOptionsMenu(); } }
From source file:com.google.reviewit.PagedChangeDetailsFragment.java
private void init() { final Change change = getApp().getQueryHandler().getCurrentChange(); checkArgument(change != null, "No change to display"); ChangeEntry changeEntry = new ChangeEntry(getContext()); changeEntry.init(getApp(), change);//from w ww . jav a 2 s .co m vg(R.id.changeHeader).addView(changeEntry); final List<PageFragment> fragments = new ArrayList<>(); CommitMessageFragment commitMessageFragment = new CommitMessageFragment(); commitMessageFragment.setChange(change); fragments.add(commitMessageFragment); FileListFragment fileListFragment = new FileListFragment(); fileListFragment.setChange(change); fragments.add(fileListFragment); ApprovalsFragment approvalsFragment = new ApprovalsFragment(); approvalsFragment.setChange(change); fragments.add(approvalsFragment); ReplyFragment replyFragment = new ReplyFragment(); replyFragment.setChange(change); fragments.add(replyFragment); // TODO add more tabs, e.g. for change messages ViewPager pager = ((ViewPager) v(R.id.pager)); pager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) { @Override public Fragment getItem(int position) { return fragments.get(position); } @Override public int getCount() { return fragments.size(); } @Override public CharSequence getPageTitle(int position) { return getString(fragments.get(position).getTitle()); } }); SlidingTabLayout tabs = ((SlidingTabLayout) v(R.id.tabs)); tabs.setTextColor(widgetUtil.color(R.color.tab)); tabs.setSelectedIndicatorColors(widgetUtil.color(R.color.tab)); tabs.setBorderColor(widgetUtil.color(R.color.tab)); tabs.setDividerColors(widgetUtil.color(R.color.tabDivider)); tabs.setBottomBorderThickness(widgetUtil.dpToPx(1)); tabs.setSelectedIndicatorThickness(widgetUtil.dpToPx(5)); tabs.setViewPager(pager); final View more = v(R.id.more); more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getContext(), more); popup.getMenuInflater().inflate(R.menu.menu_paged_change_details, popup.getMenu()); popup.getMenu().findItem(R.id.action_abandon).setVisible( change.info.status == ChangeStatus.NEW || change.info.status == ChangeStatus.SUBMITTED); popup.getMenu().findItem(R.id.action_restore) .setVisible(change.info.status == ChangeStatus.ABANDONED); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_abandon: display(AbandonFragment.create(PagedChangeDetailsFragment.class)); return true; case R.id.action_restore: display(RestoreFragment.create(PagedChangeDetailsFragment.class)); return true; default: return true; } } }); popup.show(); } }); }