Search in sources :

Example 86 with PopupMenu

use of android.support.v7.widget.PopupMenu in project MusicDNA by harjot-oberai.

the class AllPlaylistsFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    backBtn = (ImageView) view.findViewById(R.id.all_playlist_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    allPlaylistFragmentTitle = (TextView) view.findViewById(R.id.all_playlist_fragment_title);
    if (SplashActivity.tf4 != null)
        allPlaylistFragmentTitle.setTypeface(SplashActivity.tf4);
    playlistFragIcon = (ImageView) view.findViewById(R.id.all_playlist_frag_icon);
    playlistFragIcon.setImageTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    initializeHeaderImages(view);
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    noPlaylistContent = (LinearLayout) view.findViewById(R.id.noPlaylistContent);
    allPlaylistRecycler = (RecyclerView) view.findViewById(R.id.all_playlists_recycler);
    addPlaylistFAB = (FloatingActionButton) view.findViewById(R.id.new_playlist_fab);
    addPlaylistFAB.setBackgroundTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    addPlaylistFAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.newPlaylistListener();
        }
    });
    if (SplashActivity.tf4 != null)
        ((TextView) view.findViewById(R.id.noPlaylistContentText)).setTypeface(SplashActivity.tf4);
    if (HomeActivity.allPlaylists.getPlaylists().size() == 0) {
        allPlaylistRecycler.setVisibility(View.INVISIBLE);
        noPlaylistContent.setVisibility(View.VISIBLE);
    } else {
        allPlaylistRecycler.setVisibility(View.VISIBLE);
        noPlaylistContent.setVisibility(View.INVISIBLE);
    }
    vpAdapter = new ViewAllPlaylistsRecyclerAdapter(HomeActivity.allPlaylists.getPlaylists(), getContext());
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    allPlaylistRecycler.setLayoutManager(mLayoutManager2);
    allPlaylistRecycler.setItemAnimator(new DefaultItemAnimator());
    allPlaylistRecycler.setAdapter(vpAdapter);
    allPlaylistRecycler.addOnItemTouchListener(new ClickItemTouchListener(allPlaylistRecycler) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            mCallback.onPlaylistSelected(position);
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, final int position, long id) {
            PopupMenu popup = new PopupMenu(getContext(), view);
            popup.getMenuInflater().inflate(R.menu.playlist_popup, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (item.getTitle().equals("Play")) {
                        HomeActivity.tempPlaylist = HomeActivity.allPlaylists.getPlaylists().get(position);
                        int size = HomeActivity.tempPlaylist.getSongList().size();
                        HomeActivity.queue.getQueue().clear();
                        for (int i = 0; i < size; i++) {
                            HomeActivity.queue.addToQueue(HomeActivity.tempPlaylist.getSongList().get(i));
                        }
                        HomeActivity.queueCurrentIndex = 0;
                        mCallback.onPlaylistMenuPLayAll();
                    } else if (item.getTitle().equals("Add to Queue")) {
                        Playlist pl = HomeActivity.allPlaylists.getPlaylists().get(position);
                        for (UnifiedTrack ut : pl.getSongList()) {
                            HomeActivity.queue.addToQueue(ut);
                        }
                    } else if (item.getTitle().equals("Delete")) {
                        HomeActivity.allPlaylists.getPlaylists().remove(position);
                        if (vpAdapter != null) {
                            vpAdapter.notifyItemRemoved(position);
                        }
                        if (HomeActivity.allPlaylists.getPlaylists().size() == 0) {
                            noPlaylistContent.setVisibility(View.VISIBLE);
                        }
                        new HomeActivity.SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        homeActivity.pAdapter.notifyItemRemoved(position);
                    } else if (item.getTitle().equals("Rename")) {
                        HomeActivity.renamePlaylistNumber = position;
                        mCallback.onPlaylistRename();
                    }
                    return true;
                }
            });
            popup.show();
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
}
Also used : HomeActivity(com.sdsmdg.harjot.MusicDNA.activities.HomeActivity) MenuItem(android.view.MenuItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) PopupMenu(android.support.v7.widget.PopupMenu)

Example 87 with PopupMenu

use of android.support.v7.widget.PopupMenu in project AgentWeb by Justson.

the class AgentWebFragment method showPoPup.

/**
 * 显示更多菜单
 *
 * @param view 菜单依附在该View下面
 */
private void showPoPup(View view) {
    if (mPopupMenu == null) {
        mPopupMenu = new PopupMenu(this.getActivity(), view);
        mPopupMenu.inflate(R.menu.toolbar_menu);
        mPopupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
    }
    mPopupMenu.show();
}
Also used : PopupMenu(android.support.v7.widget.PopupMenu)

Example 88 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Fragmentation by YoKeyword.

the class HomeFragment method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_anim:
            final PopupMenu popupMenu = new PopupMenu(_mActivity, mToolbar, GravityCompat.END);
            popupMenu.inflate(R.menu.home_pop);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.action_anim_veritical:
                            ((ISupportActivity) _mActivity).setFragmentAnimator(new DefaultVerticalAnimator());
                            Toast.makeText(_mActivity, R.string.anim_v, Toast.LENGTH_SHORT).show();
                            break;
                        case R.id.action_anim_horizontal:
                            ((ISupportActivity) _mActivity).setFragmentAnimator(new DefaultHorizontalAnimator());
                            Toast.makeText(_mActivity, R.string.anim_h, Toast.LENGTH_SHORT).show();
                            break;
                        case R.id.action_anim_none:
                            ((ISupportActivity) _mActivity).setFragmentAnimator(new DefaultNoAnimator());
                            Toast.makeText(_mActivity, R.string.anim_none, Toast.LENGTH_SHORT).show();
                            break;
                    }
                    popupMenu.dismiss();
                    return true;
                }
            });
            popupMenu.show();
            break;
    }
    return true;
}
Also used : DefaultVerticalAnimator(me.yokeyword.fragmentation.anim.DefaultVerticalAnimator) DefaultHorizontalAnimator(me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator) MenuItem(android.view.MenuItem) DefaultNoAnimator(me.yokeyword.fragmentation.anim.DefaultNoAnimator) PopupMenu(android.support.v7.widget.PopupMenu)

Example 89 with PopupMenu

use of android.support.v7.widget.PopupMenu in project PhotoNoter by yydcdut.

the class ImageDialogView method targetImageClick.

@OnClick(R.id.img_image)
public void targetImageClick(View v) {
    PopupMenu popup = new PopupMenu(getContext(), mTargetImageView);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_popup, popup.getMenu());
    popup.setOnMenuItemClickListener(this);
    popup.show();
}
Also used : MenuInflater(android.view.MenuInflater) PopupMenu(android.support.v7.widget.PopupMenu) OnClick(butterknife.OnClick)

Example 90 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Android-Developers-Samples by johnjohndoe.

the class PopupListFragment method showPopupMenu.

// BEGIN_INCLUDE(show_popup)
private void showPopupMenu(View view) {
    final PopupAdapter adapter = (PopupAdapter) getListAdapter();
    // Retrieve the clicked item from view's tag
    final String item = (String) view.getTag();
    // Create a PopupMenu, giving it the clicked view for an anchor
    PopupMenu popup = new PopupMenu(getActivity(), view);
    // Inflate our menu resource into the PopupMenu's Menu
    popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());
    // Set a listener so we are notified if a menu item is clicked
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.menu_remove:
                    // Remove the item from the adapter
                    adapter.remove(item);
                    return true;
            }
            return false;
        }
    });
    // Finally show the PopupMenu
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15