Java Code Examples for androidx.appcompat.widget.PopupMenu#inflate()

The following examples show how to use androidx.appcompat.widget.PopupMenu#inflate() . 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: 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 2
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 3
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 4
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 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: 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 7
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 8
Source File: PlaylistSongItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public View.OnClickListener onClickMenu() {
    return v -> {
        final PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END);
        menu.inflate(R.menu.instance_song_playlist);
        menu.setOnMenuItemClickListener(onMenuItemClick(v));
        menu.show();
    };
}
 
Example 9
Source File: PlaylistItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public View.OnClickListener onClickMenu() {
    return v -> {
        PopupMenu menu = new PopupMenu(mContext, v, Gravity.END);
        menu.inflate((mPlaylist instanceof AutoPlaylist)
                ? R.menu.instance_smart_playlist
                : R.menu.instance_playlist);

        menu.setOnMenuItemClickListener(onMenuItemClick(v));
        menu.show();
    };
}
 
Example 10
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 11
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 12
Source File: NowPlayingControllerViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
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: QueueSongItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public View.OnClickListener onClickMenu() {
    return v -> {
        PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END);
        menu.inflate(getReference().isInLibrary()
                ? R.menu.instance_song_queue
                : R.menu.instance_song_queue_remote);
        menu.setOnMenuItemClickListener(onMenuItemClick(v));
        menu.show();
    };
}
 
Example 14
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 15
Source File: MainActivity.java    From ui with Apache License 2.0 5 votes vote down vote up
private void showPopupMenu(View v){
    PopupMenu popupM = new PopupMenu(this, v); //note "this" is the activity context, if you are using this in a fragment.  using getActivity()
    popupM.inflate(R.menu.popup);
    popupM.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getApplicationContext(), item.toString(), Toast.LENGTH_LONG).show();
            //textview.append("\n you clicked "+item.toString());
            return true;
        }
    });

    popupM.show();
}
 
Example 16
Source File: TikTokListFragment.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView() {
    super.initView();
    mRecyclerView = findViewById(R.id.rv_tiktok);
    mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
    mAdapter = new TikTokListAdapter(data);
    mRecyclerView.setAdapter(mAdapter);
    mSwitchImpl = findViewById(R.id.btn_switch_impl);
    PopupMenu menu = new PopupMenu(getContext(), mSwitchImpl);
    menu.inflate(R.menu.tiktok_impl_menu);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            mAdapter.setImpl(item.getItemId());
            switch (item.getItemId()) {
                case R.id.impl_recycler_view:
                    mSwitchImpl.setText("RecyclerView");
                    break;
                case R.id.impl_vertical_view_pager:
                    mSwitchImpl.setText("VerticalViewPager");
                    break;
                case R.id.impl_view_pager_2:
                    mSwitchImpl.setText("ViewPager2");
                    break;
            }
            return false;
        }
    });
    mSwitchImpl.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            menu.show();
        }
    });

    //默认VerticalViewPager
    mAdapter.setImpl(R.id.impl_vertical_view_pager);
    mSwitchImpl.setText("VerticalViewPager");
}
 
Example 17
Source File: ReminderDialogFragment.java    From Deadline with GNU General Public License v3.0 5 votes vote down vote up
private void setupPopupMenu() {
    final PopupMenu popupMenu = new PopupMenu(getActivity(), mBinding.remindIntervalUnit, Gravity.CENTER, 0, android.R.style.Widget_Material_Light_PopupMenu_Overflow);
    popupMenu.inflate(R.menu.menu_reminder_units);
    mBinding.remindIntervalUnit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            popupMenu.show();
            mViewModel.updateSelections(RemindType.SINGLE_REMIND);
        }
    });
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_remind_minutes:
                    mViewModel.singleRemindUnit.set(RemindType.SINGLE_MIN);
                    break;
                case R.id.action_remind_hours:
                    mViewModel.singleRemindUnit.set(RemindType.SINGLE_HOUR);
                    break;
                case R.id.action_remind_days:
                    mViewModel.singleRemindUnit.set(RemindType.SINGLE_DAY);
                    break;
                case R.id.action_remind_weeks:
                    mViewModel.singleRemindUnit.set(RemindType.SINGLE_WEEK);
                    break;
            }
            return true;
        }
    });
}
 
Example 18
Source File: PlayingNowList.java    From Bop with Apache License 2.0 5 votes vote down vote up
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 19
Source File: ProjectAdapterViewItem.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
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: FileManagerFragment.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
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();
}