Example usage for android.view Menu removeItem

List of usage examples for android.view Menu removeItem

Introduction

In this page you can find the example usage for android.view Menu removeItem.

Prototype

public void removeItem(int id);

Source Link

Document

Remove the item with the given identifier.

Usage

From source file:com.eveningoutpost.dexdrip.Home.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);

    //wear integration
    if (!prefs.getBoolean("wear_sync", false)) {
        menu.removeItem(R.id.action_open_watch_settings);
        menu.removeItem(R.id.action_resend_last_bg);
        menu.removeItem(R.id.action_sync_watch_db);//KS
    }/*www .ja  va  2 s . c o  m*/

    //speak readings
    MenuItem menuItem = menu.findItem(R.id.action_toggle_speakreadings);
    if (prefs.getBoolean("bg_to_speech_shortcut", false)) {

        menuItem.setVisible(true);
        if (prefs.getBoolean("bg_to_speech", false)) {
            menuItem.setChecked(true);
        } else {
            menuItem.setChecked(false);
        }
    } else {
        menuItem.setVisible(false);
    }

    menu.findItem(R.id.showmap).setVisible(prefs.getBoolean("plus_extra_features", false));
    menu.findItem(R.id.parakeetsetup).setVisible(prefs.getBoolean("plus_extra_features", false));

    boolean result = super.onCreateOptionsMenu(menu);

    return result;
}

From source file:github.daneren2005.dsub.fragments.NowPlayingFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    DownloadService downloadService = getDownloadService();
    if (Util.isOffline(context)) {
        menuInflater.inflate(R.menu.nowplaying_offline, menu);
    } else {/*  w  w w .j  av a  2 s .c  om*/
        menuInflater.inflate(R.menu.nowplaying, menu);
    }
    if (downloadService != null && downloadService.getSleepTimer()) {
        int timeRemaining = downloadService.getSleepTimeRemaining();
        timerMenu = menu.findItem(R.id.menu_toggle_timer);
        timerMenu.setTitle(context.getResources().getString(R.string.download_stop_time_remaining,
                Util.formatDuration(timeRemaining)));
    }
    if (downloadService != null && downloadService.getKeepScreenOn()) {
        menu.findItem(R.id.menu_screen_on_off).setChecked(true);
    }
    if (downloadService != null && downloadService.isRemovePlayed()) {
        menu.findItem(R.id.menu_remove_played).setChecked(true);
    }

    boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable();
    if (equalizerAvailable && !downloadService.isRemoteEnabled()) {
        SharedPreferences prefs = Util.getPreferences(context);
        boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
        if (equalizerOn && downloadService != null) {
            if (downloadService.getEqualizerController() != null
                    && downloadService.getEqualizerController().isEnabled()) {
                menu.findItem(R.id.menu_equalizer).setChecked(true);
            }
        }
    } else {
        menu.removeItem(R.id.menu_equalizer);
    }

    if (downloadService != null) {
        MenuItem mediaRouteItem = menu.findItem(R.id.menu_mediaroute);
        if (mediaRouteItem != null) {
            MediaRouteButton mediaRouteButton = (MediaRouteButton) MenuItemCompat.getActionView(mediaRouteItem);
            mediaRouteButton.setRouteSelector(downloadService.getRemoteSelector());
        }
    }
}

From source file:github.popeen.dsub.fragments.SubsonicFragment.java

public void onCreateContextMenuSupport(Menu menu, MenuInflater menuInflater, UpdateView updateView,
        Object selected) {//w  ww . jav a  2s . c o m
    if (selected instanceof Entry) {
        Entry entry = (Entry) selected;
        if (entry instanceof PodcastEpisode) {
            if (Util.isOffline(context)) {
                if (entry.isVideo()) {
                    menuInflater.inflate(R.menu.select_video_context_offline, menu);
                } else {
                    menuInflater.inflate(R.menu.select_podcast_episode_context_offline, menu);
                }
            } else {
                if (entry.isVideo()) {
                    menuInflater.inflate(R.menu.select_podcast_episode_video_context, menu);
                } else {
                    menuInflater.inflate(R.menu.select_podcast_episode_context, menu);
                }

                if (entry.getBookmark() == null) {
                    menu.removeItem(R.id.bookmark_menu_delete);
                }
                if (UserUtil.canPodcast()) {
                    String status = ((PodcastEpisode) entry).getStatus();
                    if ("completed".equals(status)) {
                        menu.removeItem(R.id.song_menu_server_download);
                    }
                } else {
                    menu.removeItem(R.id.song_menu_server_download);
                    menu.removeItem(R.id.song_menu_server_delete);
                }
            }
        } else if (entry.isDirectory()) {
            if (Util.isOffline(context)) {
                menuInflater.inflate(R.menu.select_album_context_offline, menu);
            } else {
                menuInflater.inflate(R.menu.select_album_context, menu);

                if (Util.isTagBrowsing(context)) {
                    menu.removeItem(R.id.menu_rate);
                }
            }

        } else if (!entry.isVideo()) {
            if (Util.isOffline(context)) {
                menuInflater.inflate(R.menu.select_song_context_offline, menu);
            } else {
                menuInflater.inflate(R.menu.select_song_context, menu);

                if (entry.getBookmark() == null) {
                    menu.removeItem(R.id.bookmark_menu_delete);
                }

                String songPressAction = Util.getSongPressAction(context);
                if (!"next".equals(songPressAction) && !"last".equals(songPressAction)) {
                    menu.setGroupVisible(R.id.hide_play_now, false);
                }
            }
        } else {
            if (Util.isOffline(context)) {
                menuInflater.inflate(R.menu.select_video_context_offline, menu);
            } else {
                menuInflater.inflate(R.menu.select_video_context, menu);
            }
        }

        MenuItem starMenu = menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star);
        if (starMenu != null) {
            starMenu.setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star);
        }

        if (!isShowArtistEnabled() || (!Util.isTagBrowsing(context) && entry.getParent() == null)
                || (Util.isTagBrowsing(context) && entry.getArtistId() == null)) {
            menu.setGroupVisible(R.id.hide_show_artist, false);
        }
    } else if (selected instanceof Artist) {
        Artist artist = (Artist) selected;
        if (Util.isOffline(context)) {
            menuInflater.inflate(R.menu.select_artist_context_offline, menu);
        } else {
            menuInflater.inflate(R.menu.select_artist_context, menu);

            menu.findItem(R.id.artist_menu_star)
                    .setTitle(artist.isStarred() ? R.string.common_unstar : R.string.common_star);
        }
    }

    MenuUtil.hideMenuItems(context, menu, updateView);
}

From source file:github.popeen.dsub.fragments.NowPlayingFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    DownloadService downloadService = getDownloadService();
    if (Util.isOffline(context)) {
        menuInflater.inflate(R.menu.nowplaying_offline, menu);
    } else {/*www.  ja va 2 s.  c  o m*/
        menuInflater.inflate(R.menu.nowplaying, menu);
    }
    if (downloadService != null && downloadService.getSleepTimer()) {
        int timeRemaining = downloadService.getSleepTimeRemaining();
        timerMenu = menu.findItem(R.id.menu_toggle_timer);
        if (timeRemaining > 1) {
            timerMenu.setTitle(context.getResources().getString(R.string.download_stop_time_remaining,
                    Util.formatDuration(timeRemaining)));
        } else {
            timerMenu.setTitle(R.string.menu_set_timer);
        }
    }
    if (downloadService != null && downloadService.getKeepScreenOn()) {
        menu.findItem(R.id.menu_screen_on_off).setChecked(true);
    }

    boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable();
    boolean isRemoteEnabled = downloadService != null && downloadService.isRemoteEnabled();
    if (equalizerAvailable && !isRemoteEnabled) {
        SharedPreferences prefs = Util.getPreferences(context);
        boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
        if (equalizerOn && downloadService != null) {
            if (downloadService.getEqualizerController() != null
                    && downloadService.getEqualizerController().isEnabled()) {
                menu.findItem(R.id.menu_equalizer).setChecked(true);
            }
        }
    } else {
        menu.removeItem(R.id.menu_equalizer);
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || isRemoteEnabled) {
        playbackSpeedButton.setVisibility(View.GONE);
    } else {
        playbackSpeedButton.setVisibility(View.VISIBLE);
    }

    if (downloadService != null) {
        MenuItem mediaRouteItem = menu.findItem(R.id.menu_mediaroute);
        if (mediaRouteItem != null) {
            MediaRouteButton mediaRouteButton = (MediaRouteButton) MenuItemCompat.getActionView(mediaRouteItem);
            mediaRouteButton.setDialogFactory(new CustomMediaRouteDialogFactory());
            mediaRouteButton.setRouteSelector(downloadService.getRemoteSelector());
        }
    }
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * {@inheritDoc}//from  w ww  .j a  v a  2 s.c  o  m
 */
@Override
public final boolean onPrepareOptionsMenu(final Menu menu) {
    final ConnectorSpec[] connectors = getConnectors(ConnectorSpec.CAPABILITIES_SEND,
            ConnectorSpec.STATUS_READY | ConnectorSpec.STATUS_ENABLED, true /*isIncludePseudoConnectors*/);

    boolean isPrefsConnectorOk = prefsConnectorSpec != null && prefsSubConnectorSpec != null
            && prefsConnectorSpec.hasStatus(ConnectorSpec.STATUS_ENABLED);
    menu.findItem(R.id.item_connector)
            .setVisible(connectors.length > 1
                    || (connectors.length == 1 && connectors[0].getSubConnectorCount() > 1)
                    || (connectors.length == 1 && !isPrefsConnectorOk));

    boolean hasText = this.etText != null && !TextUtils.isEmpty(this.etText.getText());
    menu.findItem(R.id.item_savechars).setVisible(hasText);
    // only allow to save drafts on API18-
    menu.findItem(R.id.item_draft).setVisible(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && hasText);
    final boolean showRestore = !TextUtils
            .isEmpty(PreferenceManager.getDefaultSharedPreferences(this).getString(PREFS_BACKUPLASTTEXT, null));
    try {
        menu.removeItem(ITEM_RESTORE);
    } catch (Exception e) {
        Log.w(TAG, "error removing item: " + ITEM_RESTORE, e);
    }
    if (showRestore) {
        menu.add(0, ITEM_RESTORE, android.view.Menu.NONE, R.string.restore_);
        menu.findItem(ITEM_RESTORE).setIcon(android.R.drawable.ic_menu_revert);
    }
    return true;
}

From source file:org.mozilla.gecko.BrowserApp.java

/**
 * Add the provided item to the provided menu, which should be
 * the root (mMenu)./*from ww w .  j a  v  a2 s .  co m*/
 */
private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info) {
    info.added = true;

    final Menu destination;
    if (info.parent == 0) {
        destination = menu;
    } else if (info.parent == GECKO_TOOLS_MENU) {
        // The tools menu only exists in our -v11 resources.
        if (Versions.feature11Plus) {
            final MenuItem tools = menu.findItem(R.id.tools);
            destination = tools != null ? tools.getSubMenu() : menu;
        } else {
            destination = menu;
        }
    } else {
        final MenuItem parent = menu.findItem(info.parent);
        if (parent == null) {
            return;
        }

        Menu parentMenu = findParentMenu(menu, parent);

        if (!parent.hasSubMenu()) {
            parentMenu.removeItem(parent.getItemId());
            destination = parentMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle());
            if (parent.getIcon() != null) {
                ((SubMenu) destination).getItem().setIcon(parent.getIcon());
            }
        } else {
            destination = parent.getSubMenu();
        }
    }

    final MenuItem item = destination.add(Menu.NONE, info.id, Menu.NONE, info.label);

    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked",
                    Integer.toString(info.id - ADDON_MENU_OFFSET)));
            return true;
        }
    });

    if (info.icon == null) {
        item.setIcon(R.drawable.ic_menu_addons_filler);
    } else {
        final int id = info.id;
        BitmapUtils.getDrawable(this, info.icon, new BitmapUtils.BitmapLoader() {
            @Override
            public void onBitmapFound(Drawable d) {
                // TODO: why do we re-find the item?
                final MenuItem item = destination.findItem(id);
                if (item == null) {
                    return;
                }
                if (d == null) {
                    item.setIcon(R.drawable.ic_menu_addons_filler);
                    return;
                }
                item.setIcon(d);
            }
        });
    }

    item.setCheckable(info.checkable);
    item.setChecked(info.checked);
    item.setEnabled(info.enabled);
    item.setVisible(info.visible);
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

private void setupActionModeCallback() {
    mActionModeCallbackV7 = new Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override//from  w w w  .j a va 2  s.c  om
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onCreateActionMode");
            }

            if (mode == null && torrentListAdapter.getCheckedItemCount() == 0
                    && torrentListAdapter.getSelectedPosition() < 0) {
                return false;
            }

            Menu origMenu = menu;
            if (tb != null) {
                menu = tb.getMenu();
            }
            if (mode != null) {
                mActionMode = (mode instanceof ActionModeWrapperV7) ? mode
                        : new ActionModeWrapperV7(mode, tb, getActivity());

                mActionMode.setTitle(R.string.context_torrent_title);
            }
            ActionBarToolbarSplitter.buildActionBar(getActivity(), this, R.menu.menu_context_torrent_details,
                    menu, tb);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onCreateActionMode(mode, menu);
            }

            if (sideListArea == null) {
                SubMenu subMenu = origMenu.addSubMenu(R.string.menu_global_actions);
                subMenu.setIcon(R.drawable.ic_menu_white_24dp);
                MenuItemCompat.setShowAsAction(subMenu.getItem(), MenuItemCompat.SHOW_AS_ACTION_NEVER);

                try {
                    // Place "Global" actions on top bar in collapsed menu
                    MenuInflater mi = mode == null ? getActivity().getMenuInflater() : mode.getMenuInflater();
                    mi.inflate(R.menu.menu_torrent_list, subMenu);
                    onPrepareOptionsMenu(subMenu);
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG, e.getMessage());
                    menu.removeItem(subMenu.getItem().getItemId());
                }
            }

            if (AndroidUtils.usesNavigationControl()) {
                MenuItem add = origMenu.add(R.string.select_multiple_items);
                add.setCheckable(true);
                add.setChecked(torrentListAdapter.isMultiCheckMode());
                add.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        boolean turnOn = !torrentListAdapter.isMultiCheckModeAllowed();

                        torrentListAdapter.setMultiCheckModeAllowed(turnOn);
                        if (turnOn) {
                            torrentListAdapter.setMultiCheckMode(turnOn);
                            torrentListAdapter.setItemChecked(torrentListAdapter.getSelectedPosition(), true);
                        }
                        return true;
                    }
                });
            }

            return true;
        }

        // Called each time the action mode is shown. Always called after
        // onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "MULTI:onPrepareActionMode " + mode);
            }
            if (tb != null) {
                menu = tb.getMenu();
            }

            // Must be called first, because our drawer sets all menu items
            // visible.. :(
            getActivity().onPrepareOptionsMenu(menu);

            prepareContextMenu(menu);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onPrepareActionMode(mode, menu);
            }

            AndroidUtils.fixupMenuAlpha(menu);

            return true;
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onActionItemClicked " + item.getTitle());
            }

            if (TorrentListFragment.this.handleFragmentMenuItems(item.getItemId())) {
                return true;
            }
            if (getActivity().onOptionsItemSelected(item)) {
                return true;
            }
            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                if (frag.onActionItemClicked(mode, item)) {
                    return true;
                }
            }
            return false;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onDestroyActionMode. BeingReplaced?" + actionModeBeingReplaced);
            }

            mActionMode = null;

            if (!actionModeBeingReplaced) {
                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        torrentListAdapter.setMultiCheckMode(false);
                        torrentListAdapter.clearChecked();
                        updateCheckedIDs();
                    }
                });

                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.actionModeBeingReplacedDone();
                        }
                    }
                });

                listview.setLongClickable(true);
                listview.requestLayout();
                AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
            }
        }
    };
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    boolean drawerOpen = mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mDrawerListsView);
    boolean holoSearch = PreferenceActivity.getUsingHoloSearchFromPrefs(this);
    // TODO: supposed to hide content-related actions when the drawer is open.

    // TODO: Add item-specific menu items (see NotesList.java example)
    // like edit, strike-through, delete.

    // Add menu option for auto adding items from string array in intent
    // extra if they exist
    if (mExtraItems == null) {
        menu.removeItem(MENU_INSERT_FROM_EXTRAS);
    }//from w w  w . ja v  a  2s  .  co  m

    // Selected list:
    long listId = getSelectedListId();

    // set menu title for change mode
    MenuItem menuItem = menu.findItem(MENU_PICK_ITEMS);

    if (mItemsView.mMode == MODE_ADD_ITEMS) {
        menuItem.setTitle(R.string.menu_start_shopping);
        menuItem.setIcon(android.R.drawable.ic_menu_myplaces);
    } else {
        menu.findItem(MENU_PICK_ITEMS).setTitle(R.string.menu_pick_items);
        menuItem.setIcon(android.R.drawable.ic_menu_add);
    }

    menuItem = menu.findItem(MENU_SEARCH_ADD);
    if (menuItem != null) {
        menuItem.setVisible(holoSearch && !drawerOpen);
        if (!holoSearch) {
            mAddPanel.setVisibility(View.VISIBLE);
        }

        View searchView = menuItem.getActionView();
        int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
        View imageView = searchView.findViewById(searchImgId);
        if (imageView instanceof ImageView) {
            ((ImageView) imageView).setImageResource(android.R.drawable.ic_menu_add);
        }

    }

    menuItem = menu.findItem(MENU_SYNC_WEAR);
    if (menuItem != null) {
        menuItem.setVisible(mItemsView.isWearSupportAvailable());
    }

    menuItem = menu.findItem(MENU_MARK_ALL_ITEMS).setVisible(mItemsView.mNumUnchecked > 0);
    menuItem = menu.findItem(MENU_UNMARK_ALL_ITEMS).setVisible(mItemsView.mNumChecked > 0);

    menuItem = menu.findItem(MENU_CLEAN_UP_LIST).setEnabled(mItemsView.mNumChecked > 0).setVisible(!drawerOpen);

    // Delete list is possible, if we have more than one list:
    // AND
    // the current list is not the default list (listId == 0) - issue #105
    // TODO: Later, the default list should be user-selectable,
    // and not deletable.

    // TODO ???
    /*
     * menu.setItemShown(MENU_DELETE_LIST, mCursorListFilter.count() > 1 &&
     * listId != 1); // 1 is hardcoded number of default first list.
     */

    // The following code is put from onCreateOptionsMenu to
    // onPrepareOptionsMenu,
    // because the URI of the shopping list can change if the user switches
    // to another list.
    // Generate any additional actions that can be performed on the
    // overall list. This allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    // menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
    // new ComponentName(this, NoteEditor.class), null, intent, 0, null);

    // Workaround to add icons:
    MenuIntentOptionsWithIcons menu2 = new MenuIntentOptionsWithIcons(this, menu);
    menu2.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(this, org.openintents.shopping.ShoppingActivity.class), null, intent, 0, null);

    return true;
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void onPrepareOptionsMenu(Menu paramMenu) {
      if (!su) {//from w w  w . j av a2 s. c o  m
          paramMenu.removeItem(2131558653);
      }
      if (!Utils.hasXposed()) {
          paramMenu.removeItem(2131558652);
      }
  }