androidx.appcompat.widget.PopupMenu Java Examples

The following examples show how to use androidx.appcompat.widget.PopupMenu. 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: ViewUtils.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #2
Source File: PlaylistFragment.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_playlist_sort && getView() != null) {
        View anchor = getView().findViewById(R.id.menu_playlist_sort);
        PopupMenu sortMenu = new PopupMenu(getContext(), anchor, Gravity.END);

        if (mPlaylist instanceof AutoPlaylist) {
            sortMenu.inflate(R.menu.sort_options_auto_playlist);
            sortMenu.setOnMenuItemClickListener(this::onAutoPlaylistSortOptionSelected);
        } else {
            sortMenu.inflate(R.menu.sort_options);
            sortMenu.setOnMenuItemClickListener(this::onSortOptionSelected);
        }

        sortMenu.show();
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #3
Source File: PlaylistItemViewModel.java    From Jockey with Apache License 2.0 6 votes vote down vote up
private PopupMenu.OnMenuItemClickListener onMenuItemClick(View view) {
    return menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.menu_item_queue_item_next:
                queuePlaylistNext();
                return true;
            case R.id.menu_item_queue_item_last:
                queuePlaylistLast();
                return true;
            case R.id.menu_item_edit:
                editThisAsAutoPlaylist();
                return true;
            case R.id.menu_item_delete:
                if (mPlaylist instanceof AutoPlaylist) {
                    deleteAutoPlaylist(view);
                } else {
                    deletePlaylist(view);
                }
                return true;
        }
        return false;
    };
}
 
Example #4
Source File: PlaylistRecyclerViewAdapter.java    From Bop with Apache License 2.0 6 votes vote down vote up
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: VideoCardPresenter.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
CardViewHolder(ImageCardView view, Context context) {
    super(view);
    mContext = context;
    Context wrapper = new ContextThemeWrapper(mContext, R.style.MyPopupMenu);
    mPopupMenu = new PopupMenu(wrapper, view);
    mPopupMenu.inflate(R.menu.popup_menu);

    mPopupMenu.setOnMenuItemClickListener(this);
    view.setOnLongClickListener(this);

    mOwner = (LifecycleOwner) mContext;

    mDefaultBackground = mContext.getResources().getDrawable(R.drawable.no_cache_no_internet, null);
    mDefaultPlaceHolder = new RequestOptions().
            placeholder(mDefaultBackground);

    mCardView = (ImageCardView) CardViewHolder.this.view;
    Resources resources = mCardView.getContext().getResources();
    mCardView.setMainImageDimensions(Math.round(
            resources.getDimensionPixelSize(R.dimen.card_width)),
            resources.getDimensionPixelSize(R.dimen.card_height));

    mFragmentActivity = (FragmentActivity) context;
    mViewModel = ViewModelProviders.of(mFragmentActivity).get(VideosViewModel.class);
}
 
Example #6
Source File: CategoryOptionPopUp.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #7
Source File: RecentFragment.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
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: NowPlayingFragment.java    From Jockey with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: QueueSongItemViewModel.java    From Jockey with Apache License 2.0 6 votes vote down vote up
private PopupMenu.OnMenuItemClickListener onMenuItemClick(View view) {
    return menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.menu_item_navigate_to_artist:
                navigateToArtist();
                return true;
            case R.id.menu_item_navigate_to_album:
                navigateToAlbum();
                return true;
            case R.id.menu_item_navigate_to_folder:
                getContext().startActivity(MusicBrowserActivity.newIntent(getContext(), getReference()));
                return true;
            case R.id.menu_item_add_to_playlist:
                addToPlaylist();
                return true;
            case R.id.menu_item_remove:
                removeFromQueue(view);
                return true;
        }
        return false;
    };
}
 
Example #10
Source File: ConversationFragment.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
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 #11
Source File: TVShowProgressFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: ViewUtils.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #13
Source File: TasksFragment.java    From simple-stack with Apache License 2.0 6 votes vote down vote up
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 #14
Source File: BasicActivity.java    From intra42 with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: DirectoryListFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    PopupMenu menu = new PopupMenu(itemView.getContext(), v, Gravity.END);
    menu.getMenu().add(getString(R.string.action_remove));
    menu.setOnMenuItemClickListener(this);
    menu.show();
}
 
Example #16
Source File: SongItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private PopupMenu.OnMenuItemClickListener onMenuItemClick() {
    return menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.menu_item_queue_item_next:
                mPlayerController.queueNext(mReference);
                return true;
            case R.id.menu_item_queue_item_last:
                mPlayerController.queueLast(mReference);
                return true;
            case R.id.menu_item_navigate_to_artist:
                mMusicStore.findArtistById(mReference.getArtistId()).subscribe(
                        artist -> {
                            startActivity(ArtistActivity.newIntent(getContext(), artist));
                        }, throwable -> {
                            Timber.e(throwable, "Failed to find artist");
                        });

                return true;
            case R.id.menu_item_navigate_to_album:
                mMusicStore.findAlbumById(mReference.getAlbumId()).subscribe(
                        album -> {
                            startActivity(AlbumActivity.newIntent(getContext(), album));
                        }, throwable -> {
                            Timber.e(throwable, "Failed to find album", throwable);
                        });
                return true;
            case R.id.menu_item_navigate_to_folder:
                getContext().startActivity(MusicBrowserActivity.newIntent(getContext(), mReference));
                return true;
            case R.id.menu_item_add_to_playlist:
                new AppendPlaylistDialogFragment.Builder(getContext(), mFragmentManager)
                        .setSongs(mReference)
                        .showSnackbarIn(R.id.list)
                        .show(TAG_PLAYLIST_DIALOG, mPlaylistStore);
                return true;
        }
        return false;
    };
}
 
Example #17
Source File: ChannelFragment.java    From RoMote with Apache License 2.0 5 votes vote down vote up
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: ReportAdapter.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 5 votes vote down vote up
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 #19
Source File: SongItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: MysplashPopupWindow.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void show(MysplashActivity activity, View anchor, @MenuRes int resId,
                        @NonNull PopupMenu.OnMenuItemClickListener l) {
    PopupMenu popupMenu = new PopupMenu(activity, anchor);
    popupMenu.getMenuInflater().inflate(resId, popupMenu.getMenu());
    popupMenu.show();
    popupMenu.setOnMenuItemClickListener(l);

    // DisplayUtils.setOverflowMenuIconsVisible(popupMenu.getMenu());

    popupMenu.show();
}
 
Example #21
Source File: ArtistItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private PopupMenu.OnMenuItemClickListener onMenuItemClick() {
    return menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.menu_item_queue_item_next:
                mMusicStore.getSongs(mArtist).subscribe(
                        mPlayerController::queueNext,
                        throwable -> {
                            Timber.e(throwable, "Failed to get songs");
                        });

                return true;
            case R.id.menu_item_queue_item_last:
                mMusicStore.getSongs(mArtist).subscribe(
                        mPlayerController::queueLast,
                        throwable -> {
                            Timber.e(throwable, "Failed to get songs");
                        });

                return true;
            case R.id.menu_item_add_to_playlist:
                mMusicStore.getSongs(mArtist).subscribe(
                        songs -> {
                            new AppendPlaylistDialogFragment.Builder(mContext, mFragmentManager)
                                    .setSongs(songs, mArtist.getArtistName())
                                    .showSnackbarIn(R.id.list)
                                    .show(TAG_PLAYLIST_DIALOG, mPlaylistStore);
                        }, throwable -> {
                            Timber.e(throwable, "Failed to get songs");
                        });

                return true;
        }
        return false;
    };
}
 
Example #22
Source File: ThemePreferencesManager.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: BottomSheetBuilder.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
public BottomSheetBuilder setMenu(@MenuRes int menu) {
    @SuppressWarnings("ConstantConditions")
    PopupMenu popupMenu = new PopupMenu(mContext, null);
    mMenu = popupMenu.getMenu();
    popupMenu.getMenuInflater().inflate(menu, mMenu);
    return setMenu(mMenu);
}
 
Example #24
Source File: MainActivity.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
/**
 * Create menu.
 */
private PopupMenu createMenu(View v, String[] menuArray) {
    PopupMenu popupMenu = new PopupMenu(this, v);
    Menu menu = popupMenu.getMenu();
    for (int i = 0; i < menuArray.length; i++) {
        String menuText = menuArray[i];
        menu.add(0, i, i, menuText);
    }
    return popupMenu;
}
 
Example #25
Source File: GenreItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: ExperimentDetailsFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
private void setupTrialHeader(DetailsViewHolder holder, final ExperimentDetailItem item) {
  holder.timeHeader.setTime(
      item.getViewType() == VIEW_TYPE_RUN_CARD
          ? item.getTrial().getFirstTimestamp()
          : item.getLabel().getTimeStamp());

  ColorUtils.colorDrawable(
      holder.captionIcon.getContext(),
      holder.captionIcon.getDrawable(),
      R.color.text_color_light_grey);
  ColorUtils.colorDrawable(
      holder.menuButton.getContext(),
      holder.menuButton.getDrawable(),
      R.color.text_color_light_grey);

  holder.menuButton.setOnClickListener(
      view -> {
        Context context = holder.menuButton.getContext();
        popupMenu =
            new PopupMenu(
                context,
                holder.menuButton,
                Gravity.NO_GRAVITY,
                R.attr.actionOverflowMenuStyle,
                0);
        setupTrialMenu(item);
        popupMenu.show();
      });
}
 
Example #27
Source File: PermissionGroupActivity.java    From AppOpsX with MIT License 5 votes vote down vote up
private void showPopMenu(int groupPosition, View view) {
  PopupMenu popupMenu = new PopupMenu(this, view);
  getMenuInflater().inflate(R.menu.group_item_menu, popupMenu.getMenu());
  popupMenu.setOnDismissListener(this);
  popupMenu.setOnMenuItemClickListener(this);
  popupMenu.show();
}
 
Example #28
Source File: GenreItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private PopupMenu.OnMenuItemClickListener onMenuItemClick() {
    return menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.menu_item_queue_item_next:
                mMusicStore.getSongs(mGenre).subscribe(
                        mPlayerController::queueNext,
                        throwable -> {
                            Timber.e(throwable, "Failed to get songs");
                        });

                return true;
            case R.id.menu_item_queue_item_last:
                mMusicStore.getSongs(mGenre).subscribe(
                        mPlayerController::queueLast,
                        throwable -> {
                            Timber.e(throwable, "Failed to get songs");
                        });

                return true;
            case R.id.menu_item_add_to_playlist:
                mMusicStore.getSongs(mGenre).subscribe(
                        songs -> {
                            new AppendPlaylistDialogFragment.Builder(mContext, mFragmentManager)
                                    .setSongs(songs, mGenre.getGenreName())
                                    .showSnackbarIn(R.id.list)
                                    .show(TAG_PLAYLIST_DIALOG, mPlaylistStore);
                        }, throwable -> {
                            Timber.e(throwable, "Failed to get songs");
                        });

                return true;
        }
        return false;
    };
}
 
Example #29
Source File: GalleryDetailScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private void ensurePopMenu() {
    if (mPopupMenu != null) {
        return;
    }

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    PopupMenu popup = new PopupMenu(context, mOtherActions, Gravity.TOP);
    mPopupMenu = popup;
    popup.getMenuInflater().inflate(R.menu.scene_gallery_detail, popup.getMenu());

    View.generateViewId();
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_open_in_other_app:
                    String url = getGalleryDetailUrl();
                    Activity activity = getActivity2();
                    if (null != url && null != activity) {
                        UrlOpener.openUrl(activity, url, false);
                    }
                    break;
                case R.id.action_refresh:
                    if (mState != STATE_REFRESH && mState != STATE_REFRESH_HEADER) {
                        adjustViewVisibility(STATE_REFRESH, true);
                        request();
                    }
                    break;
            }
            return true;
        }
    });
}
 
Example #30
Source File: MenuViewHolder.java    From RecyclerExt with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}