Search in sources :

Example 31 with PopupMenu

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

the class BaseListActivityLandTest method testSelectItemOpenStory.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSelectItemOpenStory() {
    assertThat(activity.findViewById(R.id.empty_selection)).isVisible();
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(activity.findViewById(R.id.empty_selection)).isNotVisible();
    assertStoryMode();
    shadowOf(activity).clickMenuItem(R.id.menu_share);
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu()).hasItem(R.id.menu_article).hasItem(R.id.menu_comments);
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    assertNotNull(ShadowPopupMenu.getLatestPopupMenu());
}
Also used : NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) TargetApi(android.annotation.TargetApi)

Example 32 with PopupMenu

use of android.widget.PopupMenu in project Klyph by jonathangerbaud.

the class StreamButtonBar method handleOverflowAction.

private void handleOverflowAction(final IStreamHolder holder, final Stream stream) {
    PopupMenu popup = new PopupMenu(holder.getOverflowButton().getContext(), holder.getOverflowButton());
    if (getCanDelete(stream))
        popup.getMenu().add(Menu.NONE, R.id.menu_delete, Menu.NONE, R.string.delete);
    if (getCanShare(stream))
        popup.getMenu().add(Menu.NONE, R.id.menu_share_with, Menu.NONE, R.string.share_with);
    popup.getMenu().add(Menu.NONE, R.id.menu_view_profile, Menu.NONE, R.string.view_profile);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.menu_delete) {
                handleDeleteAction(holder, stream);
                return true;
            }
            if (id == R.id.menu_share_with) {
                handleShareWithAction(holder, stream);
                return true;
            }
            if (id == R.id.menu_view_profile) {
                handleViewProfileAction(holder, stream);
                return true;
            }
            return false;
        }
    });
    holder.getOverflowButton().setTag(popup);
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu)

Example 33 with PopupMenu

use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.

the class MoviesWatchListFragment method onPopupMenuClick.

@Override
public void onPopupMenuClick(View v, final int movieTmdbId) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.getMenu().add(0, CONTEXT_WATCHLIST_REMOVE_ID, 0, R.string.watchlist_remove);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case CONTEXT_WATCHLIST_REMOVE_ID:
                    {
                        MovieTools.removeFromWatchlist(SgApp.from(getActivity()), movieTmdbId);
                        return true;
                    }
            }
            return false;
        }
    });
    popupMenu.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu)

Example 34 with PopupMenu

use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.

the class CalendarFragment method onItemLongClick.

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) {
    PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
    Menu menu = popupMenu.getMenu();
    Cursor episode = (Cursor) adapter.getItem(position);
    if (episode == null) {
        return false;
    }
    // only display the action appropriate for the items current state
    menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin);
    if (EpisodeTools.isWatched(episode.getInt(CalendarAdapter.Query.WATCHED))) {
        menu.add(0, CONTEXT_FLAG_UNWATCHED_ID, 1, R.string.action_unwatched);
    } else {
        menu.add(0, CONTEXT_FLAG_WATCHED_ID, 1, R.string.action_watched);
    }
    if (EpisodeTools.isCollected(episode.getInt(CalendarAdapter.Query.COLLECTED))) {
        menu.add(0, CONTEXT_COLLECTION_REMOVE_ID, 2, R.string.action_collection_remove);
    } else {
        menu.add(0, CONTEXT_COLLECTION_ADD_ID, 2, R.string.action_collection_add);
    }
    final int showTvdbId = episode.getInt(CalendarAdapter.Query.SHOW_ID);
    final int episodeTvdbId = episode.getInt(CalendarAdapter.Query._ID);
    final int seasonNumber = episode.getInt(CalendarAdapter.Query.SEASON);
    final int episodeNumber = episode.getInt(CalendarAdapter.Query.NUMBER);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case CONTEXT_CHECKIN_ID:
                    {
                        checkInEpisode((int) id);
                        return true;
                    }
                case CONTEXT_FLAG_WATCHED_ID:
                    {
                        updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                        return true;
                    }
                case CONTEXT_FLAG_UNWATCHED_ID:
                    {
                        updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                        return true;
                    }
                case CONTEXT_COLLECTION_ADD_ID:
                    {
                        updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                        return true;
                    }
                case CONTEXT_COLLECTION_REMOVE_ID:
                    {
                        updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                        return true;
                    }
            }
            return false;
        }
    });
    popupMenu.show();
    return true;
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) Cursor(android.database.Cursor) SuppressLint(android.annotation.SuppressLint) PopupMenu(android.widget.PopupMenu)

Example 35 with PopupMenu

use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.

the class EpisodesFragment method onPopupMenuClick.

@Override
public void onPopupMenuClick(View v, final int episodeTvdbId, final int episodeNumber, final long releaseTimeMs, final int watchedFlag, final boolean isCollected) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.episodes_popup_menu);
    Menu menu = popupMenu.getMenu();
    menu.findItem(R.id.menu_action_episodes_collection_add).setVisible(!isCollected);
    menu.findItem(R.id.menu_action_episodes_collection_remove).setVisible(isCollected);
    boolean isWatched = EpisodeTools.isWatched(watchedFlag);
    menu.findItem(R.id.menu_action_episodes_watched).setVisible(!isWatched);
    menu.findItem(R.id.menu_action_episodes_not_watched).setVisible(isWatched);
    boolean isSkipped = EpisodeTools.isSkipped(watchedFlag);
    menu.findItem(R.id.menu_action_episodes_skip).setVisible(!isWatched && !isSkipped);
    menu.findItem(R.id.menu_action_episodes_dont_skip).setVisible(isSkipped);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.menu_action_episodes_watched:
                    {
                        onFlagEpisodeWatched(episodeTvdbId, episodeNumber, true);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag watched");
                        return true;
                    }
                case R.id.menu_action_episodes_not_watched:
                    {
                        onFlagEpisodeWatched(episodeTvdbId, episodeNumber, false);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag unwatched");
                        return true;
                    }
                case R.id.menu_action_episodes_collection_add:
                    {
                        onFlagEpisodeCollected(episodeTvdbId, episodeNumber, true);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag collected");
                        return true;
                    }
                case R.id.menu_action_episodes_collection_remove:
                    {
                        onFlagEpisodeCollected(episodeTvdbId, episodeNumber, false);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag uncollected");
                        return true;
                    }
                case R.id.menu_action_episodes_skip:
                    {
                        onFlagEpisodeSkipped(episodeTvdbId, episodeNumber, true);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag skipped");
                        return true;
                    }
                case R.id.menu_action_episodes_dont_skip:
                    {
                        onFlagEpisodeSkipped(episodeTvdbId, episodeNumber, false);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag not skipped");
                        return true;
                    }
                case R.id.menu_action_episodes_watched_previous:
                    {
                        onMarkUntilHere(releaseTimeMs);
                        Utils.trackContextMenu(getActivity(), TAG, "Flag previously aired");
                        return true;
                    }
                case R.id.menu_action_episodes_manage_lists:
                    {
                        ManageListsDialogFragment.showListsDialog(episodeTvdbId, ListItemTypes.EPISODE, getFragmentManager());
                        Utils.trackContextMenu(getActivity(), TAG, "Manage lists");
                        return true;
                    }
            }
            return false;
        }
    });
    popupMenu.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(android.widget.PopupMenu)

Aggregations

PopupMenu (android.widget.PopupMenu)99 MenuItem (android.view.MenuItem)60 View (android.view.View)44 TextView (android.widget.TextView)41 ImageView (android.widget.ImageView)30 RecyclerView (android.support.v7.widget.RecyclerView)22 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Intent (android.content.Intent)14 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 MenuInflater (android.view.MenuInflater)10 AdapterView (android.widget.AdapterView)10 ListView (android.widget.ListView)10 Menu (android.view.Menu)9 NonNull (android.support.annotation.NonNull)8