Search in sources :

Example 16 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project Signal-Android by WhisperSystems.

the class PopupMenuView method init.

private void init(@Nullable AttributeSet attrs) {
    setBackgroundResource(R.drawable.ic_more_vert_24);
    if (attrs != null) {
        TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.PopupMenuView, 0, 0);
        int tint = typedArray.getColor(R.styleable.PopupMenuView_background_tint, Color.BLACK);
        Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_more_vert_24);
        DrawableCompat.setTint(Objects.requireNonNull(drawable), tint);
        setBackground(drawable);
        typedArray.recycle();
    }
    setOnClickListener(v -> {
        if (callback != null) {
            PopupMenu popup = new PopupMenu(getContext(), v);
            MenuInflater inflater = popup.getMenuInflater();
            inflater.inflate(menu, popup.getMenu());
            if (prepareOptionsMenuItemCallback != null) {
                Menu menu = popup.getMenu();
                for (int i = menu.size() - 1; i >= 0; i--) {
                    MenuItem item = menu.getItem(i);
                    if (!prepareOptionsMenuItemCallback.onPrepareOptionsMenuItem(item)) {
                        menu.removeItem(item.getItemId());
                    }
                }
            }
            popup.setOnMenuItemClickListener(item -> callback.onItemClick(item.getItemId()));
            popup.show();
        }
    });
}
Also used : MenuInflater(android.view.MenuInflater) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) PopupMenu(androidx.appcompat.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 17 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project Douya by DreaminginCodeZH.

the class BaseItemDataAdapter method createItemCollectionHolder.

protected ItemCollectionHolder createItemCollectionHolder(ViewGroup parent) {
    ItemCollectionHolder holder = new ItemCollectionHolder(ViewUtils.inflate(R.layout.item_fragment_collection, parent));
    holder.menu = new PopupMenu(RecyclerViewUtils.getContext(holder), holder.menuButton);
    holder.menu.inflate(R.menu.item_collection_actions);
    holder.menuButton.setOnClickListener(view -> holder.menu.show());
    holder.menuButton.setOnTouchListener(holder.menu.getDragToOpenListener());
    return holder;
}
Also used : PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 18 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project DiscreteScrollView by yarolegovich.

the class DiscreteScrollViewOptions method smoothScrollToUserSelectedPosition.

public static void smoothScrollToUserSelectedPosition(final DiscreteScrollView scrollView, View anchor) {
    PopupMenu popupMenu = new PopupMenu(scrollView.getContext(), anchor);
    Menu menu = popupMenu.getMenu();
    final RecyclerView.Adapter<?> adapter = scrollView.getAdapter();
    int itemCount = (adapter instanceof InfiniteScrollAdapter) ? ((InfiniteScrollAdapter<?>) adapter).getRealItemCount() : (adapter != null ? adapter.getItemCount() : 0);
    for (int i = 0; i < itemCount; i++) {
        menu.add(String.valueOf(i + 1));
    }
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int destination = Integer.parseInt(String.valueOf(item.getTitle())) - 1;
            if (adapter instanceof InfiniteScrollAdapter) {
                destination = ((InfiniteScrollAdapter<?>) adapter).getClosestPosition(destination);
            }
            scrollView.smoothScrollToPosition(destination);
            return true;
        }
    });
    popupMenu.show();
}
Also used : InfiniteScrollAdapter(com.yarolegovich.discretescrollview.InfiniteScrollAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) MenuItem(android.view.MenuItem) PopupMenu(androidx.appcompat.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 19 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project k-9 by k9mail.

the class MessageHeader method onClick.

@Override
public void onClick(View view) {
    int id = view.getId();
    if (id == R.id.subject) {
        toggleSubjectViewMaxLines();
    } else if (id == R.id.from) {
        onAddSenderToContacts();
    } else if (id == R.id.to || id == R.id.cc || id == R.id.bcc) {
        expand((TextView) view, ((TextView) view).getEllipsize() != null);
    } else if (id == R.id.crypto_status_icon) {
        onCryptoClickListener.onCryptoClick();
    } else if (id == R.id.icon_single_message_options) {
        PopupMenu popupMenu = new PopupMenu(getContext(), view);
        popupMenu.setOnMenuItemClickListener(onMenuItemClickListener);
        popupMenu.inflate(R.menu.single_message_options);
        popupMenu.show();
    }
}
Also used : TextView(android.widget.TextView) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 20 with PopupMenu

use of androidx.appcompat.widget.PopupMenu in project Tusky by Vavassor.

the class SFragment method more.

protected void more(@NonNull final Status status, View view, final int position) {
    final String id = status.getActionableId();
    final String accountId = status.getActionableStatus().getAccount().getId();
    final String accountUsername = status.getActionableStatus().getAccount().getUsername();
    final String statusUrl = status.getActionableStatus().getUrl();
    List<AccountEntity> accounts = accountManager.getAllAccountsOrderedByActive();
    String openAsTitle = null;
    String loggedInAccountId = null;
    AccountEntity activeAccount = accountManager.getActiveAccount();
    if (activeAccount != null) {
        loggedInAccountId = activeAccount.getAccountId();
    }
    PopupMenu popup = new PopupMenu(getContext(), view);
    // Give a different menu depending on whether this is the user's own toot or not.
    boolean statusIsByCurrentUser = loggedInAccountId != null && loggedInAccountId.equals(accountId);
    if (statusIsByCurrentUser) {
        popup.inflate(R.menu.status_more_for_user);
        Menu menu = popup.getMenu();
        switch(status.getVisibility()) {
            case PUBLIC:
            case UNLISTED:
                {
                    final String textId = getString(status.isPinned() ? R.string.unpin_action : R.string.pin_action);
                    menu.add(0, R.id.pin, 1, textId);
                    break;
                }
            case PRIVATE:
                {
                    boolean reblogged = status.getReblogged();
                    if (status.getReblog() != null)
                        reblogged = status.getReblog().getReblogged();
                    menu.findItem(R.id.status_reblog_private).setVisible(!reblogged);
                    menu.findItem(R.id.status_unreblog_private).setVisible(reblogged);
                    break;
                }
        }
    } else {
        popup.inflate(R.menu.status_more);
        Menu menu = popup.getMenu();
        menu.findItem(R.id.status_download_media).setVisible(!status.getAttachments().isEmpty());
    }
    Menu menu = popup.getMenu();
    MenuItem openAsItem = menu.findItem(R.id.status_open_as);
    switch(accounts.size()) {
        case 0:
        case 1:
            openAsItem.setVisible(false);
            break;
        case 2:
            for (AccountEntity account : accounts) {
                if (account != activeAccount) {
                    openAsTitle = String.format(getString(R.string.action_open_as), account.getFullName());
                    break;
                }
            }
            break;
        default:
            openAsTitle = String.format(getString(R.string.action_open_as), "…");
            break;
    }
    openAsItem.setTitle(openAsTitle);
    MenuItem muteConversationItem = menu.findItem(R.id.status_mute_conversation);
    boolean mutable = statusIsByCurrentUser || accountIsInMentions(activeAccount, status.getMentions());
    muteConversationItem.setVisible(mutable);
    if (mutable) {
        muteConversationItem.setTitle((status.getMuted() == null || !status.getMuted()) ? R.string.action_mute_conversation : R.string.action_unmute_conversation);
    }
    popup.setOnMenuItemClickListener(item -> {
        switch(item.getItemId()) {
            case R.id.status_share_content:
                {
                    Status statusToShare = status;
                    if (statusToShare.getReblog() != null)
                        statusToShare = statusToShare.getReblog();
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    String stringToShare = statusToShare.getAccount().getUsername() + " - " + statusToShare.getContent().toString();
                    sendIntent.putExtra(Intent.EXTRA_TEXT, stringToShare);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, statusUrl);
                    sendIntent.setType("text/plain");
                    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to)));
                    return true;
                }
            case R.id.status_share_link:
                {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl);
                    sendIntent.setType("text/plain");
                    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
                    return true;
                }
            case R.id.status_copy_link:
                {
                    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText(null, statusUrl);
                    clipboard.setPrimaryClip(clip);
                    return true;
                }
            case R.id.status_open_as:
                {
                    showOpenAsDialog(statusUrl, item.getTitle());
                    return true;
                }
            case R.id.status_download_media:
                {
                    requestDownloadAllMedia(status);
                    return true;
                }
            case R.id.status_mute:
                {
                    onMute(accountId, accountUsername);
                    return true;
                }
            case R.id.status_block:
                {
                    onBlock(accountId, accountUsername);
                    return true;
                }
            case R.id.status_report:
                {
                    openReportPage(accountId, accountUsername, id);
                    return true;
                }
            case R.id.status_unreblog_private:
                {
                    onReblog(false, position);
                    return true;
                }
            case R.id.status_reblog_private:
                {
                    onReblog(true, position);
                    return true;
                }
            case R.id.status_delete:
                {
                    showConfirmDeleteDialog(id, position);
                    return true;
                }
            case R.id.status_delete_and_redraft:
                {
                    showConfirmEditDialog(id, position, status);
                    return true;
                }
            case R.id.pin:
                {
                    timelineCases.pin(status.getId(), !status.isPinned()).to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe();
                    return true;
                }
            case R.id.status_mute_conversation:
                {
                    timelineCases.muteConversation(status.getId(), status.getMuted() == null || !status.getMuted()).onErrorReturnItem(status).observeOn(AndroidSchedulers.mainThread()).to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe();
                    return true;
                }
        }
        return false;
    });
    popup.show();
}
Also used : Status(com.keylesspalace.tusky.entity.Status) ClipboardManager(android.content.ClipboardManager) MenuItem(android.view.MenuItem) Intent(android.content.Intent) Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu) ClipData(android.content.ClipData) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) PopupMenu(androidx.appcompat.widget.PopupMenu)

Aggregations

PopupMenu (androidx.appcompat.widget.PopupMenu)34 MenuItem (android.view.MenuItem)20 TextView (android.widget.TextView)12 Spannable (android.text.Spannable)8 View (android.view.View)8 Menu (android.view.Menu)7 SwitchCompat (androidx.appcompat.widget.SwitchCompat)5 MenuInflater (android.view.MenuInflater)4 LinearLayout (android.widget.LinearLayout)4 RelativeLayout (android.widget.RelativeLayout)4 Intent (android.content.Intent)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 CompoundButton (android.widget.CompoundButton)2 SearchView (androidx.appcompat.widget.SearchView)2