List of usage examples for android.widget PopupMenu PopupMenu
public PopupMenu(Context context, View anchor)
From source file:com.aniruddhc.acemusic.player.NowPlayingActivity.PlaylistPagerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContext = getActivity();/* w w w . j ava 2s . c o m*/ mApp = (Common) mContext.getApplicationContext(); mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_playlist_pager_fill, container, false); mPosition = getArguments().getInt("POSITION"); overflowIcon = (ImageView) mRootView.findViewById(R.id.now_playing_overflow_icon); coverArt = (ImageView) mRootView.findViewById(R.id.coverArt); bottomDarkPatch = (RelativeLayout) mRootView.findViewById(R.id.bottomDarkPatch); songInfoLayout = (RelativeLayout) mRootView.findViewById(R.id.songInfoLayout); songNameTextView = (TextView) mRootView.findViewById(R.id.songName); artistAlbumNameTextView = (TextView) mRootView.findViewById(R.id.artistAlbumName); mLyricsScrollView = (ScrollView) mRootView.findViewById(R.id.lyrics_scroll_view); mLyricsTextView = (TextView) mRootView.findViewById(R.id.lyrics); mLyricsEmptyTextView = (TextView) mRootView.findViewById(R.id.lyrics_empty); mLyricsTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular")); mLyricsEmptyTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular")); songNameTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular")); artistAlbumNameTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular")); //Allow the TextViews to scroll if they extend beyond the layout margins. songNameTextView.setSelected(true); artistAlbumNameTextView.setSelected(true); //Initialize the pop up menu. popup = new PopupMenu(getActivity(), overflowIcon); popup.getMenuInflater().inflate(R.menu.now_playing_overflow_menu, popup.getMenu()); popup.setOnMenuItemClickListener(menuItemClickListener); mSongHelper = new SongHelper(); mSongHelper.setAlbumArtLoadedListener(this); if (mApp.getOrientation() == Common.ORIENTATION_LANDSCAPE) mSongHelper.populateSongData(mContext, mPosition); else mSongHelper.populateSongData(mContext, mPosition, new PicassoMirrorReflectionTransformer()); songNameTextView.setText(mSongHelper.getTitle()); artistAlbumNameTextView.setText(mSongHelper.getAlbum() + " - " + mSongHelper.getArtist()); overflowIcon.setOnClickListener(overflowClickListener); //Kitkat padding. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int navigationBarHeight = Common.getNavigationBarHeight(mContext); int bottomPadding = songInfoLayout.getPaddingBottom(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) bottomDarkPatch.getLayoutParams(); if (navigationBarHeight > 0) { /* The nav bar already has padding, so remove the extra 15dp * padding that was applied in the layout file. */ int marginPixelsValue = (int) mApp.convertDpToPixels(15, mContext); bottomPadding -= marginPixelsValue; params.height -= marginPixelsValue; } bottomPadding += navigationBarHeight; songInfoLayout.setPadding(0, 0, 0, bottomPadding); params.height += navigationBarHeight; bottomDarkPatch.setLayoutParams(params); } return mRootView; }
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 ww w.j a va 2s . com*/ 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:org.hawkular.client.android.fragment.FavTriggersFragment.java
private void showTriggerMenu(final View triggerView, final int triggerPosition) { PopupMenu triggerMenu = new PopupMenu(getActivity(), triggerView); triggerMenu.getMenuInflater().inflate(R.menu.popup_delete, triggerMenu.getMenu()); triggerMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// ww w . j a v a 2 s . c om public boolean onMenuItemClick(MenuItem menuItem) { Trigger trigger = getTriggersAdapter().getItem(triggerPosition); switch (menuItem.getItemId()) { case R.id.menu_delete: Context context = getActivity(); SQLStore<Trigger> store = openStore(context); store.openSync(); store.remove(trigger.getId()); onRefresh(); return true; default: return false; } } }); triggerMenu.show(); }
From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_chart_choice, container, false); // Register to the EventBus EventBus.getDefault().register(this); listViewSensor = (ListView) view.findViewById(R.id.listViewSensors); mLinearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutDateSelectionItems); mTextView = (TextView) view.findViewById(R.id.textViewUsername); spinnerDate = (Spinner) view.findViewById(R.id.spinnerDate); spinnerFrequency = (Spinner) view.findViewById(R.id.spinnerFrequency); spinnerPrecision = (Spinner) view.findViewById(R.id.spinnerPrecision); seekBar = (SeekBar) view.findViewById(R.id.seekBar); seekBarPosition = 0;/*from w ww . jav a 2 s . c o m*/ seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { // Called when the slider moves to another value @Override public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) { seekBarPosition = progresValue; } // Called when you start moving the slider @Override public void onStartTrackingTouch(SeekBar seekBar) { } // Called when it seems that you are done moving the slider @Override public void onStopTrackingTouch(SeekBar seekBar) { // Tell ChartViewFragment to update the graph EventBus.getDefault().post(new UpdateMovingAverageEvent(seekBarPosition)); } }); listViewSensor.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { lastLongClickItem = position; PopupMenu popup = new PopupMenu(mActivity, view); popup.inflate(R.menu.menu_sensor_dropdown); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_delete_sensor: if (!MiscFunctions.isOnline(mActivity)) { MiscFunctions.makeOfflineDialog(mActivity).show(); return false; } deleteSensor(lastLongClickItem); break; case R.id.action_edit_sensor: if (!MiscFunctions.isOnline(mActivity)) { MiscFunctions.makeOfflineDialog(mActivity).show(); return false; } editSensor(lastLongClickItem); break; } return false; } }); popup.show(); return false; } }); return view; }
From source file:org.hawkular.client.android.fragment.FavMetricsFragment.java
private void showMetricMenu(final View metricView, final int metricPosition) { PopupMenu metricMenu = new PopupMenu(getActivity(), metricView); metricMenu.getMenuInflater().inflate(R.menu.popup_delete, metricMenu.getMenu()); metricMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*from www . ja v a2 s . co m*/ public boolean onMenuItemClick(MenuItem menuItem) { Metric metric = getFavMetricsAdapter().getItem(metricPosition); switch (menuItem.getItemId()) { case R.id.menu_delete: Context context = getActivity(); SQLStore<Metric> store = openStore(context); store.openSync(); store.remove(metric.getId()); onRefresh(); return true; default: return false; } } }); metricMenu.show(); }
From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessIfaceTile.java
public WirelessIfaceTile(@NotNull String iface, @Nullable String parentIface, @NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) { super(parentFragment, arguments, router, R.layout.tile_status_wireless_iface, R.id.tile_status_wireless_iface_togglebutton); this.iface = iface; this.parentIface = parentIface; ((TextView) this.layout.findViewById(R.id.tile_status_wireless_iface_title)).setText(this.iface); //Create Options Menu final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_status_wireless_iface_menu); final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid()); if (!isThemeLight) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); }/*from w w w . j a v a 2 s . c o m*/ tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(WirelessIfaceTile.this); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_wireless_iface_options, menu); if (wifiEncryptionType == null || (isNullOrEmpty(wifiSsid) && isNullOrEmpty(wifiPassword))) { menu.findItem(R.id.tile_status_wireless_iface_qrcode).setEnabled(false); } 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 .ja v a 2 s.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:com.ultramegasoft.flavordex2.fragment.PhotoFragment.java
/** * Show the PopupMenu for the photo./*from www.j av a 2 s .c o m*/ * * @param v The View to attach the menu to */ private void showMenu(@NonNull View v) { final PopupMenu popupMenu = new PopupMenu(getContext(), v); popupMenu.setOnMenuItemClickListener(this); popupMenu.inflate(R.menu.photo_menu); popupMenu.show(); }
From source file:com.tcity.android.ui.overview.project.ProjectOverviewActivity.java
void projectOptionsClick(@NotNull String id, @NotNull View anchor) { PopupMenu menu = new PopupMenu(this, anchor); menu.inflate(R.menu.menu_concept);/*from www .jav a 2s . c om*/ menu.setOnMenuItemClickListener(new PopupMenuListener(WebLocator.getProjectUrl(id, new Preferences(this)))); menu.show(); }
From source file:com.tcity.android.ui.overview.buildconfiguration.BuildConfigurationOverviewActivity.java
void optionsClick(@NotNull String id, @NotNull View anchor) { PopupMenu menu = new PopupMenu(this, anchor); menu.inflate(R.menu.menu_concept);//ww w .ja v a2 s. c o m menu.setOnMenuItemClickListener(new PopupMenuListener(WebLocator.getBuildUrl(id, new Preferences(this)))); menu.show(); }