List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem savePlaylist = menu.findItem(R.id.menu_save_playlist); boolean savePlaylistEnabled = !Util.isOffline(this); savePlaylist.setEnabled(savePlaylistEnabled); savePlaylist.setVisible(savePlaylistEnabled); MenuItem screenOption = menu.findItem(R.id.menu_screen_on_off); if (getDownloadService().getKeepScreenOn()) { screenOption.setTitle(R.string.download_menu_screen_off); } else {/*w w w . ja va 2 s . c o m*/ screenOption.setTitle(R.string.download_menu_screen_on); } MenuItem searchOption = menu.findItem(R.id.menu_search); searchOption.setVisible(!Util.isOffline(this)); return super.onPrepareOptionsMenu(menu); }
From source file:com.google.android.apps.forscience.whistlepunk.project.ProjectDetailsFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { MenuItem archiveButton = menu.findItem(R.id.action_archive_project); MenuItem unarchiveButton = menu.findItem(R.id.action_unarchive_project); MenuItem deleteButton = menu.findItem(R.id.action_delete_project); // If the project hasn't loaded yet hide both options. if (mProject == null) { archiveButton.setVisible(false); unarchiveButton.setVisible(false); deleteButton.setVisible(false);/* w w w . j a v a2s. c o m*/ } else { // Show the archive button if the project is not already archived. archiveButton.setVisible(!mProject.isArchived()); // Show the unarchive button if it's already archived. unarchiveButton.setVisible(mProject.isArchived()); deleteButton.setVisible(true); deleteButton.setEnabled(mProject.isArchived()); } MenuItem includeArchived = menu.findItem(R.id.action_include_archived); includeArchived.setChecked(mIncludeArchived); }
From source file:com.ayuget.redface.ui.activity.ReplyActivity.java
@Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_reply: // Disable button to prevent user from clicking the button twice and posting the // same reply multiple times. This could happen often because there is a small delay // between the click and the activity being closed. menuItem.setEnabled(false); showSendingMessageSpinner();/* w w w.j a v a 2 s .c o m*/ postReply(); break; } return false; }
From source file:cgeo.geocaching.CacheListActivity.java
private static void setVisibleEnabled(final Menu menu, final int itemId, final boolean visible, final boolean enabled) { final MenuItem item = menu.findItem(itemId); item.setVisible(visible);/*from w ww . jav a 2s . c om*/ item.setEnabled(enabled); }
From source file:com.sabaibrowser.UI.java
public void updateMenuState(Tab tab, Menu menu) { MenuItem bm = menu.findItem(R.id.bookmarks_menu_id); if (bm != null) { bm.setVisible(!showingNavScreen()); }//from w w w.j av a 2s . c o m MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id); if (abm != null) { abm.setVisible((tab != null) && !tab.isSnapshot() && !showingNavScreen()); } MenuItem info = menu.findItem(R.id.page_info_menu_id); if (info != null) { info.setVisible(false); } MenuItem newTab = menu.findItem(R.id.new_tab_menu_id); if (newTab != null) { newTab.setVisible(false); } MenuItem newIncognitoTab = menu.findItem(R.id.new_incognito_tab_menu_id); if (newIncognitoTab != null) { newIncognitoTab.setVisible(false); } MenuItem closeOthers = menu.findItem(R.id.close_other_tabs_id); if (closeOthers != null) { boolean isLastTab = true; if (tab != null) { isLastTab = (mTabControl.getTabCount() <= 1); } closeOthers.setEnabled(!isLastTab); } if (showingNavScreen()) { menu.setGroupVisible(R.id.LIVE_MENU, false); menu.setGroupVisible(R.id.SNAPSHOT_MENU, false); menu.setGroupVisible(R.id.NAV_MENU, false); menu.setGroupVisible(R.id.COMBO_MENU, true); } }
From source file:com.github.kanata3249.ffxieq.android.EquipmentSelectorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item; item = menu.findItem(R.id.OrderByName); if (item != null) { if (mOrderByName) item.setTitle(getString(R.string.OrderByLevel)); else// www . ja va 2 s .c o m item.setTitle(getString(R.string.OrderByName)); } EquipmentListView elv; item = menu.findItem(R.id.FilterByType); SubMenu submenu = item.getSubMenu(); submenu.removeGroup(R.id.FilterByType); elv = (EquipmentListView) findViewById(R.id.ListView); if (elv != null) { String types[] = elv.getAvailableWeaponTypes(); if (types == null || types.length == 1) { item.setEnabled(false); } else { item.setEnabled(true); submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType)); for (int i = 0; i < types.length; i++) { submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]); } } } return super.onPrepareOptionsMenu(menu); }
From source file:net.bible.android.control.page.window.WindowControl.java
/** * Add the Window sub-menu resource which is not included in the main.xml for the main menu * Set the synchronised checkbox in the app menu before displayed * Disable various menu items if links window selected *///from w w w .j a v a 2 s . c o m public void updateOptionsMenu(Menu menu) { // when updating main menu rather than Window options menu MenuItem windowSubmenuItemPosition = menu.findItem(R.id.windowSubMenu); if (windowSubmenuItemPosition != null) { // check the Window sub-menu has been added Menu subMenuToPopulate = windowSubmenuItemPosition.getSubMenu(); if (subMenuToPopulate.findItem(R.id.windowNew) == null) { new MenuInflater(BibleApplication.getApplication()).inflate(R.menu.window_popup_menu, subMenuToPopulate); } } MenuItem synchronisedMenuItem = menu.findItem(R.id.windowSynchronise); MenuItem moveFirstMenuItem = menu.findItem(R.id.windowMoveFirst); MenuItem closeMenuItem = menu.findItem(R.id.windowClose); MenuItem minimiseMenuItem = menu.findItem(R.id.windowMinimise); MenuItem maximiseMenuItem = menu.findItem(R.id.windowMaximise); Window window = getActiveWindow(); if (synchronisedMenuItem != null && moveFirstMenuItem != null) { // set synchronised & maximised checkbox state synchronisedMenuItem.setChecked(window.isSynchronised()); maximiseMenuItem.setChecked(window.isMaximised()); // the dedicated links window cannot be treated as a normal window boolean isDedicatedLinksWindowActive = isActiveWindow(windowRepository.getDedicatedLinksWindow()); synchronisedMenuItem.setEnabled(!isDedicatedLinksWindowActive); moveFirstMenuItem.setEnabled(!isDedicatedLinksWindowActive); // cannot close last normal window closeMenuItem.setEnabled(isWindowRemovable(window)); minimiseMenuItem.setEnabled(isWindowMinimisable(window)); // if window is already first then cannot promote List<Window> visibleWindows = windowRepository.getVisibleWindows(); if (visibleWindows.size() > 0 && window.equals(visibleWindows.get(0))) { moveFirstMenuItem.setEnabled(false); } } }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java
/** * {@inheritDoc}//from w w w .j a v a 2 s. c om */ @Override public void onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem item = menu.findItem(R.id.busstopmap_option_menu_trafficview); if (map != null && map.isTrafficEnabled()) { item.setTitle(R.string.map_menu_mapoverlay_trafficviewoff); } else { item.setTitle(R.string.map_menu_mapoverlay_trafficviewon); } item.setEnabled(map != null); item = menu.findItem(R.id.busstopmap_option_menu_services); item.setEnabled(services != null && services.length > 0); }
From source file:com.github.kanata3249.ffxieq.android.AugmentSelectorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item; item = menu.findItem(R.id.OrderByName); if (item != null) { if (mOrderByName) item.setTitle(getString(R.string.OrderByLevel)); else// w ww. ja va 2s .c o m item.setTitle(getString(R.string.OrderByName)); } AugmentListView lv; item = menu.findItem(R.id.FilterByType); SubMenu submenu = item.getSubMenu(); submenu.removeGroup(R.id.FilterByType); lv = (AugmentListView) findViewById(R.id.ListView); if (lv != null) { String types[] = lv.getAvailableWeaponTypes(); if (types == null || types.length == 1) { item.setEnabled(false); } else { item.setEnabled(true); submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType)); for (int i = 0; i < types.length; i++) { submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]); } } } return super.onPrepareOptionsMenu(menu); }
From source file:org.envirocar.app.activity.ListTracksFragment.java
private void updateUsabilityOfMenuItems() { if (menu == null) return;// w ww . j a v a 2 s . c o m if (!isAdded()) return; getActivity().runOnUiThread(new Runnable() { @Override public void run() { Menu theMenu = menu; if (theMenu == null) { return; } if (dbAdapter.getAllLocalTracks().size() > 0) { setItemEnabled(theMenu.findItem(R.id.menu_delete_all), true); setItemEnabled(theMenu.findItem(R.id.menu_upload), UserManager.instance().isLoggedIn()); } else { setItemEnabled(theMenu.findItem(R.id.menu_upload), false); setItemEnabled(theMenu.findItem(R.id.menu_delete_all), false); } } private void setItemEnabled(com.actionbarsherlock.view.MenuItem item, boolean b) { if (item != null) { item.setEnabled(b); } } }); }