List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:ca.rmen.android.scrumchatter.main.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { Log.v(TAG, "onPrepareOptionsMenu " + menu); // Only enable the "delete team" menu item if we have at least two teams. MenuItem deleteItem = menu.findItem(R.id.action_team_delete); deleteItem.setEnabled(mTeamCount > 1); // Add the current team name to the delete and rename menu items if (mTeam != null) { deleteItem.setTitle(getString(R.string.action_team_delete_name, mTeam.teamName)); MenuItem renameItem = menu.findItem(R.id.action_team_rename); renameItem.setTitle(getString(R.string.action_team_rename_name, mTeam.teamName)); }/*from ww w . ja v a 2 s .co m*/ // Only show the settings in v14+. Currently the only setting // we have is for the day/night theme switch, which only works on // v14+. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { MenuItem settingsItem = menu.findItem(R.id.action_settings); settingsItem.setVisible(false); } // Only show the menu items for sharing a meeting and stats for a meeting, if the selected meeting is finished. MeetingFragment meetingFragment = MeetingFragment.lookupMeetingFragment(getSupportFragmentManager()); boolean meetingIsFinished = meetingFragment != null && meetingFragment.getState() == MeetingColumns.State.FINISHED; MenuItem menuItem = menu.findItem(R.id.action_share_meeting); if (menuItem != null) menuItem.setVisible(meetingIsFinished); menuItem = menu.findItem(R.id.action_charts_meeting); if (menuItem != null) menuItem.setVisible(meetingIsFinished); // Don't show the global share/stats menu items unless we have at least one meeting MeetingsListFragment meetingsListFragment = (MeetingsListFragment) mMainPagerAdapter .instantiateItem(mBinding.pager, 0); boolean hasMeetings = meetingsListFragment != null && meetingsListFragment.hasMeetings(); menu.findItem(R.id.action_share).setVisible(hasMeetings); menu.findItem(R.id.action_charts).setVisible(hasMeetings); menuItem = menu.findItem(R.id.action_share_submenu); if (menuItem != null) menuItem.setVisible(hasMeetings); menuItem = menu.findItem(R.id.action_charts_submenu); if (menuItem != null) menuItem.setVisible(hasMeetings); return super.onPrepareOptionsMenu(menu); }
From source file:com.abhijitvalluri.android.fitnotifications.AppChoicesActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem searchItem = menu.findItem(R.id.menu_app_search); MenuItem filterEnabledItem = menu.findItem(R.id.menu_filter_enabled); if (mAdapter == null) { // cannot search yet searchItem.setEnabled(false); filterEnabledItem.setEnabled(false); } else {/*from www . j a v a 2s. c o m*/ searchItem.setEnabled(true); filterEnabledItem.setEnabled(true); } return true; }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.AlertManagerFragment.java
/** * {@inheritDoc}/*w w w . ja v a 2 s . co m*/ */ @Override public void onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); final MenuItem deleteAllItem = menu.findItem(R.id.alertmanager_option_menu_delete_all); // Only enable the 'Delete all alerts' item when there's alerts to // delete. if (ad.getCount() > 0) { deleteAllItem.setEnabled(true); } else { deleteAllItem.setEnabled(false); } }
From source file:com.synox.android.ui.fragment.FileDetailFragment.java
/** * {@inheritDoc}/*from w w w.java 2s.c o m*/ */ @Override public void onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.action_search).setVisible(false); menu.findItem(R.id.action_changeView).setVisible(false); super.onPrepareOptionsMenu(menu); if (mContainerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter(getFile(), mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity()); mf.filter(menu); } // additional restriction for this fragment MenuItem item = menu.findItem(R.id.action_see_details); if (item != null) { item.setVisible(false); item.setEnabled(false); } // additional restriction for this fragment item = menu.findItem(R.id.action_move); if (item != null) { item.setVisible(false); item.setEnabled(false); } // additional restriction for this fragment item = menu.findItem(R.id.action_copy); if (item != null) { item.setVisible(false); item.setEnabled(false); } }
From source file:de.jerleo.samsung.knox.firewall.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); boolean allowed = (mViewPager.getCurrentItem() == 0); boolean hasAdmin = hasActiveAdministrator(); boolean hasLicense = hasActiveLicense(); MenuItem itemAdmin = menu.findItem(R.id.action_admin); MenuItem itemLicense = menu.findItem(R.id.action_license); MenuItem itemAllow = menu.findItem(R.id.action_allow_selected); MenuItem itemDeny = menu.findItem(R.id.action_deny_selected); MenuItem itemApply = menu.findItem(R.id.action_apply_rules); // Set visibility of options menu items itemAdmin.setEnabled(!hasAdmin); itemLicense.setEnabled(hasAdmin && !hasLicense); itemAllow.setEnabled(hasAdmin && hasLicense); itemAllow.setVisible(!allowed);/*from w ww . j av a 2 s. c o m*/ itemDeny.setEnabled(hasAdmin && hasLicense); itemDeny.setVisible(allowed); itemApply.setEnabled(hasAdmin && hasLicense); invalidateOptionsMenu(); return true; }
From source file:org.fedorahosted.freeotp.main.Activity.java
@Override public void onSelectEvent(NavigableSet<Integer> selected) { if (mMenu == null) return;/* ww w . jav a 2 s .co m*/ for (int i = 0; i < mMenu.size(); i++) { MenuItem mi = mMenu.getItem(i); switch (mi.getItemId()) { case R.id.action_about: mi.setVisible(selected.size() == 0); break; case R.id.action_up: mi.setVisible(selected.size() > 0); mi.setEnabled(!mTokenAdapter.isSelected(0)); break; case R.id.action_down: mi.setVisible(selected.size() > 0); mi.setEnabled(!mTokenAdapter.isSelected(mTokenAdapter.getItemCount() - 1)); break; case R.id.action_delete: mi.setVisible(selected.size() > 0); break; default: break; } } }
From source file:com.granita.tasks.ViewTaskFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { /*//w w w. j av a2 s . c o m * Don't show any options if we don't have a task to show. */ if (mTaskUri != null) { inflater.inflate(R.menu.view_task_fragment_menu, menu); if (mContentSet != null) { Integer status = TaskFieldAdapters.STATUS.get(mContentSet); if (status != null) { mOldStatus = status; } if (TaskFieldAdapters.IS_CLOSED.get(mContentSet) || status != null && status == Tasks.STATUS_COMPLETED) { // we disable the edit option, because the task is completed and the action button shows the edit option. MenuItem item = menu.findItem(R.id.edit_task); item.setEnabled(false); item.setVisible(false); } } } }
From source file:de.vanita5.twittnuker.activity.support.UserProfileEditorActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { final MenuItem save = menu.findItem(MENU_SAVE); if (save != null) { save.setEnabled( mHasUnsavedChanges() && (mTask == null || mTask.getStatus() != AsyncTask.Status.RUNNING)); }// w w w. ja va 2 s .co m return super.onPrepareOptionsMenu(menu); }
From source file:org.thaliproject.nativetest.app.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (mPeerListFragment != null) { MenuUtils.PeerMenuItemsAvailability availability = MenuUtils.resolvePeerMenuItemsAvailability( mPeerListFragment.getSelectedPeerProperties(), PeerAndConnectionModel.getInstance()); MenuItem connectMenuItem = menu.getItem(0); MenuItem sendDataMenuItem = menu.getItem(1); MenuItem disconnectMenuItem = menu.getItem(2); MenuItem killAllConnectionsMenuItem = menu.getItem(3); connectMenuItem.setVisible(availability.connectMenuItemAvailable); connectMenuItem.setEnabled(availability.connectMenuItemAvailable); sendDataMenuItem.setVisible(availability.sendDataMenuItemAvailable); sendDataMenuItem.setEnabled(availability.sendDataMenuItemAvailable); disconnectMenuItem.setEnabled(availability.disconnectMenuItemAvailable); killAllConnectionsMenuItem.setEnabled(availability.killAllConnectionsMenuItemAvailable); return true; }/*from w w w. j a v a2 s. c o m*/ return false; }
From source file:com.battlelancer.seriesguide.ui.MovieDetailsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); if (mMovieDetails != null) { boolean isLightTheme = SeriesGuidePreferences.THEME == R.style.Theme_SeriesGuide_Light; inflater.inflate(isLightTheme ? R.menu.movie_details_menu_light : R.menu.movie_details_menu, menu); // hide Google Play button in Amazon version if (Utils.isAmazonVersion()) { MenuItem playStoreItem = menu.findItem(R.id.menu_open_google_play); playStoreItem.setEnabled(false); playStoreItem.setVisible(false); }/*from w w w. j a va 2 s .c o m*/ } }