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:com.fastbootmobile.encore.app.adapters.SearchAdapter.java

private void showAlbumOverflow(final Context context, View parent, final Album album) {
    PopupMenu popupMenu = new PopupMenu(context, parent);
    popupMenu.inflate(R.menu.search_res_album);
    popupMenu.show();

    final String artist = Utils.getMainArtist(album);

    if (artist == null) {
        // No artist could be found for this album, don't show the entry
        popupMenu.getMenu().removeItem(R.id.menu_open_artist_page);
    }//  w w  w  .j a  va  2  s. c o  m

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.menu_play_now:
                PlaybackProxy.playAlbum(album);
                break;

            case R.id.menu_add_to_queue:
                PlaybackProxy.queueAlbum(album, false);
                break;

            case R.id.menu_open_artist_page:
                if (artist != null) {
                    Intent intent = ArtistActivity.craftIntent(context, null, artist, album.getProvider(),
                            0xFF333333);
                    context.startActivity(intent);
                }
                break;

            case R.id.menu_add_to_playlist:
                PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(album);
                fragment.show(((FragmentActivity) context).getSupportFragmentManager(), album.getRef());
                break;

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

From source file:org.videolan.vlc2.gui.video.VideoGridFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onContextPopupMenu(View anchor, final int position) {
    if (!LibVlcUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();/*  www .j a v a  2  s.  c  o  m*/
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    Media media = mVideoAdapter.getItem(position);
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}

From source file:com.fastbootmobile.encore.app.adapters.SearchAdapter.java

private void showSongOverflow(final Context context, View parent, final Song song) {
    PopupMenu popupMenu = new PopupMenu(context, parent);
    popupMenu.inflate(R.menu.search_res_song);
    popupMenu.show();

    if (song.getArtist() == null) {
        // No attached artist, don't show the menu entry
        popupMenu.getMenu().removeItem(R.id.menu_open_artist_page);
    }/*from  w  w  w  .j av a 2 s. c om*/

    if (song.getAlbum() == null) {
        // No attached album, don't show the menu entry
        popupMenu.getMenu().removeItem(R.id.menu_open_album_page);
    }

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.menu_play_now:
                PlaybackProxy.playSong(song);
                break;

            case R.id.menu_add_to_queue:
                PlaybackProxy.queueSong(song, false);
                break;

            case R.id.menu_open_artist_page:
                if (song.getArtist() != null) {
                    intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(),
                            0xFF333333);
                    context.startActivity(intent);
                }
                break;

            case R.id.menu_open_album_page:
                if (song.getAlbum() != null) {
                    intent = AlbumActivity.craftIntent(context, null, song.getAlbum(), song.getProvider(),
                            0xFF333333);
                    context.startActivity(intent);
                }
                break;

            case R.id.menu_add_to_playlist:
                PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song);
                fragment.show(((FragmentActivity) context).getSupportFragmentManager(), song.getRef());
                break;

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

From source file:com.dgsd.android.ShiftTracker.Fragment.WeekFragment.java

@Override
public void onItemClick(AdapterView<?> list, final View view, int pos, long id) {
    final WeekAdapter.ViewHolder holder = (WeekAdapter.ViewHolder) view.getTag();
    final Intent intent = getIntentFor(holder);
    if (!mHasTemplates || (holder != null && holder.shift != null)) {
        startActivity(intent);/* w  w w. j  ava2s .c  om*/
        return;
    }

    final int jd = holder == null ? -1 : holder.julianDay;
    if (Api.isMin(Api.HONEYCOMB)) {
        PopupMenu popup = new PopupMenu(getActivity(), view.findViewById(R.id.text));
        popup.getMenuInflater().inflate(R.menu.week_list_item_popup, popup.getMenu());
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.template_shift) {
                    showTemplateChooser(jd);
                } else if (item.getItemId() == R.id.new_shift) {
                    startActivity(intent);
                }
                return false;
            }
        });

        popup.show();
    } else {
        mList.showContextMenuForChild(view);
    }
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@SuppressLint("NewApi")
public OnClickListener onclickPopUpMenu(MenuItem item) {
    //Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(EncoderActivity.this, item.getActionView());
    //Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.menu_contextual_wps, popup.getMenu());

    //registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(EncoderActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
            return true;
        }/*from   ww w.  jav a  2  s. co m*/
    });

    popup.show(); //showing popup menu
    return null;

}

From source file:org.apache.cordova.navigationmenu.NavigationMenu.java

/**
 * Displays popup menu.//from   w  w w . j  a va  2 s. co m
 *
 * @param items   The array of objects which describes menu items.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void showPopup(JSONArray items) {
    final PopupMenu popup = new PopupMenu(this.webView.getContext(), this.webView);

    PopupMenu.OnMenuItemClickListener handler = new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            int itemId = item.getItemId();
            webView.sendJavascript("menu.popupItemClick && menu.popupItemClick(" + itemId + ");");
            return false;
        }
    };
    popup.setOnMenuItemClickListener(handler);
    Menu popupMenu = popup.getMenu();
    for (int i = 0; i < items.length(); i++) {
        JSONObject menuItem = items.optJSONObject(i);
        if (menuItem != null) {
            appendItem(popupMenu, menuItem);
        }
    }

    this.cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            popup.show();
        }
    });

}

From source file:com.vrs.reqdroid.fragments.RequisitosFragment.java

/**
 * Mostra o PopUpMenu das opcoes do requisito.
 * Funciona apenas para a versao 3.0 ou superior do Android.
 *
 * @param v a view do requisito/*from  w  w w.  j  av a  2 s  .com*/
 *
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void exibePopupMenuOpcoes(final View v) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.menu_opcoes_requisito, popupMenu.getMenu());

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.opcaoEditarRequisito:
                menuEdita();
                break;
            case R.id.opcaoMoverRequisito:
                menuMove();
                break;
            case R.id.opcaoDeletarRequisito:
                menuDeleta();
                break;
            }
            return true;
        }
    });
    popupMenu.show();
}

From source file:org.alfresco.mobile.android.application.fragments.person.PersonProfileFragment.java

private void display() {
    TextView tv = null;/*from  w w w .  ja  v  a 2  s.co m*/
    ImageView bIm = null;

    // HEADER
    tv = (TextView) vRoot.findViewById(R.id.name);
    tv.setText(person.getFullName());

    // JOB TITLE
    tv = (TextView) vRoot.findViewById(R.id.jobTitle);
    if (person.getJobTitle() != null && !person.getJobTitle().isEmpty() && person.getCompany() != null
            && person.getCompany().getName() != null && !person.getCompany().getName().isEmpty()) {
        tv.setText(String.format(getString(R.string.work_at), person.getJobTitle(),
                person.getCompany().getName()));
    } else if (person.getJobTitle() != null) {
        tv.setText(person.getJobTitle());
    } else {
        tv.setText(person.getCompany().getName());
    }

    // Location
    tv = (TextView) vRoot.findViewById(R.id.location);
    tv.setText(person.getLocation());

    // Summary
    displayOrHide(R.id.description, person.getSummary(), R.id.summary_group);

    // Email
    displayOrHide(R.id.email_value, person.getEmail(), R.id.email_group);

    // Telephone
    displayOrHide(R.id.telephone_value, person.getTelephoneNumber(), R.id.telephone_group);

    // Mobile
    displayOrHide(R.id.mobile_value, person.getMobileNumber(), R.id.mobile_group);

    if (person.getTelephoneNumber() != null || person.getMobileNumber() != null
            || person.getCompany().getTelephoneNumber() != null) {
        bIm = (ImageView) vRoot.findViewById(R.id.action_call);
        bIm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupMenu popup = new PopupMenu(getActivity(), v);
                getMenu(popup.getMenu(), MODE_CALL);
                popup.setOnMenuItemClickListener(PersonProfileFragment.this);
                popup.show();
            }
        });
    } else {
        vRoot.findViewById(R.id.action_call).setVisibility(View.GONE);
    }

    // SKype
    if (person.getSkypeId() != null && !person.getSkypeId().isEmpty()) {
        displayGroup();
        tv = (TextView) vRoot.findViewById(R.id.skypeId_value);
        tv.setText(person.getSkypeId());
        bIm = (ImageView) vRoot.findViewById(R.id.action_skype);
        bIm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupMenu popup = new PopupMenu(getActivity(), v);
                getMenu(popup.getMenu(), MODE_SKYPE);
                popup.setOnMenuItemClickListener(PersonProfileFragment.this);
                popup.show();
            }
        });
    } else {
        vRoot.findViewById(R.id.action_skype).setVisibility(View.GONE);
        vRoot.findViewById(R.id.skypeId_group).setVisibility(View.GONE);
    }

    // IM
    if (person.getInstantMessageId() != null && !person.getInstantMessageId().isEmpty()) {
        displayGroup();
        tv = (TextView) vRoot.findViewById(R.id.instantMessagingId_value);
        tv.setText(person.getInstantMessageId());
    } else {
        vRoot.findViewById(R.id.instantMessagingId_group).setVisibility(View.GONE);
    }

    // Google
    if (person.getGoogleId() != null && !person.getGoogleId().isEmpty()) {
        displayGroup();
        tv = (TextView) vRoot.findViewById(R.id.googleId_value);
        tv.setText(person.getGoogleId());
        bIm = (ImageView) vRoot.findViewById(R.id.action_im);
        bIm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                actionStartIm(getActivity(), person.getGoogleId());
            }
        });
    } else {
        vRoot.findViewById(R.id.action_im).setVisibility(View.GONE);
        vRoot.findViewById(R.id.googleId_group).setVisibility(View.GONE);
    }

    if (!displayContactDetails) {
        vRoot.findViewById(R.id.contactInfo_group).setVisibility(View.GONE);
        displayContactDetails = false;
    }

    // Company
    Company cp = person.getCompany();
    displayCompanyOrHide(R.id.companyName_value, cp.getName(), R.id.companyName_group);
    displayCompanyOrHide(R.id.companyAdress1_value, cp.getAddress1(), R.id.companyAdress1_group);
    displayCompanyOrHide(R.id.companyAdress2_value, cp.getAddress2(), R.id.companyAdress2_group);
    displayCompanyOrHide(R.id.companyAdress3_value, cp.getAddress3(), R.id.companyAdress3_group);
    displayCompanyOrHide(R.id.companyPostcode_value, cp.getPostCode(), R.id.companyPostcode_group);
    displayCompanyOrHide(R.id.companyTelephone_value, cp.getTelephoneNumber(), R.id.companyTelephone_group);
    displayCompanyOrHide(R.id.companyFax_value, cp.getFaxNumber(), R.id.companyFax_group);
    displayCompanyOrHide(R.id.companyEmail_value, cp.getEmail(), R.id.companyEmail_group);

    // Add Contact
    bIm = (ImageView) vRoot.findViewById(R.id.action_addcontact);
    bIm.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            actionAddContact(getActivity(), person);
        }
    });

    // Add Contact
    if (person.getEmail() != null || person.getCompany().getEmail() != null) {
        bIm = (ImageView) vRoot.findViewById(R.id.action_email);
        bIm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupMenu popup = new PopupMenu(getActivity(), v);
                getMenu(popup.getMenu(), MODE_EMAIL);
                popup.setOnMenuItemClickListener(PersonProfileFragment.this);
                popup.show();
            }
        });
    } else {
        vRoot.findViewById(R.id.action_email).setVisibility(View.GONE);
    }

    // Geolocalisation
    if (person.getCompany().getFullAddress() != null) {
        displayGroup();
        bIm = (ImageView) vRoot.findViewById(R.id.action_geolocation);
        bIm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                actionGeolocalisation(getActivity(), person.getCompany().getFullAddress(),
                        person.getCompany().getName());
            }
        });
    } else {
        vRoot.findViewById(R.id.action_geolocation).setVisibility(View.GONE);
    }

    if (!displayCompanyDetails) {
        vRoot.findViewById(R.id.company_group).setVisibility(View.GONE);
    }
}

From source file:org.hawkular.client.android.fragment.FavTriggersFragment.java

private void showTriggerMenu(final View triggerView, final int triggerPosition) {
    PopupMenu triggerMenu = new PopupMenu(getActivity(), triggerView);

    triggerMenu.getMenuInflater().inflate(R.menu.popup_delete, triggerMenu.getMenu());

    triggerMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from  w w  w  . j a va2  s .  c o  m
        public boolean onMenuItemClick(MenuItem menuItem) {
            Trigger trigger = getTriggersAdapter().getItem(triggerPosition);

            switch (menuItem.getItemId()) {
            case R.id.menu_delete:
                Context context = getActivity();
                SQLStore<Trigger> store = openStore(context);
                store.openSync();
                store.remove(trigger.getId());
                onRefresh();
                return true;

            default:
                return false;
            }
        }
    });

    triggerMenu.show();
}

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//  w w  w. ja  v a 2 s. c o  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();
}