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:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java

public AdminNVRAMTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments,
        @Nullable Router router) {//www  .  j a  va  2  s  .  c  o m
    super(parentFragment, arguments, router, R.layout.tile_admin_nvram, R.id.tile_admin_nvram_togglebutton);

    sortIds.put(R.id.tile_admin_nvram_sort_default, 11);
    sortIds.put(R.id.tile_admin_nvram_sort_asc, 12);
    sortIds.put(R.id.tile_admin_nvram_sort_desc, 13);

    this.mNvramInfoDefaultSorting = new NVRAMInfo();
    mRecyclerView = (RecyclerView) layout.findViewById(R.id.tile_admin_nvram_ListView);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    // allows for optimizations if all items are of the same size:
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(mParentFragmentActivity);
    mLayoutManager.scrollToPosition(0);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    mAdapter = new NVRAMDataRecyclerViewAdapter(mParentFragmentActivity, router, mNvramInfoDefaultSorting);
    mRecyclerView.setAdapter(mAdapter);

    //Create Options Menu
    final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_admin_nvram_menu);

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

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

            final Menu menu = popup.getMenu();

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

            //Disable menu item from preference
            Integer currentSort = null;
            if (mParentFragmentPreferences != null) {
                currentSort = sortIds.inverse().get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT),
                        sortIds.get(R.id.tile_admin_nvram_sort_default)));
            }

            if (currentSort == null) {
                currentSort = R.id.tile_admin_nvram_sort_default;
            }

            final MenuItem currentSortMenuItem = menu.findItem(currentSort);
            if (currentSortMenuItem != null) {
                currentSortMenuItem.setEnabled(false);
            }

            // Locate MenuItem with ShareActionProvider
            final MenuItem shareMenuItem = menu.findItem(R.id.tile_admin_nvram_share);

            // Fetch and store ShareActionProvider
            mShareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider();

            popup.show();
        }

    });

    //Handle for Search EditText
    final EditText filterEditText = (EditText) this.layout.findViewById(R.id.tile_admin_nvram_filter);
    //Initialize with existing search data
    filterEditText.setText(mParentFragmentPreferences != null
            ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING)
            : EMPTY_STRING);

    filterEditText.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_LEFT = 0;
            final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            final int DRAWABLE_BOTTOM = 3;

            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getRawX() >= (filterEditText.getRight()
                        - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                    //'Clear' button - clear data, and reset everything out
                    //Reset everything
                    filterEditText.setText(EMPTY_STRING);

                    final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData();
                    //Update adapter in the preferences
                    if (mParentFragmentPreferences != null) {
                        final Integer currentSort = sortIds.inverse()
                                .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1));
                        if (currentSort == null || currentSort <= 0) {
                            mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData);
                        } else {
                            switch (currentSort) {
                            case R.id.tile_admin_nvram_sort_asc:
                                //asc
                                mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE);
                                break;
                            case R.id.tile_admin_nvram_sort_desc:
                                //desc
                                mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE);
                                break;
                            case R.id.tile_admin_nvram_sort_default:
                            default:
                                mNvramInfoToDisplay = new HashMap<>();
                                break;
                            }
                            mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData);
                        }
                    } else {
                        mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData);
                    }

                    ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplay);
                    mAdapter.notifyDataSetChanged();

                    if (mParentFragmentPreferences != null) {
                        final SharedPreferences.Editor editor = mParentFragmentPreferences.edit();
                        editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING);
                        editor.apply();
                    }
                    return true;
                }
            }
            return false;
        }
    });

    filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                final String textToFind = filterEditText.getText().toString();
                if (isNullOrEmpty(textToFind)) {
                    //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present
                    return true;
                }
                final String existingSearch = mParentFragmentPreferences != null
                        ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null)
                        : null;

                if (mParentFragmentPreferences != null) {
                    if (textToFind.equalsIgnoreCase(existingSearch)) {
                        //No need to go further as this is already the string we are looking for
                        return true;
                    }
                    final SharedPreferences.Editor editor = mParentFragmentPreferences.edit();
                    editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind);
                    editor.apply();
                }

                //Filter out (and sort by user-preference)
                final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData();
                //Update adapter in the preferences
                final Map<Object, Object> mNvramInfoToDisplayCopy;
                if (mParentFragmentPreferences != null) {
                    final Integer currentSort = sortIds.inverse()
                            .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1));
                    if (currentSort == null || currentSort <= 0) {
                        mNvramInfoToDisplayCopy = new HashMap<>(mNvramInfoDefaultSortingData);
                    } else {
                        switch (currentSort) {
                        case R.id.tile_admin_nvram_sort_asc:
                            //asc
                            mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE);
                            break;
                        case R.id.tile_admin_nvram_sort_desc:
                            //desc
                            mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE);
                            break;
                        case R.id.tile_admin_nvram_sort_default:
                        default:
                            mNvramInfoToDisplayCopy = new HashMap<>();
                            break;
                        }
                        //noinspection ConstantConditions
                        for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) {
                            final Object key = entry.getKey();
                            final Object value = entry.getValue();
                            if (key == null) {
                                continue;
                            }
                            if (containsIgnoreCase(key.toString(), textToFind)
                                    || containsIgnoreCase(value.toString(), textToFind)) {
                                mNvramInfoToDisplayCopy.put(key, value);
                            }
                        }
                    }
                } else {
                    mNvramInfoToDisplayCopy = new HashMap<>();
                    //noinspection ConstantConditions
                    for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) {
                        final Object key = entry.getKey();
                        final Object value = entry.getValue();
                        if (key == null) {
                            continue;
                        }
                        if (containsIgnoreCase(key.toString(), textToFind)
                                || containsIgnoreCase(value.toString(), textToFind)) {
                            mNvramInfoToDisplayCopy.put(key, value);
                        }
                    }
                }

                ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplayCopy);
                mAdapter.notifyDataSetChanged();

                return true;
            }
            return false;
        }
    });

}

From source file:com.arcgis.android.samples.localdata.localrasterdata.FileBrowserFragment.java

private void initializeFileListView() {
    ListView lView = (ListView) (getView().findViewById(R.id.fileListView));
    lView.setBackgroundColor(Color.LTGRAY);
    LinearLayout.LayoutParams lParam = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);//from   w w  w .ja  v  a  2  s .co m
    lParam.setMargins(15, 5, 15, 5);
    lView.setAdapter(this.adapter);
    lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            chosenFile = fileList.get(position).file;
            final File sel = new File(path + "/" + chosenFile);
            if (sel.isDirectory()) {
                // Directory
                if (sel.canRead()) {
                    // Adds chosen directory to list
                    pathDirsList.add(chosenFile);
                    path = new File(sel + "");
                    loadFileList();
                    adapter.notifyDataSetChanged();
                    updateCurrentDirectoryTextView();
                } else {
                    showToast("Path does not exist or cannot be read");
                }
            } else {
                // File picked or an empty directory message clicked
                if (!mDirectoryShownIsEmpty) {
                    // show a popup menu to allow users to open a raster layer for
                    // different purpose including basemap layer, operational layer,
                    // elevation data source for BlendRenderer, or some combinations.
                    PopupMenu popupMenu = new PopupMenu(getActivity(), view);
                    popupMenu.inflate(R.menu.file_browser_popup_menu);
                    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                            case R.id.menu_raster_base_layer:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.BASEMAP_LAYER);
                                break;
                            case R.id.menu_raster_operational_layer:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.OPERATIONAL_LAYER);
                                break;
                            case R.id.menu_raster_elevation_source:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.ELEVATION_SOURCE);
                                break;
                            case R.id.menu_raster_base_elevation:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.BASEMAP_LAYER_AND_ELEVATION_SOURCE);
                                break;
                            case R.id.menu_raster_operational_elevation:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.OPERATIONAL_LAYER_AND_ELEVATION_SOURCE);
                                break;
                            }
                            return true;
                        }
                    });
                    popupMenu.show();
                }
            }
        }
    });

}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

private void showManehMenu() {
    View p = findViewById(R.id.anchorer);
    progressbar.setVisibility(View.GONE);

    final PopupMenu popup = new PopupMenu(this, p);
    //Inflating the Popup using xml file  
    for (ManehCode m : CommonPlace.manehCodes) {
        if (!m.Maneh_fldCode.equals("0")) {
            int cnt = ReadingListDetailDA.getInstance(this).getCount("HeaderID=? and fldManehCodeNow=?", "",
                    new String[] { CommonPlace.currentReadingList.id + "", m.Maneh_fldCode });
            popup.getMenu().add(0, Integer.parseInt(m.Maneh_fldCode), 0, m.fldTiltle + "\t" + cnt);
        }//ww  w.ja va  2 s.  c  o m
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            filterManeh(item.getItemId(), item.getTitle().toString());
            return true;
        }
    });

    final Handler handler1 = new Handler();
    progressbar.setVisibility(View.GONE);
    //android.R.attr.progressBarStyleLarge
    handler1.postDelayed(new Runnable() {
        @Override
        public void run() {
            popup.show();
        }
    }, 100);
}

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  ww w  . j  a va2 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.gigabytedevelopersinc.app.calculator.Calculator.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.overflow_menu:
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();//  w w w . j  a  v  a2 s .c o  m
            mInterstitialAd.setAdListener(new AdListener() {
                public void onAdClosed() {
                    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                            .build();
                    mInterstitialAd.loadAd(adRequest);
                    PopupMenu menu = constructPopupMenu();
                    if (menu != null) {
                        menu.show();
                    }
                }
            });
        } else {
            PopupMenu menu = constructPopupMenu();
            if (menu != null) {
                menu.show();
            }
        }
        break;
    }
}

From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java

@Override
public void onPopupMenuClick(View v, final int seasonTvdbId, final int seasonNumber) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.seasons_popup_menu);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/* www .j  a  va2s.com*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_action_seasons_watched_all: {
                onFlagSeasonWatched(seasonTvdbId, seasonNumber, true);
                fireTrackerEventContextMenu("Flag all watched");
                return true;
            }
            case R.id.menu_action_seasons_watched_none: {
                onFlagSeasonWatched(seasonTvdbId, seasonNumber, false);
                fireTrackerEventContextMenu("Flag all unwatched");
                return true;
            }
            case R.id.menu_action_seasons_collection_add: {
                onFlagSeasonCollected(seasonTvdbId, seasonNumber, true);
                fireTrackerEventContextMenu("Flag all collected");
                return true;
            }
            case R.id.menu_action_seasons_collection_remove: {
                onFlagSeasonCollected(seasonTvdbId, seasonNumber, false);
                fireTrackerEventContextMenu("Flag all uncollected");
                return true;
            }
            case R.id.menu_action_seasons_skip: {
                onFlagSeasonSkipped(seasonTvdbId, seasonNumber);
                fireTrackerEventContextMenu("Flag all skipped");
                return true;
            }
            case R.id.menu_action_seasons_manage_lists: {
                ManageListsDialogFragment.showListsDialog(seasonTvdbId, ListItemTypes.SEASON,
                        getFragmentManager());
                fireTrackerEventContextMenu("Manage lists");
                return true;
            }
            }
            return false;
        }
    });
    popupMenu.show();
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

private void showMenuColumnsOptions(View view) {
    final List<String> list = new ArrayList<String>();
    final List<Long> types = new ArrayList<Long>();

    ArrayList<Entity> userEntityList = DataFramework.getInstance().getEntityList("users",
            "service is null or service = \"twitter.com\"");
    for (Entity user : userEntityList) {
        list.add(getString(R.string.addColumnUser, user.getString("name")));
        types.add(user.getId());//from   w w w  . j  a v  a2s . c o  m
    }
    list.add(getString(R.string.addTrendingTopic));
    types.add(1001L);
    list.add(getString(R.string.addSavedTweet));
    types.add(1002L);
    list.add(getString(R.string.sortColumns));
    types.add(1003L);
    list.add(getString(R.string.removeColumns));
    types.add(1004L);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        PopupMenu popupMenu = new PopupMenu(this, view);
        int count = 0;
        for (String item : list) {
            popupMenu.getMenu().add(Menu.NONE, count, Menu.NONE, item);
            count++;
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                long id = types.get(item.getItemId());
                String title = list.get(item.getItemId());
                switch ((int) id) {
                case 1001:
                    newTrending();
                    break;
                case 1002:
                    openSavedTweetColumn();
                    break;
                case 1003:
                    goToSortColumns();
                    break;
                case 1004:
                    goToRemoveColumns();
                    break;
                default:
                    showActionBarIndicatorAndMovePager(-1);
                    showDialogAddColumnUser(title, id);
                    break;
                }
                return true;
            }
        });
        popupMenu.show();
    } else {
        AlertDialogFragment frag = new AlertDialogFragment();
        Bundle args = new Bundle();
        args.putInt(AlertDialogFragment.KEY_ALERT_TITLE, R.string.actions);
        args.putBoolean(AlertDialogFragment.KEY_ALERT_HAS_POSITIVE_BUTTON, false);
        args.putBoolean(AlertDialogFragment.KEY_ALERT_CANCELABLE, false);
        args.putStringArrayList(AlertDialogFragment.KEY_ALERT_ARRAY_STRING_ITEMS, (ArrayList<String>) list);
        frag.setArguments(args);
        frag.setAlertButtonListener(new AlertDialogFragment.AlertButtonListener() {
            @Override
            public void OnAlertButtonOk() {
            }

            @Override
            public void OnAlertButtonCancel() {
            }

            @Override
            public void OnAlertButtonNeutral() {
            }

            @Override
            public void OnAlertItems(int which) {
                long id = types.get(which);
                String title = list.get(which);
                switch ((int) id) {
                case 1001:
                    newTrending();
                    break;
                case 1002:
                    openSavedTweetColumn();
                    break;
                case 1003:
                    goToSortColumns();
                    break;
                case 1004:
                    goToRemoveColumns();
                    break;
                default:
                    showActionBarIndicatorAndMovePager(-1);
                    showDialogAddColumnUser(title, id);
                    break;
                }
            }
        });
        frag.show(getSupportFragmentManager(), "dialog");
    }
}

From source file:org.brandroid.openmanager.fragments.ContentFragment.java

public boolean createContextMenu(final OpenPath file, final AdapterView<?> list, final View view, final int pos,
        final int xOffset, final int yOffset) {
    Logger.LogInfo(getClassName() + ".onItemLongClick: " + file);

    final OpenContextMenuInfo info = new OpenContextMenuInfo(file);

    if (!OpenExplorer.USE_PRETTY_CONTEXT_MENUS) {
        if (Build.VERSION.SDK_INT > 10) {
            final PopupMenu pop = new PopupMenu(view.getContext(), view);
            pop.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    if (onOptionsItemSelected(item)) {
                        pop.dismiss();/*from ww w  .  ja v  a 2 s . co  m*/
                        return true;
                    } else if (getExplorer() != null)
                        return getExplorer().onIconContextItemSelected(pop, item, item.getMenuInfo(), view);
                    return false;
                }
            });
            pop.getMenuInflater().inflate(R.menu.context_file, pop.getMenu());
            onPrepareOptionsMenu(pop.getMenu());
            if (DEBUG)
                Logger.LogDebug("PopupMenu.show()");
            pop.show();
            return true;
        } else
            return list.showContextMenu();
    } else if (OpenExplorer.BEFORE_HONEYCOMB || !OpenExplorer.USE_ACTIONMODE) {

        try {
            //View anchor = view; //view.findViewById(R.id.content_context_helper);
            //if(anchor == null) anchor = view;
            //view.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            //Rect r = new Rect(view.getLeft(),view.getTop(),view.getMeasuredWidth(),view.getMeasuredHeight());
            MenuBuilder cmm = IconContextMenu.newMenu(list.getContext(), R.menu.context_file);
            if (!file.canRead()) {
                MenuUtils.setMenuEnabled(cmm, false);
                MenuUtils.setMenuEnabled(cmm, true, R.id.menu_context_info);
            }
            MenuUtils.setMenuEnabled(cmm, file.canWrite(), R.id.menu_context_paste, R.id.menu_context_cut,
                    R.id.menu_context_delete, R.id.menu_context_rename);
            onPrepareOptionsMenu(cmm);

            //if(!file.isArchive()) hideItem(cmm, R.id.menu_context_unzip);
            if (getClipboard().size() > 0)
                MenuUtils.setMenuVisible(cmm, false, R.id.menu_multi);
            else
                MenuUtils.setMenuVisible(cmm, false, R.id.menu_context_paste);
            MenuUtils.setMenuEnabled(cmm, !file.isDirectory(), R.id.menu_context_edit, R.id.menu_context_view);
            final IconContextMenu cm = new IconContextMenu(list.getContext(), cmm, view);
            //cm.setAnchor(anchor);
            cm.setNumColumns(2);
            cm.setOnIconContextItemSelectedListener(getExplorer());
            cm.setInfo(info);
            cm.setTextLayout(R.layout.context_item);
            cm.setTitle(file.getName());
            if (!cm.show()) //r.left, r.top);
                return list.showContextMenu();
            else
                return true;
        } catch (Exception e) {
            Logger.LogWarning("Couldn't show Iconified menu.", e);
            return list.showContextMenu();
        }
    }

    if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) {
        if (!file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) {
            try {
                Method mStarter = getActivity().getClass().getMethod("startActionMode");
                mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() {
                    //@Override
                    public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
                        return false;
                    }

                    //@Override
                    public void onDestroyActionMode(android.view.ActionMode mode) {
                        mActionMode = null;
                        mActionModeSelected = false;
                    }

                    //@Override
                    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                        mode.getMenuInflater().inflate(R.menu.context_file, menu);

                        mActionModeSelected = true;
                        return true;
                    }

                    //@Override
                    public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
                        //ArrayList<OpenPath> files = new ArrayList<OpenPath>();

                        //OpenPath file = mLastPath.getChild(mode.getTitle().toString());
                        //files.add(file);

                        if (item.getItemId() != R.id.menu_context_cut && item.getItemId() != R.id.menu_multi
                                && item.getItemId() != R.id.menu_context_copy) {
                            mode.finish();
                            mActionModeSelected = false;
                        }
                        return executeMenu(item.getItemId(), mode, file);
                    }
                });
                Class cAM = Class.forName("android.view.ActionMode");
                Method mST = cAM.getMethod("setTitle", CharSequence.class);
                mST.invoke(mActionMode, file.getName());
            } catch (Exception e) {
                Logger.LogError("Error using ActionMode", e);
            }
        }
        return true;

    }

    if (file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) {
        if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) {
            try {
                Method mStarter = getActivity().getClass().getMethod("startActionMode");
                mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() {

                    //@Override
                    public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
                        return false;
                    }

                    //@Override
                    public void onDestroyActionMode(android.view.ActionMode mode) {
                        mActionMode = null;
                        mActionModeSelected = false;
                    }

                    //@Override
                    public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                        mode.getMenuInflater().inflate(R.menu.context_file, menu);
                        menu.findItem(R.id.menu_context_paste).setEnabled(getClipboard().size() > 0);
                        //menu.findItem(R.id.menu_context_unzip).setEnabled(mHoldingZip);

                        mActionModeSelected = true;

                        return true;
                    }

                    //@Override
                    public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
                        return executeMenu(item.getItemId(), mode, file);
                    }
                });
                Class cAM = Class.forName("android.view.ActionMode");
                Method mST = cAM.getMethod("setTitle", CharSequence.class);
                mST.invoke(mActionMode, file.getName());
            } catch (Exception e) {
                Logger.LogError("Error using ActionMode", e);
            }
        }

        return true;
    }

    return false;
}

From source file:dk.bearware.gui.MainActivity.java

@Override
public boolean onItemLongClick(AdapterView<?> l, View v, int position, long id) {
    Object item = channelsAdapter.getItem(position);
    if (item instanceof User) {
        selectedUser = (User) item;//from w  w  w.  j av a2s. c o m
        UserAccount myuseraccount = new UserAccount();
        ttclient.getMyUserAccount(myuseraccount);

        boolean banRight = (myuseraccount.uUserRights & UserRight.USERRIGHT_BAN_USERS) != 0;
        boolean moveRight = (myuseraccount.uUserRights & UserRight.USERRIGHT_MOVE_USERS) != 0;
        boolean kickRight = (myuseraccount.uUserRights & UserRight.USERRIGHT_KICK_USERS) != 0;
        // operator of a channel can also kick users
        int myuserid = ttclient.getMyUserID();
        kickRight |= ttclient.isChannelOperator(myuserid, selectedUser.nChannelID);

        PopupMenu userActions = new PopupMenu(this, v);
        userActions.setOnMenuItemClickListener(this);
        userActions.inflate(R.menu.user_actions);
        userActions.getMenu().findItem(R.id.action_kickchan).setEnabled(kickRight).setVisible(kickRight);
        userActions.getMenu().findItem(R.id.action_kicksrv).setEnabled(kickRight).setVisible(kickRight);
        userActions.getMenu().findItem(R.id.action_banchan).setEnabled(banRight).setVisible(banRight);
        userActions.getMenu().findItem(R.id.action_bansrv).setEnabled(banRight).setVisible(banRight);
        userActions.getMenu().findItem(R.id.action_select).setEnabled(moveRight).setVisible(moveRight);
        userActions.show();
        return true;
    }
    if (item instanceof Channel) {
        selectedChannel = (Channel) item;
        if ((curchannel != null) && (curchannel.nParentID != selectedChannel.nChannelID)) {
            boolean isRemovable = (ttclient != null)
                    && (selectedChannel.nChannelID != ttclient.getMyChannelID());
            PopupMenu channelActions = new PopupMenu(this, v);
            channelActions.setOnMenuItemClickListener(this);
            channelActions.inflate(R.menu.channel_actions);
            channelActions.getMenu().findItem(R.id.action_remove).setEnabled(isRemovable)
                    .setVisible(isRemovable);
            channelActions.show();
            return true;
        }
    }
    return false;
}

From source file:com.battlelancer.seriesguide.ui.EpisodesFragment.java

@Override
public void onPopupMenuClick(View v, final int episodeTvdbId, final int episodeNumber, final long releaseTimeMs,
        final boolean isWatched, final boolean isCollected) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.episodes_popup_menu);

    Menu menu = popupMenu.getMenu();
    menu.findItem(R.id.menu_action_episodes_watched).setVisible(!isWatched);
    menu.findItem(R.id.menu_action_episodes_not_watched).setVisible(isWatched);
    menu.findItem(R.id.menu_action_episodes_collection_add).setVisible(!isCollected);
    menu.findItem(R.id.menu_action_episodes_collection_remove).setVisible(isCollected);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from   w w  w .j  a  v  a2 s .c  o m*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_action_episodes_watched: {
                onFlagEpisodeWatched(episodeTvdbId, episodeNumber, true);
                fireTrackerEventContextMenu("Flag watched");
                return true;
            }
            case R.id.menu_action_episodes_not_watched: {
                onFlagEpisodeWatched(episodeTvdbId, episodeNumber, false);
                fireTrackerEventContextMenu("Flag unwatched");
                return true;
            }
            case R.id.menu_action_episodes_collection_add: {
                onFlagEpisodeCollected(episodeTvdbId, episodeNumber, true);
                fireTrackerEventContextMenu("Flag collected");
                return true;
            }
            case R.id.menu_action_episodes_collection_remove: {
                onFlagEpisodeCollected(episodeTvdbId, episodeNumber, false);
                fireTrackerEventContextMenu("Flag uncollected");
                return true;
            }
            case R.id.menu_action_episodes_watched_previous: {
                onMarkUntilHere(releaseTimeMs);
                fireTrackerEventContextMenu("Flag previously aired");
                return true;
            }
            case R.id.menu_action_episodes_manage_lists: {
                ManageListsDialogFragment.showListsDialog(episodeTvdbId, ListItemTypes.EPISODE,
                        getFragmentManager());
                fireTrackerEventContextMenu("Manage lists");
                return true;
            }
            }
            return false;
        }
    });
    popupMenu.show();
}