List of usage examples for android.widget PopupMenu PopupMenu
public PopupMenu(Context context, View anchor)
From source file:osm.custommaps.create.PreviewMapActivity.java
private void prepareUI() { saveButton = (Button) findViewById(R.id.save); mapModeButton = (ImageButton) findViewById(R.id.mapmode); transparencyBar = (SeekBar) findViewById(R.id.transparencyBar); saveButton.setOnClickListener(new View.OnClickListener() { @Override// w w w . java 2s . c om public void onClick(View v) { computeAndReturnTiepoints(); } }); mapModeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { PopupMenu popupMenu = new PopupMenu(getApplicationContext(), view); popupMenu.inflate(R.menu.menu_options); popupMenu.show(); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.toString()) { case "Google Satellite": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.GOOGLE_SATELLITE); break; case "Google Maps": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.GOOGLE_MAPS); break; case "Google Terrain": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.GOOGLE_TERRAIN); break; case "Bing Maps": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.BING_MAPS); break; case "Bing Earth": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.BING_EARTH); break; case "Bing Hybrid": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.BING_HYBRID); break; case "Mapquest Aerial": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.MAPQUESTAERIAL_US); break; case "Mapquest OSM": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.MAPQUESTOSM); break; case "Mapnik": mapView.invalidate(); mapView.setMaxZoomLevel(20); mapView.setMinZoomLevel(3); mapView.setTileSource(WMSTileSourceFactory.MAPNIK); break; } return false; } }); } }); transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { private void updateImageOverlay(int value) { imageOverlay.setTransparency(value); mapView.invalidate(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { updateImageOverlay(seekBar.getProgress()); } @Override public void onStartTrackingTouch(SeekBar seekBar) { updateImageOverlay(seekBar.getProgress()); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { updateImageOverlay(seekBar.getProgress()); } } }); }
From source file:net.nakama.duckdroid.ui.Duckdroid.java
public void btnshowPopupSetting(View view) { PopupMenu popup = new PopupMenu(this, view); MenuInflater inflater = popup.getMenuInflater(); popup.setOnMenuItemClickListener(this); inflater.inflate(R.menu.activity_duckdroid, popup.getMenu()); popup.show();//from www.ja va 2s .c om }
From source file:com.syncedsynapse.kore2.ui.NowPlayingFragment.java
@OnClick(R.id.overflow) public void onOverflowClicked(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); popup.inflate(R.menu.video_overflow); popup.setOnMenuItemClickListener(overflowMenuClickListener); popup.show();// w ww.ja v a 2 s.co m }
From source file:nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment.java
public boolean openPopupMenu(View view, int position) { PopupMenu popupMenu = new PopupMenu(getContext(), view); popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu()); Menu menu = popupMenu.getMenu(); final GBDeviceApp selectedApp = appList.get(position); if (!selectedApp.isInCache()) { menu.removeItem(R.id.appmanager_app_reinstall); menu.removeItem(R.id.appmanager_app_delete_cache); }/* www . ja va 2 s .c om*/ if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) { menu.removeItem(R.id.appmanager_health_activate); menu.removeItem(R.id.appmanager_health_deactivate); } if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) { menu.removeItem(R.id.appmanager_hrm_activate); menu.removeItem(R.id.appmanager_hrm_deactivate); } if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) { menu.removeItem(R.id.appmanager_weather_activate); menu.removeItem(R.id.appmanager_weather_deactivate); menu.removeItem(R.id.appmanager_weather_install_provider); } if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) { menu.removeItem(R.id.appmanager_app_delete); } if (!selectedApp.isConfigurable()) { menu.removeItem(R.id.appmanager_app_configure); } if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) { PackageManager pm = getActivity().getPackageManager(); try { pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES); menu.removeItem(R.id.appmanager_weather_install_provider); } catch (PackageManager.NameNotFoundException e) { menu.removeItem(R.id.appmanager_weather_activate); menu.removeItem(R.id.appmanager_weather_deactivate); } } switch (selectedApp.getType()) { case WATCHFACE: case APP_GENERIC: case APP_ACTIVITYTRACKER: break; default: menu.removeItem(R.id.appmanager_app_openinstore); } //menu.setHeaderTitle(selectedApp.getName()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { return onContextItemSelected(item, selectedApp); } }); view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); popupMenu.show(); return true; }
From source file:com.cw.litenote.note.NoteUi.java
/** * Set picture view listeners//from w ww. j a va 2s. co m * @param act * @param pager * @param strPicture * @param linkUri * @param viewGroup */ private void setPictureView_listeners(final AppCompatActivity act, final ViewPager pager, final String strPicture, final String linkUri, ViewGroup viewGroup) { System.out.println("NoteUi / setPictureView_listeners"); Button picView_back_button = (Button) (viewGroup.findViewById(R.id.image_view_back)); Button picView_viewMode_button = (Button) (viewGroup.findViewById(R.id.image_view_mode)); Button picView_previous_button = (Button) (viewGroup.findViewById(R.id.image_view_previous)); Button picView_next_button = (Button) (viewGroup.findViewById(R.id.image_view_next)); Button mVideoPlayButton = (Button) (viewGroup.findViewById(R.id.video_view_play_video)); final TextView videoView_currPosition = (TextView) (viewGroup.findViewById(R.id.video_current_pos)); SeekBar videoView_seekBar = (SeekBar) (viewGroup.findViewById(R.id.video_seek_bar)); // Set video play button listener if (UtilVideo.hasVideoExtension(strPicture, act)) { mVideoPlayButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { System.out.println("NoteUi / setPictureView_listeners / mVideoPlayButton / getVideoState() = " + UtilVideo.getVideoState()); if ((BackgroundAudioService.mMediaPlayer != null) && (Audio_manager.getPlayerState() != Audio_manager.PLAYER_AT_STOP) && (UtilVideo.getVideoState() != UtilVideo.VIDEO_AT_PLAY)) { // Dialog: confirm to disable audio or not AlertDialog.Builder builder = new AlertDialog.Builder(act); builder.setTitle(R.string.title_playing_audio).setMessage(R.string.message_continue_or_stop) .setPositiveButton(R.string.btn_Stop, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Audio_manager.stopAudioPlayer(); UtilVideo.changeVideoState(); UtilVideo.playOrPauseVideo(pager, strPicture); } }).setNegativeButton(R.string.btn_Continue, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { UtilVideo.changeVideoState(); UtilVideo.playOrPauseVideo(pager, strPicture); } }).show(); } else { UtilVideo.changeVideoState(); UtilVideo.playOrPauseVideo(pager, strPicture); updateVideoPlayButtonState(pager, getFocus_notePos()); } } }); } else if (Util.isYouTubeLink(linkUri)) { mVideoPlayButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_media_play, 0, 0, 0); mVideoPlayButton.setVisibility(View.VISIBLE); // set listener for running YouTube mVideoPlayButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { System.out.println( "NoteUi / _setPictureView_listeners / onClick to play YouTube / linkUri = " + linkUri); // apply native YouTube // Util.openLink_YouTube(act, linkUri); // apply YouTube DATA API for note view Intent intent = new Intent(act, YouTubePlayerAct.class); act.startActivityForResult(intent, Util.YOUTUBE_LINK_INTENT); } }); } else if (Util.isEmptyString(strPicture) && linkUri.startsWith("http") && !UtilImage.hasImageExtension(linkUri, act) && //filter: some link has image extension Note.isViewAllMode()) { // set listener for running browser if (viewGroup != null) { CustomWebView linkWebView = ((CustomWebView) viewGroup.findViewById(R.id.link_web_view)); linkWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUri)); act.startActivity(i); } return true; } }); } } // view mode // picture only if (Note.isPictureMode()) { // image: view back picView_back_button.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_menu_back /*android.R.drawable.ic_menu_revert*/, 0, 0, 0); // click to finish Note_view_pager picView_back_button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { // remove current link web view int position = getFocus_notePos(); String tagPictureStr = "current" + position + "pictureView"; ViewGroup pictureGroup = (ViewGroup) pager.findViewWithTag(tagPictureStr); if (pictureGroup != null) { CustomWebView linkWebView = ((CustomWebView) pictureGroup.findViewById(R.id.link_web_view)); CustomWebView.pauseWebView(linkWebView); CustomWebView.blankWebView(linkWebView); } // set not full screen Util.setFullScreen_noImmersive(act); // back to view all mode Note.setViewAllMode(); Note.setOutline(act); } }); // image: view mode picView_viewMode_button.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_menu_view, 0, 0, 0); // click to select view mode picView_viewMode_button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { TextView audio_title_text_view = (TextView) act.findViewById(R.id.pager_audio_title); audio_title_text_view.setSelected(false); //Creating the instance of PopupMenu popup = new PopupMenu(act, view); //Inflating the Popup using xml file popup.getMenuInflater().inflate(R.menu.pop_up_menu, popup.getMenu()); //registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.view_all: Note.setViewAllMode(); Note.setOutline(act); break; case R.id.view_picture: Note.setPictureMode(); Note.setOutline(act); break; case R.id.view_text: Note.setTextMode(); Note.setOutline(act); break; } return true; } }); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { TextView audio_title_text_view = (TextView) act.findViewById(R.id.pager_audio_title); if (BackgroundAudioService.mMediaPlayer != null) { if (BackgroundAudioService.mMediaPlayer.isPlaying()) { AudioUi_note.showAudioName(act); audio_title_text_view.setSelected(true); } } else audio_title_text_view.setSelected(false); } }); popup.show();//showing pop up menu, will show status bar // for transient popup cancel_UI_callbacks(); Note_adapter.picUI_primary = new NoteUi(act, pager, pager.getCurrentItem()); Note_adapter.picUI_primary.tempShow_picViewUI(5005, strPicture); } }); // image: previous button picView_previous_button.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_media_previous, 0, 0, 0); // click to previous picView_previous_button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { setFocus_notePos(getFocus_notePos() - 1); pager.setCurrentItem(pager.getCurrentItem() - 1); } }); // image: next button picView_next_button.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_media_next, 0, 0, 0); // click to next picView_next_button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { setFocus_notePos(getFocus_notePos() + 1); pager.setCurrentItem(pager.getCurrentItem() + 1); } }); } // video view: apply media control customization or not if (Note.isPictureMode() || Note.isViewAllMode()) { if (!UtilVideo.hasMediaControlWidget) { // set video seek bar listener videoView_seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { // onStartTrackingTouch @Override public void onStartTrackingTouch(SeekBar seekBar) { System.out.println("NoteUi / _onStartTrackingTouch"); if ((UtilVideo.mVideoPlayer == null) && (UtilVideo.mVideoView != null)) { if (Build.VERSION.SDK_INT >= 16) UtilVideo.mVideoView.setBackground(null); else UtilVideo.mVideoView.setBackgroundDrawable(null); UtilVideo.mVideoView.setVisibility(View.VISIBLE); UtilVideo.mVideoPlayer = new VideoPlayer(act, pager, strPicture); UtilVideo.mVideoView.seekTo(UtilVideo.mPlayVideoPosition); } } // onProgressChanged @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { System.out.println("NoteUi / _onProgressChanged"); if (fromUser) { // show progress change int currentPos = videoFileLength_inMilliSeconds * progress / (seekBar.getMax() + 1); // update current play time videoView_currPosition.setText(Util.getTimeFormatString(currentPos)); //add below to keep showing seek bar if (Note.isPictureMode()) show_picViewUI_previous_next(true, mPosition); showSeekBarProgress = true; if (handler != null) handler.removeCallbacks(runnableHideUi); tempShow_picViewUI(3001, strPicture); // for 3 seconds, _onProgressChanged } } // onStopTrackingTouch @Override public void onStopTrackingTouch(SeekBar seekBar) { System.out.println("NoteUi / _onStopTrackingTouch"); if (UtilVideo.mVideoView != null) { int mPlayVideoPosition = (int) (((float) (videoFileLength_inMilliSeconds / 100)) * seekBar.getProgress()); if (UtilVideo.mVideoPlayer != null) UtilVideo.mVideoView.seekTo(mPlayVideoPosition); if (handler != null) handler.removeCallbacks(runnableHideUi); tempShow_picViewUI(3002, strPicture); // for 3 seconds, _onProgressChanged } } }); } } }
From source file:org.alfresco.mobile.android.application.fragments.node.browser.ProgressNodeAdapter.java
@Override protected void updateIcon(TwoLinesProgressViewHolder vh, Node item) { if (item instanceof NodePlaceHolder) { UIUtils.setBackground(vh.icon, null); vh.icon.setImageResource(MimeTypeManager.getInstance(getActivity()).getIcon(item.getName())); vh.choose.setVisibility(View.GONE); return;/*from w w w .j a v a 2s.co m*/ } else { super.updateIcon(vh, item); } if ((selectedItems != null && selectedItems.contains(item)) || (selectedMapItems != null && selectedMapItems.containsKey(item.getIdentifier()))) { if (getFragment() != null && getFragment() instanceof DocumentFolderBrowserFragment && ((DocumentFolderBrowserFragment) getFragment()).hasActionMode()) { vh.choose.setVisibility(View.VISIBLE); vh.choose.setImageResource(R.drawable.ic_done_single_white); int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16); vh.choose.setPadding(d_16, d_16, d_16, d_16); UIUtils.setBackground(vh.choose, null); vh.choose.setOnClickListener(null); } } else if (item.isFolder()) { vh.icon.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.mime_256_folder)); if (mode == ListingModeFragment.MODE_IMPORT) { return; } if (mode == ListingModeFragment.MODE_PICK) { return; } vh.choose.setImageResource(R.drawable.ic_more_options); vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light); int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16); vh.choose.setPadding(d_16, d_16, d_16, d_16); vh.choose.setVisibility(View.VISIBLE); AccessibilityUtils.addContentDescription(vh.choose, String.format(getActivity().getString(R.string.more_options_folder), item.getName())); vh.choose.setTag(R.id.node_action, item); vh.choose.setOnClickListener(new OnClickListener() { @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onClick(View v) { Node item = (Node) v.getTag(R.id.node_action); if (item == null) { return; } selectedOptionItems.add(item); PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), item); popup.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { selectedOptionItems.clear(); } }); popup.setOnMenuItemClickListener(ProgressNodeAdapter.this); popup.show(); } }); } else { UIUtils.setBackground(vh.choose, null); vh.choose.setPadding(0, 0, 0, 0); vh.choose.setVisibility(View.GONE); } }
From source file:net.nakama.duckdroid.ui.Duckdroid.java
public void btnshowPopupBang(View view) { PopupMenu p = new PopupMenu(this, view); MenuInflater inflater = p.getMenuInflater(); p.setOnMenuItemClickListener(bangListener); inflater.inflate(this.prefBangMenuId, p.getMenu()); p.show();//w w w. jav a2 s . co m }
From source file:com.fastbootmobile.encore.utils.Utils.java
public static void showCurrentSongOverflow(final Context context, final View parent, final Song song, final boolean showArtist) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.queue_overflow); if (song.getAlbum() == null) { Log.d(TAG, "No album information, removing album options"); // This song has no album information, hide the entries Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_add_album_to_queue); menu.removeItem(R.id.menu_open_album); }/* w w w . j a v a2 s. c o m*/ if (!showArtist) { Menu menu = popupMenu.getMenu(); menu.removeItem(R.id.menu_open_artist); } popupMenu.show(); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { final ProviderAggregator aggregator = ProviderAggregator.getDefault(); switch (menuItem.getItemId()) { case R.id.menu_open_album: final Resources res = context.getResources(); Intent intent = AlbumActivity.craftIntent(context, ((BitmapDrawable) res.getDrawable(R.drawable.album_placeholder)).getBitmap(), song.getAlbum(), song.getProvider(), res.getColor(R.color.default_album_art_background)); context.startActivity(intent); break; case R.id.menu_open_artist: intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(), context.getResources().getColor(R.color.default_album_art_background)); context.startActivity(intent); break; case R.id.menu_add_album_to_queue: PlaybackProxy.queueAlbum(aggregator.retrieveAlbum(song.getAlbum(), song.getProvider()), false); Toast.makeText(context, R.string.toast_album_added_to_queue, Toast.LENGTH_SHORT).show(); break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song); if (context instanceof FragmentActivity) { FragmentActivity act = (FragmentActivity) context; fragment.show(act.getSupportFragmentManager(), song.getRef()); } else { throw new IllegalArgumentException("Context must be an instance of FragmentActivity"); } break; default: return false; } return true; } }); }
From source file:com.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java
/** * Run during fragment initialization, this sets up the song info popup menu. * * @param view The view in which to setup the song info View for this class. * @return The song info view used as a field in this class. *///ww w. ja v a 2 s .co m private View getSongInfo(final View view) { final View songInfo = view.findViewById(R.id.songInfo); final PopupMenu popupMenu = new PopupMenu(mActivity, songInfo); final Menu menu = popupMenu.getMenu(); menu.add(Menu.NONE, POPUP_ALBUM, Menu.NONE, R.string.goToAlbum); menu.add(Menu.NONE, POPUP_ARTIST, Menu.NONE, R.string.goToArtist); menu.add(Menu.NONE, POPUP_ALBUM_ARTIST, Menu.NONE, R.string.goToAlbumArtist); menu.add(Menu.NONE, POPUP_FOLDER, Menu.NONE, R.string.goToFolder); menu.add(Menu.NONE, POPUP_CURRENT, Menu.NONE, R.string.goToCurrent); menu.add(Menu.NONE, POPUP_SHARE, Menu.NONE, R.string.share); popupMenu.setOnMenuItemClickListener(this); mPopupMenuTouchListener = PopupMenuCompat.getDragToOpenListener(popupMenu); final PopupMenu popupMenuStream = new PopupMenu(mActivity, songInfo); final Menu menuStream = popupMenuStream.getMenu(); menuStream.add(Menu.NONE, POPUP_STREAM, Menu.NONE, R.string.goToStream); menuStream.add(Menu.NONE, POPUP_CURRENT, Menu.NONE, R.string.goToCurrent); menuStream.add(Menu.NONE, POPUP_SHARE, Menu.NONE, R.string.share); popupMenuStream.setOnMenuItemClickListener(this); mPopupMenuStreamTouchListener = PopupMenuCompat.getDragToOpenListener(popupMenuStream); songInfo.setOnClickListener(new OnClickListener() { /** * Checks whether the album artist should be on the popup menu for the current track. * * @return True if the album artist popup menu entry should be visible, false otherwise. */ private boolean isAlbumArtistVisible() { boolean albumArtistEnabled = false; final String albumArtist = mCurrentSong.getAlbumArtist(); if (albumArtist != null && !albumArtist.isEmpty()) { final String artist = mCurrentSong.getArtist(); if (isArtistVisible() && !albumArtist.equals(artist)) { albumArtistEnabled = true; } } return albumArtistEnabled; } /** * Checks whether the album should be on the popup menu for the current track. * * @return True if the album popup menu entry should be visible, false otherwise. */ private boolean isAlbumVisible() { final boolean isAlbumVisible; final String album = mCurrentSong.getAlbum(); if (album != null && !album.isEmpty()) { isAlbumVisible = true; } else { isAlbumVisible = false; } return isAlbumVisible; } /** * Checks whether the artist should be on the popup menu for the current track. * * @return True if the artist popup menu entry should be visible, false otherwise. */ private boolean isArtistVisible() { final boolean isArtistVisible; final String artist = mCurrentSong.getArtist(); if (artist != null && !artist.isEmpty()) { isArtistVisible = true; } else { isArtistVisible = false; } return isArtistVisible; } /** * This method checks the dynamic entries for visibility prior to showing the song info * popup menu. * * @param v The view for the song info popup menu. */ @Override public void onClick(final View v) { if (mCurrentSong != null) { if (mCurrentSong.isStream()) { popupMenuStream.show(); } else { // Enable / Disable menu items that need artist and album defined. menu.findItem(POPUP_ALBUM).setVisible(isAlbumVisible()); menu.findItem(POPUP_ARTIST).setVisible(isArtistVisible()); menu.findItem(POPUP_ALBUM_ARTIST).setVisible(isAlbumArtistVisible()); popupMenu.show(); } } } }); return songInfo; }
From source file:org.xbmc.kore.ui.sections.audio.AlbumSongsListFragment.java
private void showPopupMenu(View v) { final ViewHolder viewHolder = (ViewHolder) v.getTag(); final PlaylistType.Item playListItem = new PlaylistType.Item(); final PopupMenu popupMenu = new PopupMenu(getActivity(), v); popupMenu.getMenuInflater().inflate(R.menu.song_item, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from ww w . ja v a2s. c o m public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_play_song: MediaPlayerUtils.play(AlbumSongsListFragment.this, playListItem); return true; case R.id.action_add_to_playlist: MediaPlayerUtils.queue(AlbumSongsListFragment.this, playListItem, PlaylistType.GetPlaylistsReturnType.AUDIO); return true; case R.id.download: ArrayList<FileDownloadHelper.SongInfo> songInfoList = new ArrayList<>(); songInfoList.add(viewHolder.songInfo); UIUtils.downloadSongs(getActivity(), songInfoList, HostManager.getInstance(getActivity()).getHostInfo(), callbackHandler); } return false; } }); popupMenu.show(); }