use of android.widget.PopupMenu in project Timber by naman14.
the class AlbumSongsAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
itemHolder.menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_song_play:
MusicPlayer.playAll(mContext, songIDs, position, -1, TimberUtils.IdType.NA, false);
break;
case R.id.popup_song_play_next:
long[] ids = new long[1];
ids[0] = arraylist.get(position).id;
MusicPlayer.playNext(mContext, ids, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_goto_album:
NavigationUtils.goToAlbum(mContext, arraylist.get(position).albumId);
break;
case R.id.popup_song_goto_artist:
NavigationUtils.goToArtist(mContext, arraylist.get(position).artistId);
break;
case R.id.popup_song_addto_queue:
long[] id = new long[1];
id[0] = arraylist.get(position).id;
MusicPlayer.addToQueue(mContext, id, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_addto_playlist:
AddPlaylistDialog.newInstance(arraylist.get(position)).show(((AppCompatActivity) mContext).getSupportFragmentManager(), "ADD_PLAYLIST");
break;
case R.id.popup_song_share:
TimberUtils.shareTrack(mContext, arraylist.get(position).id);
break;
case R.id.popup_song_delete:
long[] deleteIds = { arraylist.get(position).id };
TimberUtils.showDeleteDialog(mContext, arraylist.get(position).title, deleteIds, AlbumSongsAdapter.this, position);
break;
}
return false;
}
});
menu.inflate(R.menu.popup_song);
menu.show();
}
});
}
use of android.widget.PopupMenu in project Timber by naman14.
the class SearchAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
itemHolder.menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
long[] song = new long[1];
song[0] = ((Song) searchResults.get(position)).id;
switch(item.getItemId()) {
case R.id.popup_song_play:
MusicPlayer.playAll(mContext, song, 0, -1, TimberUtils.IdType.NA, false);
break;
case R.id.popup_song_play_next:
MusicPlayer.playNext(mContext, song, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_goto_album:
NavigationUtils.navigateToAlbum(mContext, ((Song) searchResults.get(position)).albumId, null);
break;
case R.id.popup_song_goto_artist:
NavigationUtils.navigateToArtist(mContext, ((Song) searchResults.get(position)).artistId, null);
break;
case R.id.popup_song_addto_queue:
MusicPlayer.addToQueue(mContext, song, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_addto_playlist:
AddPlaylistDialog.newInstance(((Song) searchResults.get(position))).show(((AppCompatActivity) mContext).getSupportFragmentManager(), "ADD_PLAYLIST");
break;
}
return false;
}
});
menu.inflate(R.menu.popup_song);
menu.show();
}
});
}
use of android.widget.PopupMenu in project Timber by naman14.
the class SongsListAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_song_remove_playlist:
TimberUtils.removeFromPlaylist(mContext, arraylist.get(position).id, playlistId);
removeSongAt(position);
notifyItemRemoved(position);
break;
case R.id.popup_song_play:
MusicPlayer.playAll(mContext, songIDs, position, -1, TimberUtils.IdType.NA, false);
break;
case R.id.popup_song_play_next:
long[] ids = new long[1];
ids[0] = arraylist.get(position).id;
MusicPlayer.playNext(mContext, ids, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_goto_album:
NavigationUtils.goToAlbum(mContext, arraylist.get(position).albumId);
break;
case R.id.popup_song_goto_artist:
NavigationUtils.goToArtist(mContext, arraylist.get(position).artistId);
break;
case R.id.popup_song_addto_queue:
long[] id = new long[1];
id[0] = arraylist.get(position).id;
MusicPlayer.addToQueue(mContext, id, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_addto_playlist:
AddPlaylistDialog.newInstance(arraylist.get(position)).show(mContext.getSupportFragmentManager(), "ADD_PLAYLIST");
break;
case R.id.popup_song_share:
TimberUtils.shareTrack(mContext, arraylist.get(position).id);
break;
case R.id.popup_song_delete:
long[] deleteIds = { arraylist.get(position).id };
TimberUtils.showDeleteDialog(mContext, arraylist.get(position).title, deleteIds, SongsListAdapter.this, position);
break;
}
return false;
}
});
menu.inflate(R.menu.popup_song);
menu.show();
if (isPlaylist)
menu.getMenu().findItem(R.id.popup_song_remove_playlist).setVisible(true);
}
});
}
use of android.widget.PopupMenu in project Timber by naman14.
the class BaseQueueAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_song_play:
MusicPlayer.playAll(mContext, getSongIds(), position, -1, TimberUtils.IdType.NA, false);
break;
case R.id.popup_song_play_next:
long[] ids = new long[1];
ids[0] = arraylist.get(position).id;
MusicPlayer.playNext(mContext, ids, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_goto_album:
NavigationUtils.goToAlbum(mContext, arraylist.get(position).albumId);
break;
case R.id.popup_song_goto_artist:
NavigationUtils.goToArtist(mContext, arraylist.get(position).artistId);
break;
case R.id.popup_song_addto_queue:
long[] id = new long[1];
id[0] = arraylist.get(position).id;
MusicPlayer.addToQueue(mContext, id, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_addto_playlist:
AddPlaylistDialog.newInstance(arraylist.get(position)).show(mContext.getSupportFragmentManager(), "ADD_PLAYLIST");
break;
case R.id.popup_song_share:
TimberUtils.shareTrack(mContext, arraylist.get(position).id);
break;
case R.id.popup_song_delete:
long[] deleteIds = { arraylist.get(position).id };
TimberUtils.showDeleteDialog(mContext, arraylist.get(position).title, deleteIds, BaseQueueAdapter.this, position);
break;
}
return false;
}
});
menu.inflate(R.menu.popup_song);
menu.show();
}
});
}
use of android.widget.PopupMenu in project AndroidChromium by JackyAndroid.
the class AppMenuHandler method showAppMenu.
/**
* Show the app menu.
* @param anchorView Anchor view (usually a menu button) to be used for the popup, if
* null is passed then hardware menu button anchor will be used.
* @param startDragging Whether dragging is started. For example, if the app menu is
* showed by tapping on a button, this should be false. If it is
* showed by start dragging down on the menu button, this should
* be true. Note that if anchorView is null, this must
* be false since we no longer support hardware menu button
* dragging.
* @return True, if the menu is shown, false, if menu is not shown, example reasons:
* the menu is not yet available to be shown, or the menu is already showing.
*/
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("ResourceType")
public boolean showAppMenu(View anchorView, boolean startDragging) {
if (!mDelegate.shouldShowAppMenu() || isAppMenuShowing())
return false;
boolean isByPermanentButton = false;
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
if (anchorView == null) {
// This fixes the bug where the bottom of the menu starts at the top of
// the keyboard, instead of overlapping the keyboard as it should.
int displayHeight = mActivity.getResources().getDisplayMetrics().heightPixels;
Rect rect = new Rect();
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
mHardwareButtonMenuAnchor.setY((displayHeight - statusBarHeight));
anchorView = mHardwareButtonMenuAnchor;
isByPermanentButton = true;
}
assert !(isByPermanentButton && startDragging);
if (mMenu == null) {
// Use a PopupMenu to create the Menu object. Note this is not the same as the
// AppMenu (mAppMenu) created below.
PopupMenu tempMenu = new PopupMenu(mActivity, anchorView);
tempMenu.inflate(mMenuResourceId);
mMenu = tempMenu.getMenu();
}
mDelegate.prepareMenu(mMenu);
ContextThemeWrapper wrapper = new ContextThemeWrapper(mActivity, R.style.OverflowMenuTheme);
if (mAppMenu == null) {
TypedArray a = wrapper.obtainStyledAttributes(new int[] { android.R.attr.listPreferredItemHeightSmall, android.R.attr.listDivider });
int itemRowHeight = a.getDimensionPixelSize(0, 0);
Drawable itemDivider = a.getDrawable(1);
int itemDividerHeight = itemDivider != null ? itemDivider.getIntrinsicHeight() : 0;
a.recycle();
mAppMenu = new AppMenu(mMenu, itemRowHeight, itemDividerHeight, this, mActivity.getResources());
mAppMenuDragHelper = new AppMenuDragHelper(mActivity, mAppMenu, itemRowHeight);
}
// Get the height and width of the display.
Rect appRect = new Rect();
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(appRect);
// Use full size of window for abnormal appRect.
if (appRect.left < 0 && appRect.top < 0) {
appRect.left = 0;
appRect.top = 0;
appRect.right = mActivity.getWindow().getDecorView().getWidth();
appRect.bottom = mActivity.getWindow().getDecorView().getHeight();
}
Point pt = new Point();
mActivity.getWindowManager().getDefaultDisplay().getSize(pt);
mAppMenu.show(wrapper, anchorView, isByPermanentButton, rotation, appRect, pt.y, mDelegate.getFooterResourceId());
mAppMenuDragHelper.onShow(startDragging);
RecordUserAction.record("MobileMenuShow");
return true;
}
Aggregations