Example usage for android.view ContextMenu findItem

List of usage examples for android.view ContextMenu findItem

Introduction

In this page you can find the example usage for android.view ContextMenu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:org.isoron.uhabits.fragments.ListHabitsFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    getActivity().getMenuInflater().inflate(R.menu.list_habits_context, menu);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Habit habit = loader.habits.get(info.id);

    if (habit.isArchived())
        menu.findItem(R.id.action_archive_habit).setVisible(false);
    else/* ww w .  j  a  v  a2 s .  c  om*/
        menu.findItem(R.id.action_unarchive_habit).setVisible(false);
}

From source file:com.liquid.wallpapers.free.ScroidWallpaperGallery.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (this.selectedWallpaper == null || !(v instanceof Gallery)) {
        return;//from  w  w w.  j a  va  2s  .com
    }

    MenuInflater menuInflater = new MenuInflater(this);
    menuInflater.inflate(R.menu.gallery_context_menu, menu);

    if (this.favouriteDAO.isFavourite(this.selectedWallpaper.getId())) {
        menu.findItem(R.id.galleryRemoveFavouriteMenuItem).setVisible(true);
    } else {
        menu.findItem(R.id.galleryAddFavouriteMenuItem).setVisible(true);
    }
}

From source file:dev.drsoran.moloko.fragments.TaskListsFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
    final RtmListWithTaskCount list = getRtmList(
            ExpandableListView.getPackedPositionGroup(info.packedPosition));
    final String listName = list.getName();
    final boolean listIsLocked = list.getLocked() != 0;

    if (isWritableAccess() && !listIsLocked) {
        getSherlockActivity().getMenuInflater().inflate(R.menu.tasklists_group_context_rwd, menu);

        menu.findItem(R.id.ctx_menu_delete_list).setTitle(getString(R.string.phr_delete_with_name, listName));

        menu.findItem(R.id.ctx_menu_rename_list)
                .setTitle(getString(R.string.tasklists_menu_ctx_rename_list, listName));
    } else {//  w w  w. j ava  2 s.  c o m
        getSherlockActivity().getMenuInflater().inflate(R.menu.tasklists_group_context, menu);
    }

    if (getExpandableListView()
            .isGroupExpanded(ExpandableListView.getPackedPositionGroup(info.packedPosition))) {
        menu.findItem(R.id.ctx_menu_collapse).setVisible(true)
                .setTitle(getString(R.string.tasklists_menu_ctx_collapse, listName));

        menu.findItem(R.id.ctx_menu_expand).setVisible(false);
    } else {
        menu.findItem(R.id.ctx_menu_expand).setVisible(true)
                .setTitle(getString(R.string.tasklists_menu_ctx_expand, listName));

        menu.findItem(R.id.ctx_menu_collapse).setVisible(false);
    }

    final boolean isDefaultList = list.getId()
            .equals(MolokoApp.getSettings(getSherlockActivity()).getDefaultListId());
    menu.findItem(R.id.ctx_menu_set_default_list).setVisible(!isDefaultList);
    menu.findItem(R.id.ctx_menu_unset_default_list).setVisible(isDefaultList);
}

From source file:com.projects.nosleepreader.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    getMenuInflater().inflate(R.menu.context_menu_main, menu);
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    menu.setHeaderTitle(mValuesArray.get(info.position).getAsString(ListingDbHelper.COLUMN_TITLE));
    MenuItem favorites = menu.findItem(R.id.context_menu_favorite);
    if (mCurrentTable.equals(ListingDbHelper.TABLE_NAME_FAVORITES)) {
        favorites.setTitle("Remove from Favorites");
    }/*from  w  ww. ja va 2 s.  c om*/
}

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooser.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    if (info.position > 0) {
        MenuInflater inflater = _main.getMenuInflater();
        inflater.inflate(R.menu.context, menu);
        if (_copiedFile == null && _cutFile == null) {
            menu.findItem(R.id.mnuPaste).setEnabled(false);
        } else {/*from  w  w  w .  j  a  v  a2 s  .  c om*/
            menu.findItem(R.id.mnuPaste).setEnabled(true);
        }
    }
}

From source file:vn.cybersoft.obs.android.fragments.ModeTabFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // Inflate the menu from xml.
    getActivity().getMenuInflater().inflate(R.menu.optimal_mode_context_menu, menu);

    // Use the current item to create a custom view for the header.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    final Cursor c = (Cursor) mModeList.getAdapter().getItem((int) info.position);

    OptimalMode optimalMode = new OptimalMode(c);

    menu.setHeaderTitle(optimalMode.name);

    if (!optimalMode.canEdit) {
        // the original mode can't modify or delete
        menu.findItem(R.id.edit_mode).setEnabled(false).setVisible(false);
        menu.findItem(R.id.delete_mode).setEnabled(false).setVisible(false);
    }//from   www.  j  a v  a 2  s  .c o m
}

From source file:org.mozilla.gecko.home.HomeFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    if (!(menuInfo instanceof HomeContextMenuInfo)) {
        return;//from  w w w  .j  a v  a 2  s . c  o  m
    }

    HomeContextMenuInfo info = (HomeContextMenuInfo) menuInfo;

    // Don't show the context menu for folders.
    if (info.isFolder) {
        return;
    }

    MenuInflater inflater = new MenuInflater(view.getContext());
    inflater.inflate(R.menu.home_contextmenu, menu);

    menu.setHeaderTitle(info.getDisplayTitle());

    // Hide unused menu items.
    menu.findItem(R.id.top_sites_edit).setVisible(false);
    menu.findItem(R.id.top_sites_pin).setVisible(false);
    menu.findItem(R.id.top_sites_unpin).setVisible(false);

    // Hide the "Edit" menuitem if this item isn't a bookmark,
    // or if this is a reading list item.
    if (!info.hasBookmarkId() || info.isInReadingList()) {
        menu.findItem(R.id.home_edit_bookmark).setVisible(false);
    }

    // Hide the "Remove" menuitem if this item not removable.
    if (!info.canRemove()) {
        menu.findItem(R.id.home_remove).setVisible(false);
    }

    if (!StringUtils.isShareableUrl(info.url) || GeckoProfile.get(getActivity()).inGuestMode()) {
        menu.findItem(R.id.home_share).setVisible(false);
    }

    if (!RestrictedProfiles.isAllowed(view.getContext(), Restriction.DISALLOW_PRIVATE_BROWSING)) {
        menu.findItem(R.id.home_open_private_tab).setVisible(false);
    }
}

From source file:com.gsma.rcs.ri.sharing.SharingListView.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    getMenuInflater().inflate(R.menu.menu_log_sharing_item, menu);
    menu.findItem(R.id.menu_sharing_display).setVisible(false);
    // Get the list item position
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    Cursor cursor = (Cursor) mAdapter.getItem(info.position);
    Direction dir = Direction.valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.DIRECTION)));
    String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.MIME_TYPE));
    if (mimeType != null && Utils.isImageType(mimeType)) {
        if (Direction.INCOMING == dir) {
            Long transferred = cursor.getLong(cursor.getColumnIndexOrThrow(HistoryLog.TRANSFERRED));
            Long fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(HistoryLog.FILESIZE));
            if (fileSize.equals(transferred)) {
                menu.findItem(R.id.menu_sharing_display).setVisible(true);
                return;
            }//from  w ww  . j  a  v a 2s  . c  om
            return;
        }
        menu.findItem(R.id.menu_sharing_display).setVisible(true);
    }
}

From source file:com.jbirdvegas.mgerrit.CardsFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = mParent.getMenuInflater();
    inflater.inflate(R.menu.change_list_menu, menu);

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    View targetView = info.targetView;

    // Set the title of the user tracking menu item
    MenuItem userMenuItem = menu.findItem(R.id.menu_change_track_user);
    setMenuItemTitle(userMenuItem, getResources().getString(R.string.context_menu_track_user),
            (String) targetView.getTag(R.id.userName));
}

From source file:ru.yandex.subtitles.ui.fragment.conversations.ConversationFragment.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View v,
        final ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final ContextableRecyclerView.RecyclerContextMenuInfo recyclerInfo = (ContextableRecyclerView.RecyclerContextMenuInfo) menuInfo;
    if (recyclerInfo != null) {
        final Message message = (Message) recyclerInfo.getData();

        getMenuInflater().inflate(R.menu.context_menu_message, menu);
        if (message.isPinned()) {
            menu.findItem(R.id.action_pin_message).setVisible(false);
        } else {/*from ww  w.j  av a 2  s. co  m*/
            menu.findItem(R.id.action_unpin_message).setVisible(false);
        }
    }
}