Search in sources :

Example 41 with PopupMenu

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();
        }
    });
}
Also used : MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.widget.PopupMenu)

Example 42 with PopupMenu

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();
        }
    });
}
Also used : MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Example 43 with PopupMenu

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);
        }
    });
}
Also used : MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Example 44 with PopupMenu

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();
        }
    });
}
Also used : MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.widget.PopupMenu)

Example 45 with PopupMenu

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;
}
Also used : Rect(android.graphics.Rect) ContextThemeWrapper(android.view.ContextThemeWrapper) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) Point(android.graphics.Point) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) PopupMenu(android.widget.PopupMenu) SuppressLint(android.annotation.SuppressLint)

Aggregations

PopupMenu (android.widget.PopupMenu)99 MenuItem (android.view.MenuItem)60 View (android.view.View)44 TextView (android.widget.TextView)41 ImageView (android.widget.ImageView)30 RecyclerView (android.support.v7.widget.RecyclerView)22 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Intent (android.content.Intent)14 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 MenuInflater (android.view.MenuInflater)10 AdapterView (android.widget.AdapterView)10 ListView (android.widget.ListView)10 Menu (android.view.Menu)9 NonNull (android.support.annotation.NonNull)8