Search in sources :

Example 46 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Gladys-Android-App by LeptitGeek.

the class AllSentencesFragment method onPopupMenuClickBrainSentences.

@Override
public void onPopupMenuClickBrainSentences(View view, int pos, final Long id, String status, final String label) {
    PopupMenu popup = new PopupMenu(getContext(), view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.brain_popup_menu, popup.getMenu());
    MenuItem approve_button = popup.getMenu().findItem(R.id.approve_button);
    MenuItem reject_button = popup.getMenu().findItem(R.id.reject_button);
    switch(status) {
        case "official":
            approve_button.setVisible(false);
            break;
        case "approved":
            approve_button.setVisible(false);
            break;
        case "rejected":
            reject_button.setVisible(false);
            break;
    }
    popup.show();
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.approve_button:
                    setStatus(id, "approved");
                    break;
                case R.id.reject_button:
                    setStatus(id, "rejected");
                    break;
                case R.id.set_label_button:
                    setLabelDialog(id, label);
                    break;
            }
            return false;
        }
    });
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) PopupMenu(android.support.v7.widget.PopupMenu)

Example 47 with PopupMenu

use of android.support.v7.widget.PopupMenu in project quran_android by quran.

the class AyahToolBar method init.

private void init(Context context) {
    this.context = context;
    final Resources resources = context.getResources();
    itemWidth = resources.getDimensionPixelSize(R.dimen.toolbar_item_width);
    final int toolBarHeight = resources.getDimensionPixelSize(R.dimen.toolbar_height);
    pipHeight = resources.getDimensionPixelSize(R.dimen.toolbar_pip_height);
    pipWidth = resources.getDimensionPixelSize(R.dimen.toolbar_pip_width);
    final int background = ContextCompat.getColor(context, R.color.toolbar_background);
    menuLayout = new LinearLayout(context);
    menuLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, toolBarHeight));
    menuLayout.setBackgroundColor(background);
    addView(menuLayout);
    pipPosition = PipPosition.DOWN;
    toolBarPip = new AyahToolBarPip(context);
    toolBarPip.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, pipHeight));
    addView(toolBarPip);
    // used to use MenuBuilder, but now it has @RestrictTo, so using this clever trick from
    // StackOverflow - PopupMenu generates a new MenuBuilder internally, so this just lets us
    // get that menu and do whatever we want with it.
    menu = new PopupMenu(this.context, this).getMenu();
    final MenuInflater inflater = new MenuInflater(this.context);
    inflater.inflate(ayahMenu, menu);
    showMenu(menu);
}
Also used : MenuInflater(android.view.MenuInflater) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout) PopupMenu(android.support.v7.widget.PopupMenu)

Example 48 with PopupMenu

use of android.support.v7.widget.PopupMenu in project gh4a by slapperwan.

the class DiffViewHolder method showPopupMenu.

private void showPopupMenu(final TimelineItem.Diff diff, final int line, final boolean isRightLine) {
    PopupMenu popupMenu = new PopupMenu(mContext, mDiffHunkTextView);
    Menu menu = popupMenu.getMenu();
    popupMenu.getMenuInflater().inflate(R.menu.review_diff_hunk_menu, menu);
    menu.findItem(R.id.view_in_file).setVisible(diff.getInitialComment().position() != null);
    popupMenu.setOnMenuItemClickListener(item -> {
        switch(item.getItemId()) {
            case R.id.share:
                IntentUtils.share(mContext, "Line", createUrl(diff, line, isRightLine));
                return true;
            case R.id.view_in_file:
                Intent intent = diff.getInitialTimelineComment().makeDiffIntent(mContext, line, isRightLine);
                mContext.startActivity(intent);
                return true;
        }
        return false;
    });
    popupMenu.show();
}
Also used : Intent(android.content.Intent) PopupMenu(android.support.v7.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(android.support.v7.widget.PopupMenu)

Example 49 with PopupMenu

use of android.support.v7.widget.PopupMenu in project incubator-weex by apache.

the class WXTextView method enableCopy.

public void enableCopy(boolean enable) {
    if (enable) {
        setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                PopupMenu popupMenu = new PopupMenu(getContext(), WXTextView.this);
                String s = "Copy";
                try {
                    s = getContext().getResources().getString(android.R.string.copy);
                } catch (Throwable t) {
                // ignore
                }
                final String title = s;
                popupMenu.getMenu().add(title);
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        if (title.equals(item.getTitle())) {
                            String data = getText().toString();
                            ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                            if (clipboardManager != null) {
                                ClipData clipData = ClipData.newPlainText(data, data);
                                clipboardManager.setPrimaryClip(clipData);
                            }
                            return true;
                        }
                        return false;
                    }
                });
                popupMenu.show();
                return true;
            }
        });
    } else {
        setOnLongClickListener(null);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) MenuItem(android.view.MenuItem) View(android.view.View) ClipData(android.content.ClipData) PopupMenu(android.support.v7.widget.PopupMenu)

Example 50 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Tusky by tuskyapp.

the class SFragment method more.

protected void more(final Status status, View view, final int position) {
    final String id = status.getActionableId();
    final String accountId = status.getActionableStatus().getAccount().getId();
    final String accountUsename = status.getActionableStatus().getAccount().getUsername();
    final Spanned content = status.getActionableStatus().getContent();
    final String statusUrl = status.getActionableStatus().getUrl();
    PopupMenu popup = new PopupMenu(getContext(), view);
    // Give a different menu depending on whether this is the user's own toot or not.
    if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
        popup.inflate(R.menu.status_more);
    } else {
        popup.inflate(R.menu.status_more_for_user);
    }
    popup.setOnMenuItemClickListener(item -> {
        switch(item.getItemId()) {
            case R.id.status_share_content:
                {
                    StringBuilder sb = new StringBuilder();
                    sb.append(status.getAccount().getUsername());
                    sb.append(" - ");
                    sb.append(status.getContent().toString());
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
                    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_mute:
                {
                    timelineCases().mute(accountId);
                    return true;
                }
            case R.id.status_block:
                {
                    timelineCases().block(accountId);
                    return true;
                }
            case R.id.status_report:
                {
                    openReportPage(accountId, accountUsename, id, content);
                    return true;
                }
            case R.id.status_delete:
                {
                    timelineCases().delete(id);
                    removeItem(position);
                    return true;
                }
        }
        return false;
    });
    popup.show();
}
Also used : ClipboardManager(android.content.ClipboardManager) Intent(android.content.Intent) Spanned(android.text.Spanned) ClipData(android.content.ClipData) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15