Search in sources :

Example 1 with PopupMenu

use of android.support.v7.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testSaveItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSaveItem() {
    ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_save).isVisible()).isFalse();
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_save));
    verify(favoriteManager).add(any(Context.class), eq(item));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
    assertTrue(item.isFavorite());
    View snackbarView = ShadowSnackbar.getLatestView();
    assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_saved);
    snackbarView.findViewById(R.id.snackbar_action).performClick();
    verify(favoriteManager).remove(any(Context.class), eq("1"));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
    assertFalse(item.isFavorite());
}
Also used : Context(android.content.Context) ShadowContentObserver(org.robolectric.shadows.ShadowContentObserver) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 2 with PopupMenu

use of android.support.v7.widget.PopupMenu in project remusic by aa112901.

the class MainFragmentAdapter method setOnPlaylistListener.

private void setOnPlaylistListener(ItemHolder itemHolder, final int position, final long playlistid, final String albumArt, final String playlistname) {
    itemHolder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    Intent intent = new Intent(mContext, PlaylistActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    intent.putExtra("islocal", true);
                    intent.putExtra("playlistid", playlistid + "");
                    intent.putExtra("albumart", albumArt);
                    intent.putExtra("playlistname", playlistname);
                    mContext.startActivity(intent);
                }
            }, 60);
        }
    });
    itemHolder.menu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popupMenu = new PopupMenu(mContext, v);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (position == 5) {
                        Toast.makeText(mContext, "此歌单不应删除", Toast.LENGTH_SHORT).show();
                    } else {
                        new AlertDialog.Builder(mContext).setTitle(mContext.getString(R.string.sure_to_delete_music)).setPositiveButton(mContext.getString(R.string.sure), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                PlaylistInfo.getInstance(mContext).deletePlaylist(playlistid);
                                PlaylistsManager.getInstance(mContext).delete(playlistid);
                                Intent intent = new Intent();
                                intent.setAction(IConstants.PLAYLIST_COUNT_CHANGED);
                                mContext.sendBroadcast(intent);
                                dialog.dismiss();
                            }
                        }).setNegativeButton(mContext.getString(R.string.cancel), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).show();
                    }
                    return true;
                }
            });
            popupMenu.inflate(R.menu.popmenu);
            popupMenu.show();
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) Handler(android.os.Handler) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) TintImageView(com.bilibili.magicasakura.widgets.TintImageView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.support.v7.widget.PopupMenu)

Example 3 with PopupMenu

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

the class SFragment method more.

protected void more(final Status status, View view, final AdapterItemRemover adapter, final int position) {
    final String id = status.getActionableId();
    final String accountId = status.getActionableStatus().account.id;
    final String accountUsename = status.getActionableStatus().account.username;
    final Spanned content = status.getActionableStatus().content;
    final String statusUrl = status.getActionableStatus().url;
    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(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.status_share_content:
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.append(status.account.username);
                        sb.append(" - ");
                        sb.append(status.content.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_mute:
                    {
                        mute(accountId);
                        return true;
                    }
                case R.id.status_block:
                    {
                        block(accountId);
                        return true;
                    }
                case R.id.status_report:
                    {
                        openReportPage(accountId, accountUsename, id, content);
                        return true;
                    }
                case R.id.status_delete:
                    {
                        delete(id);
                        adapter.removeItem(position);
                        return true;
                    }
            }
            return false;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Intent(android.content.Intent) Spanned(android.text.Spanned) PopupMenu(android.support.v7.widget.PopupMenu)

Example 4 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DashboardAdapter method showRemoveOption.

private void showRemoveOption(View v, final Tile suggestion) {
    PopupMenu popup = new PopupMenu(new ContextThemeWrapper(mContext, R.style.Theme_AppCompat_DayNight), v);
    popup.getMenu().add(R.string.suggestion_remove).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            MetricsLogger.action(mContext, MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION, DashboardAdapter.getSuggestionIdentifier(mContext, suggestion));
            disableSuggestion(suggestion);
            mSuggestions.remove(suggestion);
            recountItems();
            return true;
        }
    });
    popup.show();
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) MenuItem(android.view.MenuItem) PopupMenu(android.support.v7.widget.PopupMenu)

Example 5 with PopupMenu

use of android.support.v7.widget.PopupMenu in project RxBinding by JakeWharton.

the class RxPopupMenuTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View anchor = new View(this);
    setContentView(anchor);
    popupMenu = new PopupMenu(this, anchor);
}
Also used : View(android.view.View) 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