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;
}
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();
}
use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.
the class SeasonsFragment method setCollectedToggleState.
private void setCollectedToggleState(int uncollectedEpisodes) {
collectedAllEpisodes = uncollectedEpisodes == 0;
//noinspection ResourceType
buttonCollectedAll.setImageResource(collectedAllEpisodes ? R.drawable.ic_collected_all : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollectAll));
buttonCollectedAll.setContentDescription(getString(collectedAllEpisodes ? R.string.uncollect_all : R.string.collect_all));
// set onClick listener not before here to avoid unexpected actions
buttonCollectedAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
if (!collectedAllEpisodes) {
popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_ALL_ID, 0, R.string.collect_all);
}
popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_NONE_ID, 0, R.string.uncollect_all);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case CONTEXT_COLLECTED_SHOW_ALL_ID:
{
onFlagShowCollected(true);
Utils.trackAction(getActivity(), TAG, "Flag all collected (inline)");
return true;
}
case CONTEXT_COLLECTED_SHOW_NONE_ID:
{
onFlagShowCollected(false);
Utils.trackAction(getActivity(), TAG, "Flag all uncollected (inline)");
return true;
}
}
return false;
}
});
popupMenu.show();
}
});
}
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();
}
use of android.widget.PopupMenu in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testReply.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testReply() {
viewHolder.itemView.findViewById(R.id.button_more).performClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_comment));
assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class).hasExtra(ComposeActivity.EXTRA_PARENT_ID, "1");
}
Aggregations