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:io.mapsquare.osmcontributor.ui.activities.MapActivity.java

@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseInitializeDrawer(PleaseInitializeDrawer event) {
    Timber.d("initializing drawer with poiType");

    if (filtersItemList == null) {
        filtersItemList = new ArrayList<>();
    }/*from  ww w. j a  v  a2 s. c  o m*/
    List<PoiType> poiTypes = event.getPoiTypes();

    poiTypesHidden = event.getPoiTypeHidden();

    filters.clear();
    for (PoiType poiType : poiTypes) {
        Long id = poiType.getId();
        filters.add(new PoiTypeFilter(poiType.getName(), id, poiType.getIcon(), !poiTypesHidden.contains(id)));
    }
    Collections.sort(filters);

    Menu menu = filterView.getMenu();

    int order = 1;
    for (PoiTypeFilter poiTypeFilter : filters) {
        PoiTypeFilter nextPoiTypeFilter = null;
        if (order < filters.size()) {
            nextPoiTypeFilter = filters.get(order);
        }
        // Add only menu if not present
        if (menu.findItem(poiTypeFilter.getPoiTypeId().intValue()) == null) {
            filtersItemList.add(menu
                    .add(Menu.NONE, poiTypeFilter.getPoiTypeId().intValue(),
                            (nextPoiTypeFilter != null
                                    ? (poiTypeFilter.compareTo(nextPoiTypeFilter) > 0 ? order - 1 : order)
                                    : order),
                            poiTypeFilter.getPoiTypeName())
                    .setChecked(poiTypeFilter.isActive())
                    .setIcon(bitmapHandler.getDrawable(poiTypeFilter.getPoiTypeIconName())));
        }
        order++;
    }

    // Remove only filter removed by user
    if (filters.size() < filtersItemList.size()) {
        List<MenuItem> temp = new ArrayList<>(filters.size());
        for (MenuItem menuItem : filtersItemList) {
            PoiTypeFilter poiTypeFilter = new PoiTypeFilter("", (long) menuItem.getItemId(), "", true);
            if (!filters.contains(poiTypeFilter)) {
                menu.removeItem(poiTypeFilter.getPoiTypeId().intValue());
            } else {
                temp.add(menuItem);
            }
        }

        filtersItemList.clear();
        filtersItemList.addAll(temp);
        temp.clear();
    }

    selectAllMenuItem.setChecked(poiTypesHidden.isEmpty());
}

From source file:jackpal.androidterm.Term.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    if (mSettings.getActionBarPlusKeyAction() != 999) {
        MenuItemCompat.setShowAsAction(menu.findItem(R.id.menu_plus), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    } else {/*from w w w.ja  v a2  s.c  o m*/
        menu.removeItem(R.id.menu_plus);
    }
    //        if (mSettings.getActionBarMinusKeyAction() != 999) {
    //            MenuItemCompat.setShowAsAction(menu.findItem(R.id.menu_minus), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    //        } else {
    //            menu.removeItem(R.id.menu_minus);
    //        }
    if (mSettings.getActionBarXKeyAction() != 999) {
        MenuItemCompat.setShowAsAction(menu.findItem(R.id.menu_x), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    } else {
        menu.removeItem(R.id.menu_x);
    }
    //        if (mSettings.getActionBarUserKeyAction() != 999) {
    //            MenuItemCompat.setShowAsAction(menu.findItem(R.id.menu_user), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    //        } else {
    //            menu.removeItem(R.id.menu_user);
    //        }
    return true;
}

From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java

/**
 * Prepare the Screen's standard options menu to be displayed.  This is
 * called right before the menu is shown, every time it is shown.  You can
 * use this method to efficiently enable/disable items or otherwise
 * dynamically modify the contents.// www  .  j  a  v  a  2  s  .  com
 *
 * @param menu The options menu as last shown or first initialized by
 *             onCreateOptionsMenu().
 * @see #setHasOptionsMenu
 * @see #onCreateOptionsMenu
 */
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem mi;
    /* If the image has been loaded to the main page, remove the menu option for image */
    if (mActivity.mPreferenceAdapter.getPicFirst() && mCardBitmap != null) {
        mi = menu.findItem(R.id.image);
        if (mi != null) {
            menu.removeItem(mi.getItemId());
        }
    }
    /* This code removes the "change set" button if there is only one set.
     * Turns out some users use it to view the full set name when there is only one set/
     * I'm leaving it here, but commented, for posterity */
    /*
     if (mPrintings != null && mPrintings.size() == 1) {
    mi = menu.findItem(R.id.changeset);
    if (mi != null) {
        menu.removeItem(mi.getItemId());
    }
    }
    */
}

From source file:com.docd.purefm.ui.fragments.BrowserFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    final AbstractBrowserActivity activity = getBrowserActivity();
    if (activity.shouldShowBrowserFragmentMenu()) {
        inflater.inflate(R.menu.browser, menu);

        // TODO it returns true even on devices that don't have the physical key.
        // Find a better method to detect search hardware button
        //if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_SEARCH)) {
        //    menu.removeItem(R.id.menu_search);
        //}/*from w ww. j a  va2 s. co  m*/

        final MenuItem content = menu.findItem(android.R.id.content);
        if (content == null) {
            throw new RuntimeException("Inflated menu item should contain android.R.id.content");
        }

        final Settings settings = Settings.getInstance(activity);
        switch (settings.getListAppearance()) {
        case LIST:
            content.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_view_as_grid))
                    .setTitle(R.string.menu_view_as_grid).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            break;

        case GRID:
            content.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_view_as_list))
                    .setTitle(R.string.menu_view_as_list).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            break;

        default:
            throw new IllegalArgumentException("Unexpected ListAppearance:" + settings.getListAppearance());
        }

        if (ClipBoard.isEmpty()) {
            menu.removeItem(android.R.id.paste);
        }
    }
}

From source file:io.jawg.osmcontributor.ui.activities.MapActivity.java

@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseInitializeDrawer(PleaseInitializeDrawer event) {
    Timber.d("initializing drawer with poiType");

    if (filtersItemList == null) {
        filtersItemList = new ArrayList<>();
    }/*from ww w .  j  a v  a 2s .c  om*/
    List<PoiType> poiTypes = event.getPoiTypes();

    poiTypesHidden = event.getPoiTypeHidden();
    poiAccessibilityTypesHidden = new ArrayList<>();

    filters.clear();
    for (PoiType poiType : poiTypes) {
        Long id = poiType.getId();
        filters.add(new PoiTypeFilter(poiType.getName(), id, poiType.getIcon(), !poiTypesHidden.contains(id)));
    }
    Collections.sort(filters);

    Menu menu = filterView.getMenu();

    int order = 1;
    for (PoiTypeFilter poiTypeFilter : filters) {
        PoiTypeFilter nextPoiTypeFilter = null;
        if (order < filters.size()) {
            nextPoiTypeFilter = filters.get(order);
        }
        // Add only menu if not present
        if (menu.findItem(poiTypeFilter.getPoiTypeId().intValue()) == null) {
            filtersItemList.add(menu
                    .add(Menu.NONE, poiTypeFilter.getPoiTypeId().intValue(),
                            (nextPoiTypeFilter != null
                                    ? (poiTypeFilter.compareTo(nextPoiTypeFilter) > 0 ? order - 1 : order)
                                    : order),
                            poiTypeFilter.getPoiTypeName())
                    .setChecked(poiTypeFilter.isActive())
                    .setIcon(bitmapHandler.getDrawable(poiTypeFilter.getPoiTypeIconName())));
        }
        order++;
    }

    // Remove only filter removed by user
    if (filters.size() < filtersItemList.size()) {
        List<MenuItem> temp = new ArrayList<>(filters.size());
        for (MenuItem menuItem : filtersItemList) {
            PoiTypeFilter poiTypeFilter = new PoiTypeFilter("", (long) menuItem.getItemId(), "", true);
            if (!filters.contains(poiTypeFilter)) {
                menu.removeItem(poiTypeFilter.getPoiTypeId().intValue());
            } else {
                temp.add(menuItem);
            }
        }

        filtersItemList.clear();
        filtersItemList.addAll(temp);
        temp.clear();
    }

    selectAllMenuItem.setChecked(poiTypesHidden.isEmpty());
}

From source file:com.google.android.apps.mytracks.TrackDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.track_detail, menu);
    String fileTypes[] = getResources().getStringArray(R.array.file_types);
    menu.findItem(R.id.track_detail_mail_gpx).setTitle(getString(R.string.menu_save_format, fileTypes[0]));
    menu.findItem(R.id.track_detail_mail_kml).setTitle(getString(R.string.menu_save_format, fileTypes[1]));
    menu.findItem(R.id.track_detail_mail_csv).setTitle(getString(R.string.menu_save_format, fileTypes[2]));
    // menu.findItem(R.id.track_detail_save_tcx).setTitle(getString(R.string.menu_save_format,
    // fileTypes[3]));

    insertMarkerMenuItem = menu.findItem(R.id.track_detail_insert_marker);
    playNogagoMenuItem = menu.findItem(R.id.track_detail_play);
    playEarthMenuItem = menu.findItem(R.id.track_detail_earth_play); // Not
                                                                     // Supported
    if (Constants.IS_BLACKBERRY)
        playEarthMenuItem.setVisible(false);
    shareMenuItem = menu.findItem(R.id.track_detail_share);
    saveMenuItem = menu.findItem(R.id.track_detail_mail);
    voiceFrequencyMenuItem = menu.findItem(R.id.track_detail_voice_frequency);
    splitFrequencyMenuItem = menu.findItem(R.id.track_detail_split_frequency);

    if (!Constants.isOnline(TrackDetailActivity.this)) {
        // Alternative would be to hide them
        menu.removeItem(R.id.track_detail_share);
        menu.removeItem(R.id.track_detail_earth_play);
    }/*from  w  w  w.  j  a  v  a 2 s . co  m*/
    updateMenuItems(trackId == recordingTrackId, recordingTrackPaused);
    return true;
}

From source file:com.hybris.mobile.app.commerce.activity.MainActivity.java

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

    // HockeyApp feedback
    menu.findItem(R.id.menu_feedback).setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override//from www  .  j  av a  2  s  .  c om
        public boolean onMenuItemClick(MenuItem item) {
            HockeyAppUtils.showFeedbackActivity(MainActivity.this);
            return true;
        }
    });

    // Sync Settings
    menu.findItem(R.id.menu_settings).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            return true;
        }
    });

    // Barcode scanner
    menu.findItem(R.id.menu_scanner).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            CommerceApplication.getScannerHelper().launch(MainActivity.this, MainActivity.this);
            return true;
        }
    });

    // Cart items
    MenuItem item = menu.findItem(R.id.b2b_icon_cart);

    if (mCartDrawer != null) {

        // Onclick to open/hide cart menu
        item.getActionView().setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mDrawerLayout != null) {
                    mDrawerLayout.closeDrawers();
                }
                if (mCartDrawer.isDrawerOpen(mCartDrawer.getChildAt(1))) {
                    mCartDrawer.closeDrawer(mCartDrawer.getChildAt(1));
                } else {
                    mCartDrawer.openDrawer(mCartDrawer.getChildAt(1));
                }
            }
        });
    } else {
        menu.removeItem(R.id.b2b_icon_cart);
    }

    // Search component
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.b2b_icon_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    return true;
}

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

public void onCreateContextMenuSupport(Menu menu, MenuInflater menuInflater, UpdateView updateView,
        Object selected) {//from   w  w  w. j av  a2 s. c  om
    if (selected instanceof Entry) {
        Entry entry = (Entry) selected;
        if (entry instanceof PodcastEpisode && !entry.isVideo()) {
            if (Util.isOffline(context)) {
                menuInflater.inflate(R.menu.select_podcast_episode_context_offline, menu);
            } else {
                menuInflater.inflate(R.menu.select_podcast_episode_context, menu);

                if (entry.getBookmark() == null) {
                    menu.removeItem(R.id.bookmark_menu_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);
                }
            }
            menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star)
                    .setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star);
        } 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);
                }
            }
            menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star)
                    .setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star);
        } else {
            if (Util.isOffline(context)) {
                menuInflater.inflate(R.menu.select_video_context_offline, menu);
            } else {
                menuInflater.inflate(R.menu.select_video_context, menu);
            }
        }
    } 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:com.master.metehan.filtereagle.ActivityMain.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (Build.VERSION.SDK_INT < MIN_SDK)
        return false;

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

    // Search/*www .  j  a  va 2s. c  o m*/
    menuSearch = menu.findItem(R.id.menu_search);
    MenuItemCompat.setOnActionExpandListener(menuSearch, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            if (getIntent().hasExtra(EXTRA_SEARCH))
                finish();
            return true;
        }
    });

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (adapter != null)
                adapter.getFilter().filter(query);
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (adapter != null)
                adapter.getFilter().filter(newText);
            return true;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (adapter != null)
                adapter.getFilter().filter(null);
            return true;
        }
    });

    if (!Util.hasValidFingerprint(this) || getIntentInvite(this).resolveActivity(getPackageManager()) == null)
        menu.removeItem(R.id.menu_invite);

    if (getIntentSupport().resolveActivity(getPackageManager()) == null)
        menu.removeItem(R.id.menu_support);

    return true;
}