Example usage for android.widget PopupMenu getMenu

List of usage examples for android.widget PopupMenu getMenu

Introduction

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

Prototype

public Menu getMenu() 

Source Link

Document

Returns the Menu associated with this popup.

Usage

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);//  w w w  . ja  v a 2s.co m
    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;
}

From source file:net.nakama.duckdroid.ui.Duckdroid.java

public void btnshowPopupBang(View view) {

    PopupMenu p = new PopupMenu(this, view);
    MenuInflater inflater = p.getMenuInflater();
    p.setOnMenuItemClickListener(bangListener);

    inflater.inflate(this.prefBangMenuId, p.getMenu());
    p.show();//from   www. j a  v  a2s.  c  o  m

}

From source file:freed.viewer.gridview.GridViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    this.mImageThumbSize = getResources().getDimensionPixelSize(dimen.image_thumbnail_size);
    viewerActivityInterface = (ActivityInterface) getActivity();
    executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);

    ImageButton gobackButton = (ImageButton) view.findViewById(id.button_goback);
    gobackButton.setOnClickListener(onGobBackClick);

    filetypeButton = (Button) view.findViewById(id.button_filetype);
    filetypeButton.setOnClickListener(new OnClickListener() {
        @Override/*from  ww  w. ja  v  a2  s . c om*/
        public void onClick(View v) {
            showFileSelectionPopup(v);
        }
    });

    filesSelected = (TextView) view.findViewById(id.textView_filesSelected);

    optionsButton = (Button) view.findViewById(id.button_options);
    optionsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(getContext(), v);

            popup.getMenu().add(0, 0, 0, "Delete File");
            if (!isRootDir && VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN_MR2)
                popup.getMenu().add(0, 1, 1, "StackJpeg");
            if (!isRootDir)
                popup.getMenu().add(0, 2, 2, "Raw to Dng");
            if (!isRootDir)
                popup.getMenu().add(0, 3, 3, "DngStack");
            popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case 0:
                        onDeltedButtonClick.onClick(null);
                        break;
                    case 1:
                        onStackClick.onClick(null);
                        break;
                    case 2:
                        onRawToDngClick.onClick(null);
                        break;
                    case 3:
                        onDngStackClick.onClick(null);
                    }
                    return false;
                }
            });
            popup.show();
        }
    });

    doActionButton = (Button) view.findViewById(id.button_DoAction);
    doActionButton.setVisibility(View.GONE);
    firstload();

    return view;
}

From source file:net.nakama.duckdroid.ui.Duckdroid.java

public void btnshowPopupSetting(View view) {
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    popup.setOnMenuItemClickListener(this);
    inflater.inflate(R.menu.activity_duckdroid, popup.getMenu());
    popup.show();//from  w  w w.ja va  2s  .  c o  m
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.DirectionListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ImageButton btnDisplayMap = (ImageButton) header.findViewById(R.id.btnDisplayMap);
    ImageButton btnShareDirections = (ImageButton) header.findViewById(R.id.btnShareDirections);
    ImageButton btnAlarmDirections = (ImageButton) header.findViewById(R.id.btnAlarmDirections);
    final OtpFragment ofl = this.getFragmentListener();
    final DirectionListFragment dlf = this;
    OnClickListener oclDisplayDirection = new OnClickListener() {
        @Override//ww w . j  a v a2s  .  c  om
        public void onClick(View arg0) {
            ofl.onSwitchedToMainFragment(dlf);
        }
    };
    btnDisplayMap.setOnClickListener(oclDisplayDirection);
    btnShareDirections.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            // create popup menu
            View menuItemView = getView().findViewById(R.id.btnShareDirections);
            PopupMenu popup = new PopupMenu(getActivity(), menuItemView);
            popup.getMenuInflater().inflate(R.menu.share_menu, popup.getMenu());
            menuItemView.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popup));

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {

                    Intent itn = new Intent();
                    itn.setAction(Intent.ACTION_SEND);
                    itn.setType("text/plain");

                    // fill intend content based on chosen menu item
                    switch (item.getItemId()) {
                    case R.id.btnShareDirectionsShort:
                        itn.putExtra(Intent.EXTRA_TEXT, getDepartureArrivalHeaders(false));
                        break;
                    case R.id.btnShareDirectionsDetailed:
                        itn.putExtra(Intent.EXTRA_TEXT, getDepartureArrivalHeaders(true));
                        break;
                    default:
                        break;
                    }
                    startActivity(Intent.createChooser(itn, "Share via"));
                    return true;
                }
            });

            popup.show();
        }
    });
    btnAlarmDirections.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            // create popup menu
            View menuItemView = getView().findViewById(R.id.btnAlarmDirections);
            PopupMenu popup = new PopupMenu(getActivity(), menuItemView);
            popup.getMenuInflater().inflate(R.menu.alarm_menu, popup.getMenu());
            menuItemView.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popup));

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {

                    switch (item.getItemId()) {
                    case R.id.btnAlarmDirectionsAlarm:
                        setAlarmItinerary();
                        break;
                    case R.id.btnAlarmDirectionsNotifications:
                        setNotificationsItinerary();
                        break;
                    case R.id.btnAlarmDirectionsCalendar:
                        setCalendarItinerary();
                        break;
                    default:
                        break;
                    }
                    return true;
                }
            });

            popup.show();
        }
    });

    fromHeader = (TextView) header.findViewById(R.id.fromHeader);
    toHeader = (TextView) header.findViewById(R.id.toHeader);
    departureTimeHeader = (TextView) header.findViewById(R.id.departureTimeHeader);
    arrivalTimeHeader = (TextView) header.findViewById(R.id.arrivalTimeHeader);
    tripList = (Spinner) header.findViewById(R.id.itinerarySelection);

    if (savedInstanceState != null) {
        otpBundle = (OTPBundle) savedInstanceState.getSerializable(OTPApp.BUNDLE_KEY_OTP_BUNDLE);
        fragmentListener.setOTPBundle(otpBundle);
    } else {
        otpBundle = fragmentListener.getOTPBundle();
    }

    fromHeader.setText(otpBundle.getFromText());
    toHeader.setText(otpBundle.getToText());
    setDepartureArrivalHeaders();

    ArrayList<Leg> currentItinerary = new ArrayList<Leg>();
    currentItinerary.addAll(fragmentListener.getCurrentItinerary());
    ArrayList<Itinerary> itineraryList = new ArrayList<Itinerary>();
    itineraryList.addAll(fragmentListener.getCurrentItineraryList());
    int currentItineraryIndex = fragmentListener.getCurrentItineraryIndex();

    ArrayList<Direction> directions = new ArrayList<Direction>();
    DirectionsGenerator dirGen = new DirectionsGenerator(currentItinerary,
            getActivity().getApplicationContext());
    ArrayList<Direction> tempDirections = dirGen.getDirections();
    if (tempDirections != null && !tempDirections.isEmpty()) {
        directions.addAll(tempDirections);
    }

    final Activity activity = this.getActivity();
    String[] itinerarySummaryList = new String[itineraryList.size()];

    boolean isTransitIsTagSet = false;
    for (int i = 0; i < itinerarySummaryList.length; i++) {
        isTransitIsTagSet = false;
        Itinerary it = itineraryList.get(i);
        for (Leg leg : it.legs) {
            TraverseMode traverseMode = TraverseMode.valueOf(leg.mode);
            if (traverseMode.isTransit()) {
                itinerarySummaryList[i] = ConversionUtils.getRouteShortNameSafe(leg.routeShortName,
                        leg.routeLongName, getActivity().getApplicationContext()) + ". ";
                isTransitIsTagSet = true;
                break;
            }
        }
        if (!isTransitIsTagSet) {
            itinerarySummaryList[i] = Integer.toString(i + 1) + ".   ";//Shown index is i + 1, to use 1-based indexes for the UI instead of 0-based
        }
    }

    for (int i = 0; i < itinerarySummaryList.length; i++) {
        Itinerary it = itineraryList.get(i);
        long tripDuration;
        if (PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext())
                .getInt(OTPApp.PREFERENCE_KEY_API_VERSION, OTPApp.API_VERSION_V1) == OTPApp.API_VERSION_V1) {
            tripDuration = it.duration;
        } else {
            tripDuration = it.duration / 1000;
        }
        itinerarySummaryList[i] += getString(R.string.step_by_step_total_duration) + " " + ConversionUtils
                .getFormattedDurationTextNoSeconds(tripDuration, false, getActivity().getApplicationContext());
        if (isTransitIsTagSet) {
            itinerarySummaryList[i] += "   " + getString(R.string.step_by_step_walking_duration) + " "
                    + ConversionUtils.getFormattedDurationTextNoSeconds(it.walkTime, false,
                            getActivity().getApplicationContext());
        }
    }

    ArrayAdapter<String> itineraryAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item, itinerarySummaryList);

    itineraryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    tripList.setAdapter(itineraryAdapter);

    AdapterView.OnItemSelectedListener itinerarySpinnerListener = new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (fragmentListener.getCurrentItineraryIndex() != position) {
                fragmentListener.onItinerarySelected(position, 3);
            }

            setDepartureArrivalHeaders();

            if (!isFragmentFirstLoad) {
                ArrayList<Direction> directions = new ArrayList<Direction>();
                DirectionsGenerator dirGen = new DirectionsGenerator(fragmentListener.getCurrentItinerary(),
                        getActivity().getApplicationContext());
                ArrayList<Direction> tempDirections = dirGen.getDirections();
                if (tempDirections != null && !tempDirections.isEmpty()) {
                    directions.addAll(tempDirections);
                }

                Direction direction_data[] = directions.toArray(new Direction[directions.size()]);

                DirectionExpandableListAdapter adapter = new DirectionExpandableListAdapter(
                        DirectionListFragment.this.getActivity(), R.layout.list_direction_item,
                        R.layout.list_subdirection_item, direction_data);

                elv.setAdapter(adapter);

            }
            openIfNonTransit();

            isFragmentFirstLoad = false;

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    };
    tripList.setSelection(currentItineraryIndex);
    tripList.setOnItemSelectedListener(itinerarySpinnerListener);

    // Populate list with our static array of titles.
    elv = getExpandableListView();

    Direction direction_data[] = directions.toArray(new Direction[directions.size()]);

    DirectionExpandableListAdapter adapter = new DirectionExpandableListAdapter(this.getActivity(),
            R.layout.list_direction_item, R.layout.list_subdirection_item, direction_data);

    elv.addHeaderView(header);

    elv.setAdapter(adapter);

    elv.setGroupIndicator(null); // Get rid of the down arrow

    openIfNonTransit();

    if (savedInstanceState == null) {
        if (otpBundle.isFromInfoWindow()) {
            elv.expandGroup(otpBundle.getCurrentStepIndex());
            elv.setSelectedGroup(otpBundle.getCurrentStepIndex());
            otpBundle.setFromInfoWindow(false);
        }
    }
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindSound(View view, Cursor cursor) {
    AppState appState = AppState.getInstance();

    final View card = view;
    final View downloadFrame = view.findViewById(R.id.sound_download_frame);
    final TextView tv = (TextView) view.findViewById(R.id.grid_text);
    final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image);
    final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav);
    final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu);

    final String soundName = cursor
            .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME));
    String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME));
    final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC));
    final boolean favorite = appState.favSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1;
    final boolean widget = appState.widgetSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1;
    final boolean downloaded = cursor
            .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0;

    new Handler().post(new Runnable() {
        @Override//w  w  w.j av  a  2 s  .c  o  m
        public void run() {
            ContentValues cv = new ContentValues();
            File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg");

            if (downloaded && !sndFile.exists()) {
                cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0);
                mContext.getContentResolver().update(
                        Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null,
                        null);
            }
        }
    });

    final View.OnClickListener playSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String category = mContext.getString(R.string.ana_cat_sound);
            String action = mContext.getString(R.string.ana_act_play);

            Bundle extras = new Bundle();
            extras.putString(SoundFragment.SOUND_TO_PLAY, soundName);
            extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet());
            Intent intent = new Intent(mContext, SoundService.class);
            intent.putExtras(extras);

            mContext.startService(intent);
            AnalyticsUtils.sendEvent(category, action, soundName);
        }
    };

    final View.OnClickListener downloadSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            card.setOnClickListener(null);
            RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setInterpolator(new BounceInterpolator());
            animation.setFillAfter(true);
            animation.setFillEnabled(true);
            animation.setDuration(1000);
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.RESTART);
            downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation);

            DownloadService.startActionDownloadSound(mContext, soundName,
                    new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this));
        }
    };

    if (downloaded) {
        downloadFrame.setVisibility(View.GONE);
        downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation();
        card.setOnClickListener(playSound);
    } else {
        downloadFrame.setAlpha(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1);
        downloadFrame.setVisibility(View.VISIBLE);
        card.setOnClickListener(downloadSound);
    }

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ImageView menuIc = (ImageView) v;
            PopupMenu popup = new PopupMenu(mContext, menuIc);
            Menu menu = popup.getMenu();
            popup.getMenuInflater().inflate(R.menu.sound_menu, menu);

            if (favorite)
                menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris");
            if (widget)
                menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget");

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_sound_fav:
                        SoundUtils.addRemoveFavorite(mContext, soundName);
                        return true;
                    case R.id.action_sound_wid:
                        SoundUtils.addRemoveWidget(mContext, soundName);
                        return true;
                    /*case R.id.action_sound_add:
                       return true;*/
                    case R.id.action_sound_ring:
                        SoundUtils.addRingtone(mContext, soundName, description);
                        return true;
                    case R.id.action_sound_share:
                        AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext),
                                mContext.getString(R.string.ana_act_weblink), soundName);
                        ClipboardManager clipboard = (ClipboardManager) mContext
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show();
                        return true;
                    case R.id.action_sound_delete:
                        SoundUtils.delete(mContext, soundName);
                        return true;
                    default:
                        return false;
                    }
                }
            });

            popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark));
                }
            });
            menuIc.setColorFilter(mContext.getResources().getColor(R.color.black));

            popup.show();
        }
    });

    tv.setText(description);
    siv.setTag(imgId);

    if (appState.favSounds.contains(soundName)) {
        star.setVisibility(View.VISIBLE);
    } else if (favorite) {
        star.setVisibility(View.VISIBLE);
        appState.favSounds.add(soundName);
    } else {
        star.setVisibility(View.INVISIBLE);
    }

    File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg");
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv);
}

From source file:info.papdt.blacklight.support.adapter.WeiboAdapter.java

void buildPopup(final ViewHolder h) {
    PopupMenu p = new PopupMenu(mContext, h.popup);
    p.inflate(R.menu.popup);//from   w  w w .  j av  a  2 s. c o m
    final Menu m = p.getMenu();

    // Show needed items
    m.findItem(R.id.popup_copy).setVisible(true);
    if (h.msg instanceof CommentModel) {
        m.findItem(R.id.popup_reply).setVisible(true);

        CommentModel cmt = (CommentModel) h.msg;
        if (cmt.user.id.equals(mUid)
                || (cmt.status != null && cmt.status.user != null && cmt.status.user.id.equals(mUid))) {
            m.findItem(R.id.popup_delete).setVisible(true);
        }
    } else {
        m.findItem(R.id.popup_repost).setVisible(true);
        m.findItem(R.id.popup_comment).setVisible(true);

        if (h.msg.liked) {
            m.findItem(R.id.popup_unlike).setVisible(true);
        } else {
            m.findItem(R.id.popup_like).setVisible(true);
        }

        if (h.msg.user != null && h.msg.user.id.equals(mUid)) {
            m.findItem(R.id.popup_delete).setVisible(true);
        }
    }

    p.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.popup_delete) {
                h.delete();
            } else if (id == R.id.popup_copy) {
                h.copy();
            } else if (id == R.id.popup_comment || id == R.id.popup_reply) {
                h.reply();
            } else if (id == R.id.popup_repost) {
                h.repost();
            } else if (id == R.id.popup_like || id == R.id.popup_unlike) {
                new LikeTask().execute(h.msg, h, m);
            }

            return true;
        }
    });

    // Pop up!
    p.show();
}

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/* w  ww  .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:im.vector.fragments.GroupsFragment.java

@SuppressLint("NewApi")
private void displayGroupPopupMenu(final Group group, final View actionView) {
    final Context context = getActivity();
    final PopupMenu popup;

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        popup = new PopupMenu(context, actionView, Gravity.END);
    } else {/*from w  ww .j av  a2  s .c  om*/
        popup = new PopupMenu(context, actionView);
    }
    popup.getMenuInflater().inflate(R.menu.vector_home_group_settings, popup.getMenu());
    CommonActivityUtils.tintMenuIcons(popup.getMenu(),
            ThemeUtils.getColor(context, R.attr.settings_icon_tint_color));

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.ic_action_select_remove_group: {
                leaveOrReject(group.getGroupId());
                break;
            }
            }
            return false;
        }
    });

    // force to display the icon
    try {
        Field[] fields = popup.getClass().getDeclaredFields();
        for (Field field : fields) {
            if ("mPopup".equals(field.getName())) {
                field.setAccessible(true);
                Object menuPopupHelper = field.get(popup);
                Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
                Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
                setForceIcons.invoke(menuPopupHelper, true);
                break;
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "## displayGroupPopupMenu() : failed " + e.getMessage());
    }

    popup.show();
}

From source file:org.akop.crosswords.fragment.CrosswordFragment.java

@Override
public void onCellLongPressed(CrosswordView view, Crossword.Word word, int cell) {
    // Get the highlighted cell's rectangle
    Rect rect = view.getCellRect(word, cell);

    // Offset the placeholder to the same position as the cell
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(rect.width(), rect.height());
    lp.setMargins(rect.left, rect.top, 0, 0);
    mMenuPlaceholder.setLayoutParams(lp);

    // Save the word/cell associated with the popup
    mPopupWord = word;//from   www.  j  a v  a 2  s.  com
    mPopupCell = cell;

    // Initialize and show the popup menu
    PopupMenu popup = new PopupMenu(getActivity(), mMenuPlaceholder);
    popup.setOnMenuItemClickListener(mCellPopupListener);

    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.fragment_crossword_popup_cell, popup.getMenu());

    popup.show();
}