Example usage for android.widget PopupMenu PopupMenu

List of usage examples for android.widget PopupMenu PopupMenu

Introduction

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

Prototype

public PopupMenu(Context context, View anchor) 

Source Link

Document

Constructor to create a new popup menu with an anchor view.

Usage

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_category(final View anchor) {
    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_category, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from  w w w.  j  a va 2  s  . c  o  m
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.add:
                onOpt_category_add(anchor);
                break;
            case R.id.rename:
                onOpt_category_rename(anchor);
                break;
            case R.id.delete:
                onOpt_category_delete(anchor);
                break;
            default:
                eAssert(false);
            }
            return true;
        }
    });
    popup.show();
}

From source file:com.custom.music.MusicBrowserActivity.java

/**
 * M: Create fake menu.//from  w ww  .j a va  2  s. c  o  m
 */
private void createFakeMenu() {
    if (mHasMenukey) {
        Log.w(TAG, "<createFakeMenu> Quit when there has Menu Key", Log.APP);
        return;
    }
    if (mOrientaiton == Configuration.ORIENTATION_LANDSCAPE) {
        mOverflowMenuButtonId = R.id.overflow_menu;
        mOverflowMenuButton = findViewById(R.id.overflow_menu);
    } else {
        mOverflowMenuButtonId = R.id.overflow_menu_nowplaying;
        mOverflowMenuButton = findViewById(R.id.overflow_menu_nowplaying);
        View parent = (View) mOverflowMenuButton.getParent();
        if (parent != null) {
            parent.setVisibility(View.VISIBLE);
        }
    }
    mOverflowMenuButton.setVisibility(View.VISIBLE);
    mOverflowMenuButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "<createFakeMenu> onClick()", Log.APP);
            if (v.getId() == mOverflowMenuButtonId) {
                final PopupMenu popupMenu = new PopupMenu(MusicBrowserActivity.this, mOverflowMenuButton);
                mPopupMenu = popupMenu;
                final Menu menu = popupMenu.getMenu();
                onCreateOptionsMenu(menu);
                popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        return onOptionsItemSelected(item);
                    }
                });
                popupMenu.setOnDismissListener(new OnDismissListener() {
                    public void onDismiss(PopupMenu menu) {
                        mPopupMenuShowing = false;
                        Log.i(TAG, "<createFakeMenu> onDismiss() called", Log.APP);
                        return;
                    }
                });
                onPrepareOptionsMenu(menu);
                mPopupMenuShowing = true;
                if (popupMenu != null) {
                    Log.i(TAG, "<createFakeMenu> popupMenu.show()", Log.APP);
                    popupMenu.show();
                }
            }
        }
    });
}

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

private void display() {
    TextView tv = null;//ww  w  . j  a v  a2 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.rm3l.ddwrt.tiles.status.wireless.WirelessClientsTile.java

/**
 * Called when a previously created loader has finished its load.  Note
 * that normally an application is <em>not</em> allowed to commit fragment
 * transactions while in this call, since it can happen after an
 * activity's state is saved.  See {@link android.support.v4.app.FragmentManager#beginTransaction()
 * FragmentManager.openTransaction()} for further discussion on this.
 * <p/>/* w  ww.  j  av a  2s . c  o  m*/
 * <p>This function is guaranteed to be called prior to the release of
 * the last data that was supplied for this Loader.  At this point
 * you should remove all use of the old data (since it will be released
 * soon), but should not do your own release of the data since its Loader
 * owns it and will take care of that.  The Loader will take care of
 * management of its data so you don't have to.  In particular:
 * <p/>
 * <ul>
 * <li> <p>The Loader will monitor for changes to the data, and report
 * them to you through new calls here.  You should not monitor the
 * data yourself.  For example, if the data is a {@link android.database.Cursor}
 * and you place it in a {@link android.widget.CursorAdapter}, use
 * the {@link android.widget.CursorAdapter#CursorAdapter(android.content.Context,
 * android.database.Cursor, int)} constructor <em>without</em> passing
 * in either {@link android.widget.CursorAdapter#FLAG_AUTO_REQUERY}
 * or {@link android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER}
 * (that is, use 0 for the flags argument).  This prevents the CursorAdapter
 * from doing its own observing of the Cursor, which is not needed since
 * when a change happens you will get a new Cursor throw another call
 * here.
 * <li> The Loader will release the data once it knows the application
 * is no longer using it.  For example, if the data is
 * a {@link android.database.Cursor} from a {@link android.content.CursorLoader},
 * you should not call close() on it yourself.  If the Cursor is being placed in a
 * {@link android.widget.CursorAdapter}, you should use the
 * {@link android.widget.CursorAdapter#swapCursor(android.database.Cursor)}
 * method so that the old Cursor is not closed.
 * </ul>
 *
 * @param loader The Loader that has finished.
 * @param data   The data generated by the Loader.
 */
@Override
public void onLoadFinished(Loader<ClientDevices> loader, ClientDevices data) {
    Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data);

    layout.findViewById(R.id.tile_status_wireless_clients_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_wireless_clients_layout_list_container).setVisibility(View.VISIBLE);
    layout.findViewById(R.id.tile_status_wireless_clients_togglebutton_container).setVisibility(View.VISIBLE);

    if (data == null || (data.getDevices().isEmpty()
            && !(data.getException() instanceof DDWRTTileAutoRefreshNotAllowedException))) {
        data = new ClientDevices().setException(new DDWRTNoDataException("No Data!"));
    }

    @NotNull
    final TextView errorPlaceHolderView = (TextView) this.layout
            .findViewById(R.id.tile_status_wireless_clients_error);

    @Nullable
    final Exception exception = data.getException();

    if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {

        if (exception == null) {
            errorPlaceHolderView.setVisibility(View.GONE);
        }

        final GridLayout clientsContainer = (GridLayout) this.layout
                .findViewById(R.id.tile_status_wireless_clients_layout_list_container);
        clientsContainer.removeAllViews();
        clientsContainer.setBackgroundColor(
                mParentFragmentActivity.getResources().getColor(android.R.color.transparent));

        final Set<Device> devices = data.getDevices(MAX_CLIENTS_TO_SHOW_IN_TILE);
        final int themeBackgroundColor = getThemeBackgroundColor(mParentFragmentActivity, mRouter.getUuid());
        final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid());
        for (final Device device : devices) {

            final CardView cardView = (CardView) mParentFragmentActivity.getLayoutInflater()
                    .inflate(R.layout.tile_status_wireless_client, null);

            //Create Options Menu
            final ImageButton tileMenu = (ImageButton) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_menu);

            if (!isThemeLight) {
                //Set menu background to white
                tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark);
            }

            cardView.setCardBackgroundColor(themeBackgroundColor);

            //Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners.
            cardView.setPreventCornerOverlap(true);
            //Add padding in API v21+ as well to have the same measurements with previous versions.
            cardView.setUseCompatPadding(true);

            final TextView deviceName = (TextView) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_name);
            final String name = device.getName();
            deviceName.setText(name);

            final TextView deviceMac = (TextView) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_mac);
            final String macAddress = device.getMacAddress();
            deviceMac.setText(macAddress);

            final TextView deviceIp = (TextView) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_ip);
            final String ipAddress = device.getIpAddress();
            final boolean isThisDevice = (ipAddress != null && ipAddress.equals(mCurrentIpAddress));
            deviceIp.setText(ipAddress);
            if (isThisDevice) {
                final View thisDevice = cardView.findViewById(R.id.tile_status_wireless_client_device_this);
                if (isThemeLight) {
                    //Set text color to blue
                    ((TextView) thisDevice)
                            .setTextColor(mParentFragmentActivity.getResources().getColor(R.color.blue));
                }
                thisDevice.setVisibility(View.VISIBLE);
            }

            cardView.setOnClickListener(new DeviceOnClickListener(device));

            clientsContainer.addView(cardView);

            tileMenu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v);
                    popup.setOnMenuItemClickListener(new DeviceOnMenuItemClickListener(device));
                    final MenuInflater inflater = popup.getMenuInflater();

                    final Menu menu = popup.getMenu();

                    inflater.inflate(R.menu.tile_status_wireless_client_options, menu);

                    if (isThisDevice) {
                        //WOL not needed as this is the current device
                        menu.findItem(R.id.tile_status_wireless_client_wol).setEnabled(false);
                    }

                    popup.show();
                }
            });
        }

        final Button showMore = (Button) this.layout.findViewById(R.id.tile_status_wireless_clients_show_more);
        //Whether to display 'Show more' button
        if (data.getDevicesCount() > MAX_CLIENTS_TO_SHOW_IN_TILE) {
            showMore.setVisibility(View.VISIBLE);
            showMore.setOnClickListener(this);
        } else {
            showMore.setVisibility(View.GONE);
        }

    }

    if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final Throwable rootCause = Throwables.getRootCause(exception);
        errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null"));
        final Context parentContext = this.mParentFragmentActivity;
        errorPlaceHolderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                //noinspection ThrowableResultOfMethodCallIgnored
                if (rootCause != null) {
                    Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
        errorPlaceHolderView.setVisibility(View.VISIBLE);
    }

    doneWithLoaderInstance(this, loader, R.id.tile_status_wireless_clients_togglebutton_title,
            R.id.tile_status_wireless_clients_togglebutton_separator);

    Log.d(LOG_TAG, "onLoadFinished(): done loading!");
}

From source file:org.catnut.fragment.TweetFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.comments, null, false);
    mListView = (ListView) view.findViewById(android.R.id.list);
    mSendText = (EditText) view.findViewById(R.id.action_reply);
    mSend = (ImageView) view.findViewById(R.id.action_send);
    mTextCounter = (TextView) view.findViewById(R.id.text_counter);
    mOverflow = (ImageView) view.findViewById(R.id.action_overflow);
    mPopupMenu = new PopupMenu(getActivity(), mOverflow);
    // for our headers
    mTweetLayout = inflater.inflate(R.layout.tweet, null);
    mAvatar = (ImageView) mTweetLayout.findViewById(R.id.avatar);
    mRemark = (TextView) mTweetLayout.findViewById(R.id.remark);
    mScreenName = (TextView) mTweetLayout.findViewById(R.id.screen_name);
    mText = (TweetTextView) mTweetLayout.findViewById(R.id.text);
    mReplayCount = (TextView) mTweetLayout.findViewById(R.id.reply_count);
    mReteetCount = (TextView) mTweetLayout.findViewById(R.id.reteet_count);
    mFavoriteCount = (TextView) mTweetLayout.findViewById(R.id.like_count);
    mSource = (TextView) mTweetLayout.findViewById(R.id.source);
    mCreateAt = (TextView) mTweetLayout.findViewById(R.id.create_at);
    mThumbs = (ImageView) mTweetLayout.findViewById(R.id.thumbs);
    mPicsOverflow = mTweetLayout.findViewById(R.id.pics_overflow);
    mRetweetLayout = (ViewStub) mTweetLayout.findViewById(R.id.view_stub);
    // just return the list
    return view;//  w  ww.ja v a2 s. com
}

From source file:com.scooter1556.sms.androidtv.fragment.AudioPlayerFragment.java

public void showOptionsMenu(View v) {
    PopupMenu popup = new PopupMenu(getActivity(), v);

    // This activity implements OnMenuItemClickListener
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.menu_playlist_item);
    popup.show();//ww  w.ja  v  a 2  s . c  om
}

From source file:org.alfresco.mobile.android.application.fragments.user.UserProfileFragment.java

private void display() {
    TextView tv = null;/*  w ww .  j  ava 2  s .co  m*/
    ImageView bIm = null;

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

    // JOB TITLE
    tv = (TextView) viewById(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) viewById(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) viewById(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(UserProfileFragment.this);
                popup.show();
            }
        });
    } else {
        hide(R.id.action_call);
    }

    // SKype
    if (person.getSkypeId() != null && !person.getSkypeId().isEmpty()) {
        displayGroup();
        tv = (TextView) viewById(R.id.skypeId_value);
        tv.setText(person.getSkypeId());
        bIm = (ImageView) viewById(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(UserProfileFragment.this);
                popup.show();
            }
        });
    } else {
        hide(R.id.action_skype);
        hide(R.id.skypeId_group);
    }

    // IM
    if (person.getInstantMessageId() != null && !person.getInstantMessageId().isEmpty()) {
        displayGroup();
        tv = (TextView) viewById(R.id.instantMessagingId_value);
        tv.setText(person.getInstantMessageId());
    } else {
        hide(R.id.instantMessagingId_group);
    }

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

    if (!displayContactDetails) {
        hide(R.id.contactInfo_group);
        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) viewById(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) viewById(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(UserProfileFragment.this);
                popup.show();
            }
        });
    } else {
        hide(R.id.action_email);
    }

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

    if (!displayCompanyDetails) {
        hide(R.id.company_group);
    }
}

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 www . j  av  a2 s .com
    });

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

}

From source file:com.notalenthack.blaster.CommandActivity.java

@Override
public void onClick(View v) {
    Integer position = (Integer) v.getTag();
    if (v.getId() == R.id.btnEditCommand) {
        final Command cmd = mListAdapter.getCommand(position);
        Log.d(TAG, "Edit button click for position " + position);
        //Creating the instance of PopupMenu
        PopupMenu popup = new PopupMenu(this, v);
        //Inflating the Popup using xml file
        popup.getMenuInflater().inflate(R.menu.edit_delete, popup.getMenu());
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override/*from  ww  w. j a  v a 2 s  .c om*/
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.edit) {
                    editCommand(cmd);
                } else if (item.getItemId() == R.id.delete) {
                    mListAdapter.deleteCommand(cmd);
                } else {
                    return false;
                }
                saveCommands(); // update commands in pref for presistent
                mListAdapter.notifyDataSetChanged();
                return true;
            }
        });

        // show the popup
        popup.show();

    } else if (v.getId() == R.id.btnCommandAction) {
        Log.d(TAG, "Play button click for position " + position);
        handlePlayCommand(position);
    }
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

private PopupMenu createPopupMenu(View view, int menuId) {
    int[] pos = new int[2];
    view.getLocationOnScreen(pos);/*from   ww  w  . j ava  2  s .com*/
    View moveView = ((HostView) getParent()).getMovableView();
    moveView.layout(pos[0], pos[1], pos[0] + 10, pos[1] + 10);

    PopupMenu popup = new PopupMenu(getContext(), moveView);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(menuId, popup.getMenu());
    return popup;
}