List of usage examples for android.widget PopupMenu setOnMenuItemClickListener
public void setOnMenuItemClickListener(OnMenuItemClickListener listener)
From source file:com.battlelancer.seriesguide.ui.EpisodesFragment.java
@Override public void onPopupMenuClick(View v, final int episodeTvdbId, final int episodeNumber, final long releaseTimeMs, final boolean isWatched, 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_watched).setVisible(!isWatched); menu.findItem(R.id.menu_action_episodes_not_watched).setVisible(isWatched); menu.findItem(R.id.menu_action_episodes_collection_add).setVisible(!isCollected); menu.findItem(R.id.menu_action_episodes_collection_remove).setVisible(isCollected); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from ww w. ja va 2s. c o m public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_action_episodes_watched: { onFlagEpisodeWatched(episodeTvdbId, episodeNumber, true); fireTrackerEventContextMenu("Flag watched"); return true; } case R.id.menu_action_episodes_not_watched: { onFlagEpisodeWatched(episodeTvdbId, episodeNumber, false); fireTrackerEventContextMenu("Flag unwatched"); return true; } case R.id.menu_action_episodes_collection_add: { onFlagEpisodeCollected(episodeTvdbId, episodeNumber, true); fireTrackerEventContextMenu("Flag collected"); return true; } case R.id.menu_action_episodes_collection_remove: { onFlagEpisodeCollected(episodeTvdbId, episodeNumber, false); fireTrackerEventContextMenu("Flag uncollected"); return true; } case R.id.menu_action_episodes_watched_previous: { onMarkUntilHere(releaseTimeMs); fireTrackerEventContextMenu("Flag previously aired"); return true; } case R.id.menu_action_episodes_manage_lists: { ManageListsDialogFragment.showListsDialog(episodeTvdbId, ListItemTypes.EPISODE, getFragmentManager()); fireTrackerEventContextMenu("Manage lists"); return true; } } return false; } }); popupMenu.show(); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_addChannel_youtube(final View anchor) { PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_addchannel_youtube, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* ww w .j a v a2s . com*/ public boolean onMenuItemClick(MenuItem item) { onOpt_addChannel_youtubeEditDiag(item); return true; } }); popup.show(); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_category(final View anchor) { PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_category, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* ww w. j a v a2 s . c o m*/ public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.add: onOpt_category_add(anchor); break; case R.id.rename: onOpt_category_rename(anchor); break; case R.id.delete: onOpt_category_delete(anchor); break; default: eAssert(false); } return true; } }); popup.show(); }
From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java
private void setWatchedToggleState(int unwatchedEpisodes) { mWatchedAllEpisodes = unwatchedEpisodes == 0; mButtonWatchedAll.setImageResource(mWatchedAllEpisodes ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatchedAll) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatchAll)); // set onClick listener not before here to avoid unexpected actions mButtonWatchedAll.setOnClickListener(new OnClickListener() { @Override/*from ww w .j av a 2s . c o m*/ public void onClick(View v) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); if (mWatchedAllEpisodes) { popupMenu.getMenu().add(0, CONTEXT_WATCHED_SHOW_NONE_ID, 0, R.string.unmark_all); } else { popupMenu.getMenu().add(0, CONTEXT_WATCHED_SHOW_ALL_ID, 0, R.string.mark_all); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_WATCHED_SHOW_ALL_ID: { onFlagShowWatched(true); fireTrackerEvent("Flag all watched (inline)"); return true; } case CONTEXT_WATCHED_SHOW_NONE_ID: { onFlagShowWatched(false); fireTrackerEvent("Flag all unwatched (inline)"); return true; } } return false; } }); popupMenu.show(); } }); CheatSheet.setup(mButtonWatchedAll, mWatchedAllEpisodes ? R.string.unmark_all : R.string.mark_all); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_moreMenu(final View anchor) { PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_more_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*from w w w. j av a 2 s. c om*/ public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.about: onOpt_moreMenu_about(anchor); break; case R.id.license: onOpt_moreMenu_license(anchor); break; case R.id.media_delete_all: onOpt_moreMenu_deleteAllDnFiles(anchor); break; case R.id.media_delete_used_all: onOpt_moreMenu_deleteAllUsedDnFiles(anchor); break; case R.id.feedback_opinion: onOpt_moreMenu_feedbackOpinion(anchor); break; case R.id.db_management: onOpt_moreMenu_dbManagement(anchor); break; default: eAssert(false); } return true; } }); popup.show(); }
From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java
private void setCollectedToggleState(int uncollectedEpisodes) { mCollectedAllEpisodes = uncollectedEpisodes == 0; mButtonCollectedAll.setImageResource(mCollectedAllEpisodes ? R.drawable.ic_collected_all : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollectAll)); // set onClick listener not before here to avoid unexpected actions mButtonCollectedAll.setOnClickListener(new OnClickListener() { @Override/*from www . j a v a 2s . com*/ public void onClick(View v) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); if (mCollectedAllEpisodes) { popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_NONE_ID, 0, R.string.uncollect_all); } else { popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_ALL_ID, 0, R.string.collect_all); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_COLLECTED_SHOW_ALL_ID: { onFlagShowCollected(true); fireTrackerEvent("Flag all collected (inline)"); return true; } case CONTEXT_COLLECTED_SHOW_NONE_ID: { onFlagShowCollected(false); fireTrackerEvent("Flag all uncollected (inline)"); return true; } } return false; } }); popupMenu.show(); } }); CheatSheet.setup(mButtonCollectedAll, mCollectedAllEpisodes ? R.string.uncollect_all : R.string.collect_all); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_addChannel(final View anchor) { if (0 == mAb.getNavigationItemCount()) { eAssert(false);//from ww w. j a v a 2 s.c om return; } if (0 > mAb.getSelectedNavigationIndex()) { UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_select_category_to_add); return; } if (!Utils.isNetworkAvailable()) { // TODO Handling error UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_network_unavailable); return; } PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_addchannel, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.predefined: onOpt_addChannel_predefined(anchor); break; case R.id.url: onOpt_addChannel_url(anchor); break; case R.id.youtube: onOpt_addChannel_youtube(anchor); break; default: eAssert(false); } return true; } }); popup.show(); }
From source file:org.catnut.adapter.TweetAdapter.java
private void showPopupMenu(View view) { final Bean bean = (Bean) view.getTag(); PopupMenu popup = new PopupMenu(mContext, view); Menu menu = popup.getMenu();//from ww w .java2 s . co m popup.getMenuInflater().inflate(R.menu.tweet_overflow, menu); MenuItem item = menu.findItem(R.id.action_favorite); item.setTitle(bean.favorited ? R.string.cancle_favorite : R.string.favorite); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_favorite: mRequestQueue.add(new CatnutRequest(mContext, bean.favorited ? FavoritesAPI.destroy(bean.id) : FavoritesAPI.create(bean.id), new StatusProcessor.FavoriteTweetProcessor(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(mContext, bean.favorited ? R.string.cancle_favorite_success : R.string.favorite_success, Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error); Toast.makeText(mContext, weiboAPIError.error, Toast.LENGTH_LONG).show(); } })); break; case R.id.action_like: Toast.makeText(mContext, "sina not provide this option...", Toast.LENGTH_SHORT).show(); break; case android.R.id.copy: CatnutUtils.copy2ClipBoard(mContext, mContext.getString(R.string.tweet), bean.text, mContext.getString(R.string.tweet_text_copied)); break; default: break; } return false; } }); popup.show(); }
From source file:edu.usf.cutr.opentripplanner.android.fragments.DirectionListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ImageButton btnDisplayMap = (ImageButton) header.findViewById(R.id.btnDisplayMap); ImageButton btnShareDirections = (ImageButton) header.findViewById(R.id.btnShareDirections); ImageButton btnAlarmDirections = (ImageButton) header.findViewById(R.id.btnAlarmDirections); final OtpFragment ofl = this.getFragmentListener(); final DirectionListFragment dlf = this; OnClickListener oclDisplayDirection = new OnClickListener() { @Override/*from w ww.j ava2s . c om*/ public void onClick(View arg0) { ofl.onSwitchedToMainFragment(dlf); } }; btnDisplayMap.setOnClickListener(oclDisplayDirection); btnShareDirections.setOnClickListener(new OnClickListener() { public void onClick(View v) { // create popup menu View menuItemView = getView().findViewById(R.id.btnShareDirections); PopupMenu popup = new PopupMenu(getActivity(), menuItemView); popup.getMenuInflater().inflate(R.menu.share_menu, popup.getMenu()); menuItemView.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popup)); //registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent itn = new Intent(); itn.setAction(Intent.ACTION_SEND); itn.setType("text/plain"); // fill intend content based on chosen menu item switch (item.getItemId()) { case R.id.btnShareDirectionsShort: itn.putExtra(Intent.EXTRA_TEXT, getDepartureArrivalHeaders(false)); break; case R.id.btnShareDirectionsDetailed: itn.putExtra(Intent.EXTRA_TEXT, getDepartureArrivalHeaders(true)); break; default: break; } startActivity(Intent.createChooser(itn, "Share via")); return true; } }); popup.show(); } }); btnAlarmDirections.setOnClickListener(new OnClickListener() { public void onClick(View v) { // create popup menu View menuItemView = getView().findViewById(R.id.btnAlarmDirections); PopupMenu popup = new PopupMenu(getActivity(), menuItemView); popup.getMenuInflater().inflate(R.menu.alarm_menu, popup.getMenu()); menuItemView.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popup)); //registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.btnAlarmDirectionsAlarm: setAlarmItinerary(); break; case R.id.btnAlarmDirectionsNotifications: setNotificationsItinerary(); break; case R.id.btnAlarmDirectionsCalendar: setCalendarItinerary(); break; default: break; } return true; } }); popup.show(); } }); fromHeader = (TextView) header.findViewById(R.id.fromHeader); toHeader = (TextView) header.findViewById(R.id.toHeader); departureTimeHeader = (TextView) header.findViewById(R.id.departureTimeHeader); arrivalTimeHeader = (TextView) header.findViewById(R.id.arrivalTimeHeader); tripList = (Spinner) header.findViewById(R.id.itinerarySelection); if (savedInstanceState != null) { otpBundle = (OTPBundle) savedInstanceState.getSerializable(OTPApp.BUNDLE_KEY_OTP_BUNDLE); fragmentListener.setOTPBundle(otpBundle); } else { otpBundle = fragmentListener.getOTPBundle(); } fromHeader.setText(otpBundle.getFromText()); toHeader.setText(otpBundle.getToText()); setDepartureArrivalHeaders(); ArrayList<Leg> currentItinerary = new ArrayList<Leg>(); currentItinerary.addAll(fragmentListener.getCurrentItinerary()); ArrayList<Itinerary> itineraryList = new ArrayList<Itinerary>(); itineraryList.addAll(fragmentListener.getCurrentItineraryList()); int currentItineraryIndex = fragmentListener.getCurrentItineraryIndex(); ArrayList<Direction> directions = new ArrayList<Direction>(); DirectionsGenerator dirGen = new DirectionsGenerator(currentItinerary, getActivity().getApplicationContext()); ArrayList<Direction> tempDirections = dirGen.getDirections(); if (tempDirections != null && !tempDirections.isEmpty()) { directions.addAll(tempDirections); } final Activity activity = this.getActivity(); String[] itinerarySummaryList = new String[itineraryList.size()]; boolean isTransitIsTagSet = false; for (int i = 0; i < itinerarySummaryList.length; i++) { isTransitIsTagSet = false; Itinerary it = itineraryList.get(i); for (Leg leg : it.legs) { TraverseMode traverseMode = TraverseMode.valueOf(leg.mode); if (traverseMode.isTransit()) { itinerarySummaryList[i] = ConversionUtils.getRouteShortNameSafe(leg.routeShortName, leg.routeLongName, getActivity().getApplicationContext()) + ". "; isTransitIsTagSet = true; break; } } if (!isTransitIsTagSet) { itinerarySummaryList[i] = Integer.toString(i + 1) + ". ";//Shown index is i + 1, to use 1-based indexes for the UI instead of 0-based } } for (int i = 0; i < itinerarySummaryList.length; i++) { Itinerary it = itineraryList.get(i); long tripDuration; if (PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()) .getInt(OTPApp.PREFERENCE_KEY_API_VERSION, OTPApp.API_VERSION_V1) == OTPApp.API_VERSION_V1) { tripDuration = it.duration; } else { tripDuration = it.duration / 1000; } itinerarySummaryList[i] += getString(R.string.step_by_step_total_duration) + " " + ConversionUtils .getFormattedDurationTextNoSeconds(tripDuration, false, getActivity().getApplicationContext()); if (isTransitIsTagSet) { itinerarySummaryList[i] += " " + getString(R.string.step_by_step_walking_duration) + " " + ConversionUtils.getFormattedDurationTextNoSeconds(it.walkTime, false, getActivity().getApplicationContext()); } } ArrayAdapter<String> itineraryAdapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, itinerarySummaryList); itineraryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); tripList.setAdapter(itineraryAdapter); AdapterView.OnItemSelectedListener itinerarySpinnerListener = new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (fragmentListener.getCurrentItineraryIndex() != position) { fragmentListener.onItinerarySelected(position, 3); } setDepartureArrivalHeaders(); if (!isFragmentFirstLoad) { ArrayList<Direction> directions = new ArrayList<Direction>(); DirectionsGenerator dirGen = new DirectionsGenerator(fragmentListener.getCurrentItinerary(), getActivity().getApplicationContext()); ArrayList<Direction> tempDirections = dirGen.getDirections(); if (tempDirections != null && !tempDirections.isEmpty()) { directions.addAll(tempDirections); } Direction direction_data[] = directions.toArray(new Direction[directions.size()]); DirectionExpandableListAdapter adapter = new DirectionExpandableListAdapter( DirectionListFragment.this.getActivity(), R.layout.list_direction_item, R.layout.list_subdirection_item, direction_data); elv.setAdapter(adapter); } openIfNonTransit(); isFragmentFirstLoad = false; } @Override public void onNothingSelected(AdapterView<?> parent) { } }; tripList.setSelection(currentItineraryIndex); tripList.setOnItemSelectedListener(itinerarySpinnerListener); // Populate list with our static array of titles. elv = getExpandableListView(); Direction direction_data[] = directions.toArray(new Direction[directions.size()]); DirectionExpandableListAdapter adapter = new DirectionExpandableListAdapter(this.getActivity(), R.layout.list_direction_item, R.layout.list_subdirection_item, direction_data); elv.addHeaderView(header); elv.setAdapter(adapter); elv.setGroupIndicator(null); // Get rid of the down arrow openIfNonTransit(); if (savedInstanceState == null) { if (otpBundle.isFromInfoWindow()) { elv.expandGroup(otpBundle.getCurrentStepIndex()); elv.setSelectedGroup(otpBundle.getCurrentStepIndex()); otpBundle.setFromInfoWindow(false); } } }
From source file:com.inde.shiningdays.MainActivity.java
private void showPopupMenu() { final View menuItemView = findViewById(R.id.action_menumore); // SAME ID AS MENU ID PopupMenu popupMenu = new PopupMenu(this, menuItemView); popupMenu.inflate(R.menu.more_popup_menu); String currentSortRule = getCurrentSortRule(); if (CountDown.SORT_END_DATE_ASC.equals(currentSortRule)) { popupMenu.getMenu().findItem(R.id.sort_end_date_asc).setChecked(true); } else if (CountDown.DEFAULT_SORT_ORDER.equals(currentSortRule)) { popupMenu.getMenu().findItem(R.id.sort_update_date_desc).setChecked(true); }//from w w w .j av a 2s. com popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { String rule = ""; switch (item.getItemId()) { case R.id.sort_end_date_asc: rule = CountDown.SORT_END_DATE_ASC; updateCurrentSortRule(rule); selectItem(currentTypePosition, rule); return true; case R.id.sort_update_date_desc: rule = CountDown.DEFAULT_SORT_ORDER; updateCurrentSortRule(rule); selectItem(currentTypePosition, rule); return true; case R.id.action_setting: Intent intent = new Intent(menuItemView.getContext(), MenuMore.class); startActivity(intent); default: return true; } } }); popupMenu.show(); }