Example usage for android.widget PopupMenu show

List of usage examples for android.widget PopupMenu show

Introduction

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

Prototype

public void show() 

Source Link

Document

Show the menu popup anchored to the view specified during construction.

Usage

From source file:MainActivity.java

public void showPopupMenu(View view) {
    PopupMenu popupMenu = new PopupMenu(MainActivity.this, view);
    popupMenu.inflate(R.menu.menu_popup);
    popupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
    popupMenu.show();
}

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//from   w w  w  . j av  a  2s .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.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);
    }//  w  w  w . ja v  a  2 s.  c  o  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.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;//  w w w  . jav a 2  s  .  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.sf.golly.SettingsActivity.java

public void doPasteMode(View view) {
    // display pop-up menu with these items: AND, COPY, OR, XOR
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.pastemode_menu, popup.getMenu());
    popup.show();
}

From source file:com.ultramegasoft.flavordex2.fragment.PhotoFragment.java

/**
 * Show the PopupMenu for the photo.//w  ww  .j a  va  2 s.  c  o  m
 *
 * @param v The View to attach the menu to
 */
private void showMenu(@NonNull View v) {
    final PopupMenu popupMenu = new PopupMenu(getContext(), v);
    popupMenu.setOnMenuItemClickListener(this);
    popupMenu.inflate(R.menu.photo_menu);
    popupMenu.show();
}

From source file:com.oda.calculator.Calculator.java

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.overflow_menu:
        PopupMenu menu = constructPopupMenu();
        if (menu != null) {
            menu.show();
        }//from  w w w  . j  a  v  a  2s . co m
        break;
    }
}

From source file:com.aman.stockcalculator.Calculator.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.overflow_menu:
        PopupMenu menu = constructPopupMenu();
        if (menu != null) {
            menu.show();
        }// ww w .j av a 2  s.com
        break;
    }
}

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  ww.  ja  va  2  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.buildconfiguration.BuildConfigurationOverviewActivity.java

void optionsClick(@NotNull String id, @NotNull View anchor) {
    PopupMenu menu = new PopupMenu(this, anchor);

    menu.inflate(R.menu.menu_concept);/*from  ww  w  .  j ava  2 s.c  o m*/

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

    menu.show();
}