Example usage for android.widget PopupMenu setOnMenuItemClickListener

List of usage examples for android.widget PopupMenu setOnMenuItemClickListener

Introduction

In this page you can find the example usage for android.widget PopupMenu setOnMenuItemClickListener.

Prototype

public void setOnMenuItemClickListener(OnMenuItemClickListener listener) 

Source Link

Document

Sets a listener that will be notified when the user selects an item from the menu.

Usage

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   w  w w .  ja  v  a  2  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:com.owncloud.android.ui.trashbin.TrashbinActivity.java

@Override
public void onOverflowIconClicked(TrashbinFile file, View view) {
    PopupMenu popup = new PopupMenu(this, view);
    popup.inflate(R.menu.trashbin_actions_menu);

    popup.setOnMenuItemClickListener(item -> {
        trashbinPresenter.removeTrashbinFile(file);

        return true;
    });//from   www.  ja va  2s  .co  m
    popup.show();
}

From source file:com.fastbootmobile.encore.utils.Utils.java

public static void showSongOverflow(final FragmentActivity context, final View parent, final Song song,
        final boolean hideArtist) {
    PopupMenu popupMenu = new PopupMenu(context, parent);
    popupMenu.inflate(R.menu.track_overflow);

    if (song.getArtist() == null || hideArtist) {
        // This song has no artist information, hide the entry
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_open_artist);
    }//from ww  w . j a  v  a2  s  .  co m

    if (song.getAlbum() == null) {
        // This song has no album information, hide the entry
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_add_album_to_queue);
    }

    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_play_now:
                PlaybackProxy.playSong(song);
                break;

            case R.id.menu_play_next:
                PlaybackProxy.playNext(song);
                break;

            case R.id.menu_open_artist:
                Intent 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_to_queue:
                PlaybackProxy.queueSong(song, false);
                Toast.makeText(context, R.string.toast_song_added_to_queue, Toast.LENGTH_SHORT).show();
                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);
                fragment.show(context.getSupportFragmentManager(), song.getRef());
                break;

            default:
                return false;
            }
            return true;
        }
    });
}

From source file:com.siva.animation_sample.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    //getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getActionBar().setDisplayShowCustomEnabled(true);
    getActionBar().setCustomView(R.layout.custom_action_bar_layout);
    custom_action_view = getActionBar().getCustomView();
    ImageView more_icon = (ImageView) custom_action_view.findViewById(R.id.moreimage);
    more_icon.setOnClickListener(new View.OnClickListener() {

        @Override//  w w w . j  a  va 2 s.co m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            PopupMenu popup = new PopupMenu(HomeActivity.this, v);
            MenuInflater inflate = popup.getMenuInflater();
            inflate.inflate(R.menu.home, popup.getMenu());
            popup.show();
            popup.setOnMenuItemClickListener(HomeActivity.this);

        }
    });

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
    Create_alert_box();

    mTabHost.addTab(
            mTabHost.newTabSpec("tab1").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)),
            FragmentTab1.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab2").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)),
            FragmentTab2.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab3").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)),
            FragmentTab3.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab4").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)),
            FragmentTab4.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab5").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)),
            FragmentTab5.class, null);

    mTabHost.setCurrentTab(2);

}

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);//from   w  ww  . ja v  a  2s  . com

    menu.setOnMenuItemClickListener(new PopupMenuListener(WebLocator.getBuildUrl(id, new Preferences(this))));

    menu.show();
}

From source file:com.oceansky.yellow.utils.Utils.java

public static void showSongOverflow(final FragmentActivity context, final View parent, final Song song,
        final boolean hideArtist) {
    if (song == null) {
        return;//  www . jav  a2s. c  o  m
    }

    PopupMenu popupMenu = new PopupMenu(context, parent);
    popupMenu.inflate(R.menu.track_overflow);

    if (song.getArtist() == null || hideArtist) {
        // This song has no artist information, hide the entry
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_open_artist);
    }

    if (song.getAlbum() == null) {
        // This song has no album information, hide the entry
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_add_album_to_queue);
    }

    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_play_now:
                PlaybackProxy.playSong(song);
                break;

            case R.id.menu_play_next:
                PlaybackProxy.playNext(song);
                break;

            case R.id.menu_open_artist:
                Intent 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_to_queue:
                PlaybackProxy.queueSong(song, false);
                Toast.makeText(context, R.string.toast_song_added_to_queue, Toast.LENGTH_SHORT).show();
                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);
                fragment.show(context.getSupportFragmentManager(), song.getRef());
                break;

            default:
                return false;
            }
            return true;
        }
    });
}

From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java

@TargetApi(11)
@Override//from   w ww.  ja  v  a 2 s  . com
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.contact_actions:
        if (Utility.isPreHoneycomb()) {
            showContactQuickActions(v);
            return;
        } else {
            PopupMenu popup = new PopupMenu(getActivity(), v);
            popup.setOnMenuItemClickListener(HoneycombListeners.getPopupMenuListener(this));
            MenuInflater inflater = popup.getMenuInflater();

            inflater.inflate(R.menu.contact_actions_menu, popup.getMenu());
            popup.show();
        }
        break;
    case R.id.save_contact:
        this.contactWriter.saveContact(getView().getContext());
    default:
        break;
    }
}

From source file:systems.soapbox.ombuds.client.ui.BlockListFragment.java

@Override
public void onBlockMenuClick(final View view, final StoredBlock block) {
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.blocks_context);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/* www.  ja  va2  s .  c  om*/
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.blocks_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(config.getBlockExplorer(),
                        "block/" + block.getHeader().getHashAsString())));
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}

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);
    }//from  w w w .ja 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.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);/* w ww. j  a  va 2s  .c  o  m*/

    menu.setOnMenuItemClickListener(new PopupMenuListener(WebLocator.getProjectUrl(id, new Preferences(this))));

    menu.show();
}