List of usage examples for android.view Menu findItem
public MenuItem findItem(int id);
From source file:com.android.contacts.activities.PeopleActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { mOptionsMenuContactsAvailable = areContactsAvailable(); if (!mOptionsMenuContactsAvailable) { return false; }/* w w w . ja v a2 s. c o m*/ // Get references to individual menu items in the menu final MenuItem contactsFilterMenu = menu.findItem(R.id.menu_contacts_filter); final MenuItem clearFrequentsMenu = menu.findItem(R.id.menu_clear_frequents); final MenuItem helpMenu = menu.findItem(R.id.menu_help); final boolean isSearchOrSelectionMode = mActionBarAdapter.isSearchMode() || mActionBarAdapter.isSelectionMode(); if (isSearchOrSelectionMode) { contactsFilterMenu.setVisible(false); clearFrequentsMenu.setVisible(false); helpMenu.setVisible(false); } else { switch (getTabPositionForTextDirection(mActionBarAdapter.getCurrentTab())) { case TabState.FAVORITES: contactsFilterMenu.setVisible(false); clearFrequentsMenu.setVisible(hasFrequents()); break; case TabState.ALL: contactsFilterMenu.setVisible(true); clearFrequentsMenu.setVisible(false); break; } helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); } final boolean showMiscOptions = !isSearchOrSelectionMode; final boolean showBlockedNumbers = PhoneCapabilityTester.isPhone(this) && ContactsUtils.FLAG_N_FEATURE && BlockedNumberContractCompat.canCurrentUserBlockNumbers(this); makeMenuItemVisible(menu, R.id.menu_search, showMiscOptions); makeMenuItemVisible(menu, R.id.menu_import_export, showMiscOptions); makeMenuItemVisible(menu, R.id.menu_accounts, showMiscOptions); makeMenuItemVisible(menu, R.id.menu_blocked_numbers, showMiscOptions && showBlockedNumbers); makeMenuItemVisible(menu, R.id.menu_settings, showMiscOptions && !ContactsPreferenceActivity.isEmpty(this)); final boolean showSelectedContactOptions = mActionBarAdapter.isSelectionMode() && mAllFragment.getSelectedContactIds().size() != 0; makeMenuItemVisible(menu, R.id.menu_share, showSelectedContactOptions); makeMenuItemVisible(menu, R.id.menu_delete, showSelectedContactOptions); final boolean showLinkContactsOptions = mActionBarAdapter.isSelectionMode() && mAllFragment.getSelectedContactIds().size() > 1; makeMenuItemVisible(menu, R.id.menu_join, showLinkContactsOptions); // Debug options need to be visible even in search mode. makeMenuItemVisible(menu, R.id.export_database, mEnableDebugMenuOptions && hasExportIntentHandler()); return true; }
From source file:com.ichi2.anki.NoteEditor.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.note_editor, menu); if (mAddNote) { menu.findItem(R.id.action_copy_card).setVisible(false); } else {//from w ww. j a v a 2 s. c o m menu.findItem(R.id.action_add_card_from_card_editor).setVisible(true); menu.findItem(R.id.action_reset_card_progress).setVisible(true); menu.findItem(R.id.action_reschedule_card).setVisible(true); menu.findItem(R.id.action_reset_card_progress).setVisible(true); } if (mEditFields != null) { for (int i = 0; i < mEditFields.size(); i++) { if (mEditFields.get(i).getText().length() > 0) { menu.findItem(R.id.action_copy_card).setEnabled(true); break; } else if (i == mEditFields.size() - 1) { menu.findItem(R.id.action_copy_card).setEnabled(false); } } } return super.onCreateOptionsMenu(menu); }
From source file:com.ringdroid.RingdroidEditActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.findItem(CMD_SAVE).setVisible(true); menu.findItem(CMD_RESET).setVisible(true); menu.findItem(CMD_USE_ALL).setVisible(true); // menu.findItem(CMD_ABOUT).setVisible(true); return true;/*from w ww .j av a2 s .c o m*/ }
From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java
public boolean onPrepareOptionsMenu(Menu menu) { // gps status menu.findItem(R.id.action_gps_inactive).setVisible(false); menu.findItem(R.id.action_gps_active_has_signal).setVisible(false); menu.findItem(R.id.action_gps_active_no_signal).setVisible(false); if (gpsDataManager.isExternalGPSStarted() || gpsDataManager.isInternalGPSStarted()) { if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) { menu.findItem(R.id.action_gps_active_has_signal).setVisible(true); } else {/*from ww w . j av a2 s . c o m*/ menu.findItem(R.id.action_gps_active_no_signal).setVisible(true); } } else { menu.findItem(R.id.action_gps_inactive).setVisible(true); } // tracker status menu.findItem(R.id.action_tracker_active_no_gps).setVisible(false); menu.findItem(R.id.action_tracker_active_has_gps).setVisible(false); menu.findItem(R.id.action_tracker_inactive).setVisible(false); if (gpsDataManager.isTrackingStarted()) { if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) { menu.findItem(R.id.action_tracker_active_has_gps).setVisible(true); } else { menu.findItem(R.id.action_tracker_active_no_gps).setVisible(true); } } else { menu.findItem(R.id.action_tracker_inactive).setVisible(true); } // sync status menu.findItem(R.id.action_sync).setVisible(false); menu.findItem(R.id.action_sync_active).setVisible(false); menu.findItem(R.id.action_sync_error).setVisible(false); menu.findItem(R.id.action_sync_has_changes).setVisible(false); menu.findItem(R.id.action_sync_inactive).setVisible(false); syncAnimImage.clearAnimation(); switch (syncStatus) { case ACTIVE_SYNCING: MenuItem syncItem = menu.findItem(R.id.action_sync_active).setVisible(true); syncAnimImage.startAnimation(rotation); syncItem.setActionView(syncAnimImage); break; case ERROR: menu.findItem(R.id.action_sync_error).setVisible(true); break; case ACTIVE_NO_CHANGES: menu.findItem(R.id.action_sync).setVisible(true); break; case ACTIVE_HAS_CHANGES: menu.findItem(R.id.action_sync_has_changes).setVisible(true); break; default: menu.findItem(R.id.action_sync_inactive).setVisible(true); break; } // follow status MenuItem distance_text = menu.findItem(R.id.distance_text); distance_text.setVisible(pathIndicatorVisible); String distanceInfo = pathIndex < 0 ? "" : " to point (" + pathIndex + "/" + pathLength + ")"; if (pathDistance > 1000) { distance_text.setTitle( MeasurementUtil.displayAsKiloMeters(pathDistance / 1000, "###,###,###,###.0") + distanceInfo); } else { distance_text.setTitle(MeasurementUtil.displayAsMeters(pathDistance, "###,###,###,###") + distanceInfo); } MenuItem direction_text = menu.findItem(R.id.direction_text); direction_text.setVisible(pathIndicatorVisible); direction_text.setTitle(MeasurementUtil.displayAsDegrees(pathBearing, "###")); MenuItem direction_indicator = menu.findItem(R.id.direction_indicator); direction_indicator.setVisible(pathIndicatorVisible); if (pathHeading != null) { if (tempBitmap != null) { tempBitmap.recycle(); } if (whiteArrow == null) { whiteArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(), au.org.intersect.faims.android.R.drawable.white_arrow)); } if (greyArrow == null) { greyArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(), au.org.intersect.faims.android.R.drawable.grey_arrow)); } this.tempBitmap = BitmapUtil.rotateBitmap(pathValid ? whiteArrow.getBitmap() : greyArrow.getBitmap(), pathBearing - pathHeading); direction_indicator.setIcon(new BitmapDrawable(getResources(), tempBitmap)); } else { direction_indicator.setVisible(false); } return true; }
From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java
private void setUpActionModeOnListItems() { getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override// ww w .j a v a2s .co m public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return performAction(mode, item); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.fragment_events_list_context, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { verifyMenuItems(mode.getMenu()); for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) { if (i != position) { getListView().setItemChecked(i, false); } } } } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } private void verifyMenuItems(Menu menu) { Event checkedEvent = getFirstCheckedItem(); menu.findItem(R.id.fragment_events_list_context_menu_archive) .setVisible(!checkedEvent.isArchived()); menu.findItem(R.id.fragment_events_list_context_menu_edit) .setVisible(!checkedEvent.isArchived() || !checkedEvent.isLocked()); menu.findItem(R.id.fragment_events_list_context_menu_lock).setVisible(!checkedEvent.isLocked()); menu.findItem(R.id.fragment_events_list_context_menu_share).setVisible(!checkedEvent.isArchived()); menu.findItem(R.id.fragment_events_list_context_menu_unlock).setVisible(checkedEvent.isLocked()); } }); }
From source file:com.android.email.activity.MessageView.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.message_view_option, menu); if (mDisableReplyAndForward) { menu.findItem(R.id.forward).setEnabled(false); menu.findItem(R.id.reply).setEnabled(false); menu.findItem(R.id.reply_all).setEnabled(false); }//w ww. j ava 2s.c o m return true; }
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // This happens when the user begins to hold down the menu key, so // allow them to chord to get a shortcut. mCanChord = true;/* w w w. j a v a 2 s . c om*/ super.onPrepareOptionsMenu(menu); MenuItem src, dest; // Login/Logout if (mSettings.isLoggedIn()) { menu.findItem(R.id.login_menu_id).setVisible(false); if (!mSubreddit.equals(Constants.FRONTPAGE_STRING)) { ArrayList<String> mSubredditsList = CacheInfo.getCachedSubredditList(getApplicationContext()); if (mSubredditsList != null && StringUtils.listContainsIgnoreCase(mSubredditsList, mSubreddit)) { menu.findItem(R.id.unsubscribe_menu_id).setVisible(true); menu.findItem(R.id.subscribe_menu_id).setVisible(false); } else { menu.findItem(R.id.subscribe_menu_id).setVisible(true); menu.findItem(R.id.unsubscribe_menu_id).setVisible(false); } } menu.findItem(R.id.inbox_menu_id).setVisible(true); menu.findItem(R.id.user_profile_menu_id).setVisible(true); menu.findItem(R.id.user_profile_menu_id).setTitle( String.format(getResources().getString(R.string.user_profile), mSettings.getUsername())); menu.findItem(R.id.logout_menu_id).setVisible(true); menu.findItem(R.id.logout_menu_id) .setTitle(String.format(getResources().getString(R.string.logout), mSettings.getUsername())); } else { menu.findItem(R.id.login_menu_id).setVisible(true); menu.findItem(R.id.unsubscribe_menu_id).setVisible(false); menu.findItem(R.id.subscribe_menu_id).setVisible(false); menu.findItem(R.id.inbox_menu_id).setVisible(false); menu.findItem(R.id.user_profile_menu_id).setVisible(false); menu.findItem(R.id.logout_menu_id).setVisible(false); } // Theme: Light/Dark src = Util.isLightTheme(mSettings.getTheme()) ? menu.findItem(R.id.dark_menu_id) : menu.findItem(R.id.light_menu_id); dest = menu.findItem(R.id.light_dark_menu_id); dest.setTitle(src.getTitle()); // Sort if (Constants.ThreadsSort.SORT_BY_HOT_URL.equals(mSortByUrl)) src = menu.findItem(R.id.sort_by_hot_menu_id); else if (Constants.ThreadsSort.SORT_BY_NEW_URL.equals(mSortByUrl)) src = menu.findItem(R.id.sort_by_new_menu_id); else if (Constants.ThreadsSort.SORT_BY_CONTROVERSIAL_URL.equals(mSortByUrl)) src = menu.findItem(R.id.sort_by_controversial_menu_id); else if (Constants.ThreadsSort.SORT_BY_TOP_URL.equals(mSortByUrl)) src = menu.findItem(R.id.sort_by_top_menu_id); dest = menu.findItem(R.id.sort_by_menu_id); dest.setTitle(src.getTitle()); return true; }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@Override public void onClick(final View view) { switch (view.getId()) { case R.id.image_thumbnail_preview: { if (mPopupMenu != null) { mPopupMenu.dismiss();// w w w . ja v a2s . c om } mPopupMenu = PopupMenu.getInstance(this, view); mPopupMenu.inflate(R.menu.action_attached_image); mPopupMenu.setOnMenuItemClickListener(this); final Menu menu = mPopupMenu.getMenu(); final MenuItem itemUpload = menu.findItem(MENU_UPLOAD); if (!isNullOrEmpty(mUploadProvider) && itemUpload != null) { itemUpload.setVisible(true); } mPopupMenu.show(); break; } } }
From source file:com.android.calendar.AllInOneActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); mOptionsMenu = menu;//from w ww. j a va2s. co m getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu); // Add additional options (if any). Integer extensionMenuRes = mExtensions.getExtensionMenuResource(menu); if (extensionMenuRes != null) { getMenuInflater().inflate(extensionMenuRes, menu); } MenuItem item = menu.findItem(R.id.action_import); item.setVisible(ImportActivity.hasThingsToImport(this)); mSearchMenu = menu.findItem(R.id.action_search); mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchMenu); if (mSearchView != null) { Utils.setUpSearchView(mSearchView, this); mSearchView.setOnQueryTextListener(this); mSearchView.setOnSuggestionListener(this); } // Hide the "show/hide controls" button if this is a phone // or the view type is "Month" or "Agenda". mControlsMenu = menu.findItem(R.id.action_hide_controls); if (!mShowCalendarControls) { if (mControlsMenu != null) { mControlsMenu.setVisible(false); mControlsMenu.setEnabled(false); } } else if (mControlsMenu != null && mController != null && (mController.getViewType() == ViewType.MONTH || mController.getViewType() == ViewType.AGENDA)) { mControlsMenu.setVisible(false); mControlsMenu.setEnabled(false); } else if (mControlsMenu != null) { mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); } MenuItem menuItem = menu.findItem(R.id.action_today); if (Utils.isJellybeanOrLater()) { // replace the default top layer drawable of the today icon with a // custom drawable that shows the day of the month of today LayerDrawable icon = (LayerDrawable) menuItem.getIcon(); Utils.setTodayIcon(icon, this, mTimeZone); } else { menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light); } return true; }