List of usage examples for android.view Menu findItem
public MenuItem findItem(int id);
From source file:com.adafruit.bluefruit.le.connect.app.MainActivity.java
public void onClickFilterNameSettings(View view) { PopupMenu popup = new PopupMenu(this, view); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from w ww. j a v a 2 s . c om public boolean onMenuItemClick(MenuItem item) { boolean processed = true; switch (item.getItemId()) { case R.id.scanfilter_name_contains: mPeripheralList.setFilterNameExact(false); break; case R.id.scanfilter_name_exact: mPeripheralList.setFilterNameExact(true); break; case R.id.scanfilter_name_sensitive: mPeripheralList.setFilterNameCaseInsensitive(false); break; case R.id.scanfilter_name_insensitive: mPeripheralList.setFilterNameCaseInsensitive(true); break; default: processed = false; break; } updateFilters(); return processed; } }); MenuInflater inflater = popup.getMenuInflater(); Menu menu = popup.getMenu(); inflater.inflate(R.menu.menu_scan_filters_name, menu); final boolean isFilterNameExact = mPeripheralList.isFilterNameExact(); menu.findItem(isFilterNameExact ? R.id.scanfilter_name_exact : R.id.scanfilter_name_contains) .setChecked(true); final boolean isFilterNameCaseInsensitive = mPeripheralList.isFilterNameCaseInsensitive(); menu.findItem( isFilterNameCaseInsensitive ? R.id.scanfilter_name_insensitive : R.id.scanfilter_name_sensitive) .setChecked(true); popup.show(); }
From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java
/** * Initializes the navigation drawer, when the app is started. *//*from w ww.j a v a 2 s. c o m*/ @SuppressWarnings("deprecation") private void setupNavigationDrawer() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); NavigationView mDrawer = (NavigationView) findViewById(R.id.left_drawer); setupDrawerContent(mDrawer); // Set the item text for the debug view in the naviation drawer: if (mDrawer == null) return; Menu menu = mDrawer.getMenu(); if (menu == null) return; MenuItem item = menu.findItem(R.id.debug_view_item); if (item == null) return; if (mIsDebugViewEnabled) item.setTitle(R.string.hide_debug_view_text); else item.setTitle(R.string.show_debug_view_text); }
From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.actionbar_menu, menu); mFlashMenuItem = menu.findItem(R.id.flash_mode_item); // The flash menu item is not visible at the beginning ('weak' devices might have no flash) if (mFlashModes != null) mFlashMenuItem.setVisible(true); return true;/* w ww . ja v a2s .co m*/ }
From source file:com.ichi2.anki.DeckPicker.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.deck_picker, menu); boolean sdCardAvailable = AnkiDroidApp.isSdCardMounted(); menu.findItem(R.id.action_sync).setEnabled(sdCardAvailable); menu.findItem(R.id.action_new_filtered_deck).setEnabled(sdCardAvailable); menu.findItem(R.id.action_check_database).setEnabled(sdCardAvailable); menu.findItem(R.id.action_check_media).setEnabled(sdCardAvailable); menu.findItem(R.id.action_empty_cards).setEnabled(sdCardAvailable); // Hide import, export, and restore backup on ChromeOS as users // don't have access to the file system. if (CompatHelper.isChromebook()) { menu.findItem(R.id.action_restore_backup).setVisible(false); menu.findItem(R.id.action_import).setVisible(false); menu.findItem(R.id.action_export).setVisible(false); }// w ww . ja v a 2s . c o m return super.onCreateOptionsMenu(menu); }
From source file:com.oakesville.mythling.MediaActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MediaSettings mediaSettings = appSettings.getMediaSettings(); mediaMenuItem = menu.findItem(R.id.menu_media); if (mediaMenuItem != null) { if (mediaList != null) mediaMenuItem.setTitle(/*from www . ja va 2 s. c om*/ Localizer.getMediaLabel(mediaSettings.getType()) + " (" + mediaList.getCount() + ")"); else mediaMenuItem.setTitle(Localizer.getMediaLabel(mediaSettings.getType())); if (mediaSettings.isMusic()) mediaMenuItem.getSubMenu().findItem(R.id.media_music).setChecked(true); else if (mediaSettings.isLiveTv()) mediaMenuItem.getSubMenu().findItem(R.id.media_tv).setChecked(true); else if (mediaSettings.isMovies()) mediaMenuItem.getSubMenu().findItem(R.id.media_movies).setChecked(true); else if (mediaSettings.isTvSeries()) mediaMenuItem.getSubMenu().findItem(R.id.media_tv_series).setChecked(true); else if (mediaSettings.isVideos()) mediaMenuItem.getSubMenu().findItem(R.id.media_videos).setChecked(true); else mediaMenuItem.getSubMenu().findItem(R.id.media_recordings).setChecked(true); moviesMenuItem = mediaMenuItem.getSubMenu().findItem(R.id.media_movies); showMoviesMenuItem(supportsMovies()); tvSeriesMenuItem = mediaMenuItem.getSubMenu().findItem(R.id.media_tv_series); showTvSeriesMenuItem(supportsTvSeries()); musicMenuItem = mediaMenuItem.getSubMenu().findItem(R.id.media_music); showMusicMenuItem(supportsMusic()); } searchMenuItem = menu.findItem(R.id.menu_search); showSearchMenu(supportsSearch()); sortMenuItem = menu.findItem(R.id.menu_sort); showSortMenu(supportsSort()); viewMenuItem = menu.findItem(R.id.menu_view); showViewMenu(supportsViewMenu()); stopMenuItem = menu.findItem(R.id.menu_stop); showStopMenuItem(isPlayingMusic()); return super.onPrepareOptionsMenu(menu); }
From source file:com.dycody.android.idealnote.ListFragment.java
private void prepareActionModeMenu() { Menu menu = getActionMode().getMenu(); int navigation = Navigation.getNavigation(); boolean showArchive = navigation == Navigation.NOTES || navigation == Navigation.REMINDERS || navigation == Navigation.UNCATEGORIZED || navigation == Navigation.CATEGORY; boolean showUnarchive = navigation == Navigation.ARCHIVE || navigation == Navigation.UNCATEGORIZED || navigation == Navigation.CATEGORY; if (navigation == Navigation.TRASH) { menu.findItem(R.id.menu_untrash).setVisible(true); menu.findItem(R.id.menu_delete).setVisible(true); } else {//from w w w. j a v a 2 s .c om if (getSelectedCount() == 1) { menu.findItem(R.id.menu_share).setVisible(true); menu.findItem(R.id.menu_merge).setVisible(false); menu.findItem(R.id.menu_archive).setVisible(showArchive && !getSelectedNotes().get(0).isArchived()); menu.findItem(R.id.menu_unarchive) .setVisible(showUnarchive && getSelectedNotes().get(0).isArchived()); } else { menu.findItem(R.id.menu_share).setVisible(false); menu.findItem(R.id.menu_merge).setVisible(true); menu.findItem(R.id.menu_archive).setVisible(showArchive); menu.findItem(R.id.menu_unarchive).setVisible(showUnarchive); } menu.findItem(R.id.menu_add_reminder).setVisible(true); menu.findItem(R.id.menu_category).setVisible(true); menu.findItem(R.id.menu_tags).setVisible(true); menu.findItem(R.id.menu_trash).setVisible(true); } menu.findItem(R.id.menu_select_all).setVisible(true); setCabTitle(); }
From source file:cgeo.geocaching.CacheListActivity.java
private void setMenuItemLabel(final Menu menu, final int menuId, @StringRes final int resIdSelection, @StringRes final int resId) { final MenuItem menuItem = menu.findItem(menuId); if (menuItem == null) { return;/*from w ww . j a v a2 s . co m*/ } final boolean hasSelection = adapter != null && adapter.getCheckedCount() > 0; if (hasSelection) { menuItem.setTitle(res.getString(resIdSelection) + " (" + adapter.getCheckedCount() + ")"); } else { menuItem.setTitle(res.getString(resId)); } }
From source file:cgeo.geocaching.CacheListActivity.java
@Override public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.cache_list_options, menu); sortProvider = (SortActionProvider) MenuItemCompat.getActionProvider(menu.findItem(R.id.menu_sort)); assert sortProvider != null; // We set it in the XML file sortProvider.setSelection(adapter.getCacheComparator()); sortProvider.setIsEventsOnly(adapter.isEventsOnly()); sortProvider.setClickListener(new Action1<CacheComparator>() { @Override/*from ww w . j ava2 s . c o m*/ public void call(final CacheComparator selectedComparator) { final CacheComparator oldComparator = adapter.getCacheComparator(); // selecting the same sorting twice will toggle the order if (selectedComparator != null && oldComparator != null && selectedComparator.getClass().equals(oldComparator.getClass())) { adapter.toggleInverseSort(); } else { // always reset the inversion for a new sorting criteria adapter.resetInverseSort(); } setComparator(selectedComparator); sortProvider.setSelection(selectedComparator); } }); ListNavigationSelectionActionProvider.initialize(menu.findItem(R.id.menu_cache_list_app_provider), new ListNavigationSelectionActionProvider.Callback() { @Override public void onListNavigationSelected(final CacheListApp app) { app.invoke(CacheListAppUtils.filterCoords(cacheList), CacheListActivity.this, getFilteredSearch()); } }); return true; }